@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
package/lib/ir/validate.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","names":[],"sources":["../../src/ir/validate.ts"],"sourcesContent":["import { isLinkHopFromForeignKeySource, resolveLinkHop } from \"../utils/links.js\";\nimport { unwrapType } from \"../utils/types.js\";\nimport { ImageMediaTypeOptions } from \"./generated/constants.js\";\nimport type { ValidationIssue } from \"../utils/validation.js\";\nimport type { Result } from \"../utils/values.js\";\nimport type {\n ActionParameterDef,\n ActionTypeDef,\n Expression,\n LinkTypeDef,\n ObjectTypeDef,\n OntologyIR,\n PropertyAssignment,\n PropertyDef,\n QueryFunctionTypeDef,\n TypeDef,\n InputReferenceExpression,\n} from \"./generated/types.js\";\n\nexport type ValidationResult = Result<void, ValidationIssue[]>;\n\n// TODO: Replace this attachment-specific range validation with real numeric constraints in the meta ontology.\nfunction validateNonNegativeRange(\n range: { min?: number; max?: number } | undefined,\n path: (string | number)[]\n): ValidationIssue[] {\n if (!range) return [];\n const errors: ValidationIssue[] = [];\n for (const bound of [\"min\", \"max\"] as const) {\n const value = range[bound];\n if (value !== undefined && (!Number.isFinite(value) || value < 0)) {\n errors.push({\n message: `Range ${bound} must be a finite, non-negative number.`,\n path: [...path, bound],\n });\n }\n }\n if (range.min !== undefined && range.max !== undefined && range.min > range.max) {\n errors.push({\n message: \"Range min must be less than or equal to max.\",\n path,\n });\n }\n return errors;\n}\n\nfunction validateAttachmentConstraints(type: Extract<TypeDef, { kind: \"attachment\" }>): ValidationIssue[] {\n const constraint = type.value.constraint;\n if (!constraint) return [];\n\n const errors = validateNonNegativeRange(constraint.size, [\"constraint\", \"size\"]);\n const content = constraint.content;\n if (content?.kind !== \"image\") return errors;\n\n for (const [index, mediaType] of (content.value.mediaTypes ?? []).entries()) {\n if (!ImageMediaTypeOptions.some((option) => option.value === mediaType)) {\n errors.push({\n message: `Unsupported image media type: \"${mediaType}\".`,\n path: [\"constraint\", \"content\", \"value\", \"mediaTypes\", index],\n });\n }\n }\n errors.push(\n ...validateNonNegativeRange(content.value.dimensions?.width, [\n \"constraint\",\n \"content\",\n \"value\",\n \"dimensions\",\n \"width\",\n ]),\n ...validateNonNegativeRange(content.value.dimensions?.height, [\n \"constraint\",\n \"content\",\n \"value\",\n \"dimensions\",\n \"height\",\n ])\n );\n return errors;\n}\n\nfunction validateTypeDef(\n type: TypeDef,\n path: (string | number)[],\n valueTypeNames: Set<string>,\n objectTypeNames: Set<string>\n): ValidationIssue[] {\n switch (type.kind) {\n case \"string\":\n case \"boolean\":\n case \"integer\":\n case \"float\":\n case \"double\":\n case \"date\":\n case \"timestamp\":\n case \"geopoint\":\n case \"unknown\":\n return [];\n\n case \"attachment\":\n return validateAttachmentConstraints(type).map((error) => ({\n ...error,\n path: [...path, ...(error.path ?? [])],\n }));\n\n case \"objectReference\":\n return objectTypeNames.has(type.value.objectType)\n ? []\n : [\n {\n message: `Unknown object type reference: \"${type.value.objectType}\".`,\n path: [...path, \"objectType\"],\n },\n ];\n\n case \"list\":\n return validateTypeDef(\n type.value.elementType,\n [...path, \"elementType\"],\n valueTypeNames,\n objectTypeNames\n );\n\n case \"map\": {\n const errors: ValidationIssue[] = [];\n if (type.value.keyType.kind !== \"string\") {\n errors.push({\n message: \"Map key types must be string.\",\n path: [...path, \"keyType\"],\n });\n }\n return [\n ...errors,\n ...validateTypeDef(type.value.keyType, [...path, \"keyType\"], valueTypeNames, objectTypeNames),\n ...validateTypeDef(\n type.value.valueType,\n [...path, \"valueType\"],\n valueTypeNames,\n objectTypeNames\n ),\n ];\n }\n\n case \"struct\":\n return validateStructFields(\n type.value.fields,\n [...path, \"fields\"],\n valueTypeNames,\n objectTypeNames\n );\n\n case \"union\":\n return validateUnionVariants(\n type.value.variants,\n [...path, \"variants\"],\n valueTypeNames,\n objectTypeNames\n );\n\n case \"optional\":\n return validateTypeDef(type.value.type, [...path, \"type\"], valueTypeNames, objectTypeNames);\n\n case \"result\":\n return [\n ...validateTypeDef(type.value.okType, [...path, \"okType\"], valueTypeNames, objectTypeNames),\n ...validateTypeDef(type.value.errType, [...path, \"errType\"], valueTypeNames, objectTypeNames),\n ];\n\n case \"ref\":\n return valueTypeNames.has(type.value.name)\n ? []\n : [\n {\n message: `Unknown value type reference: \"${type.value.name}\".`,\n path: [...path, \"name\"],\n },\n ];\n }\n}\n\nfunction validateStructFields(\n fields: Array<{ name: string; displayName: string; type: TypeDef }>,\n path: (string | number)[],\n valueTypeNames: Set<string>,\n objectTypeNames: Set<string>\n): ValidationIssue[] {\n const fieldNames = new Set<string>();\n const errors: ValidationIssue[] = [];\n\n for (let i = 0; i < fields.length; i++) {\n const field = fields[i]!;\n const fieldPath = [...path, i];\n\n if (fieldNames.has(field.name)) {\n errors.push({ message: `Duplicate field name: \"${field.name}\".`, path: [...fieldPath, \"name\"] });\n }\n fieldNames.add(field.name);\n\n errors.push(...validateTypeDef(field.type, [...fieldPath, \"type\"], valueTypeNames, objectTypeNames));\n }\n\n return errors;\n}\n\nfunction validateUnionVariants(\n variants: Array<{ name: string; type: TypeDef }>,\n path: (string | number)[],\n valueTypeNames: Set<string>,\n objectTypeNames: Set<string>\n): ValidationIssue[] {\n const seen = new Set<string>();\n const errors: ValidationIssue[] = [];\n\n for (let i = 0; i < variants.length; i++) {\n const variant = variants[i]!;\n const variantPath = [...path, i];\n\n if (seen.has(variant.name)) {\n errors.push({\n message: `Duplicate variant name: \"${variant.name}\".`,\n path: [...variantPath, \"name\"],\n });\n }\n seen.add(variant.name);\n\n errors.push(\n ...validateTypeDef(variant.type, [...variantPath, \"type\"], valueTypeNames, objectTypeNames)\n );\n }\n\n return errors;\n}\n\nfunction validateProperties(\n properties: PropertyDef[],\n path: (string | number)[],\n valueTypeNames: Set<string>,\n objectTypeNames: Set<string>\n): ValidationIssue[] {\n const names = new Set<string>();\n const errors: ValidationIssue[] = [];\n\n for (let i = 0; i < properties.length; i++) {\n const prop = properties[i]!;\n const propPath = [...path, i];\n\n if (names.has(prop.name)) {\n errors.push({\n message: `Duplicate property name: \"${prop.name}\".`,\n path: [...propPath, \"name\"],\n });\n }\n names.add(prop.name);\n\n errors.push(...validateTypeDef(prop.type, [...propPath, \"type\"], valueTypeNames, objectTypeNames));\n }\n\n return errors;\n}\n\nfunction resolveType(\n type: TypeDef,\n valueTypes: ReadonlyMap<string, TypeDef>,\n seen = new Set<string>()\n): TypeDef | undefined {\n if (type.kind !== \"ref\") {\n return type;\n }\n\n const name = type.value.name;\n if (seen.has(name)) {\n return undefined;\n }\n\n const resolved = valueTypes.get(name);\n if (!resolved) {\n return undefined;\n }\n\n return resolveType(resolved, valueTypes, new Set([...seen, name]));\n}\n\nfunction resolveFieldType(\n type: TypeDef,\n path: string[],\n valueTypes: ReadonlyMap<string, TypeDef>\n): TypeDef | undefined {\n const resolvedType = resolveType(type, valueTypes);\n if (!resolvedType) {\n return undefined;\n }\n\n if (path.length === 0) {\n return resolvedType;\n }\n\n const [segment, ...rest] = path;\n\n switch (resolvedType.kind) {\n case \"optional\":\n return resolveFieldType(resolvedType.value.type, path, valueTypes);\n case \"struct\": {\n const field = resolvedType.value.fields.find((candidate) => candidate.name === segment);\n return field ? resolveFieldType(field.type, rest, valueTypes) : undefined;\n }\n default:\n return undefined;\n }\n}\n\ntype ExpressionValueType =\n | TypeDef\n | {\n kind: \"ontologyObject\";\n objectType: string;\n };\n\nfunction resolveExpressionType(\n expression: Expression,\n parameters: ReadonlyMap<string, ActionParameterDef>,\n valueTypes: ReadonlyMap<string, TypeDef>,\n objectTypes: ReadonlyMap<string, ObjectTypeDef>,\n linkTypes: readonly LinkTypeDef[],\n contextType: TypeDef | undefined,\n locals: ReadonlyMap<string, TypeDef>\n): ExpressionValueType | undefined {\n switch (expression.kind) {\n case \"inputReference\":\n return parameters.get(expression.value.name)?.type;\n case \"contextReference\":\n return contextType\n ? resolveFieldType(contextType, [expression.value.name], valueTypes)\n : undefined;\n case \"localReference\":\n return locals.get(expression.value.name);\n case \"getAt\": {\n const sourceType = resolveExpressionType(\n expression.value.source,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n if (!sourceType || expression.value.path.length === 0) {\n return undefined;\n }\n if (sourceType.kind === \"ontologyObject\") {\n const [propertyName, ...rest] = expression.value.path;\n const property = objectTypes\n .get(sourceType.objectType)\n ?.properties.find((candidate) => candidate.name === propertyName);\n return property ? resolveFieldType(property.type, rest, valueTypes) : undefined;\n }\n return resolveFieldType(sourceType, expression.value.path, valueTypes);\n }\n case \"objectLookup\": {\n const referenceType = resolveExpressionType(\n expression.value.reference,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n const resolved =\n referenceType?.kind === \"ontologyObject\"\n ? undefined\n : referenceType\n ? unwrapOptionalType(referenceType, valueTypes)\n : undefined;\n return resolved?.kind === \"objectReference\"\n ? {\n kind: \"ontologyObject\",\n objectType: resolved.value.objectType,\n }\n : undefined;\n }\n case \"linkHop\": {\n const sourceType = resolveExpressionType(\n expression.value.source,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n if (sourceType?.kind !== \"ontologyObject\") {\n return undefined;\n }\n const link = resolveLinkHop(\n {\n objectTypes: [...objectTypes.values()],\n linkTypes: [...linkTypes],\n },\n sourceType.objectType,\n expression.value.link\n );\n if (!link) return undefined;\n const foreignKeyOnSource = isLinkHopFromForeignKeySource(\n link,\n sourceType.objectType,\n expression.value.link\n );\n if (!foreignKeyOnSource && link.cardinality === \"many\") {\n return undefined;\n }\n return {\n kind: \"ontologyObject\",\n objectType: foreignKeyOnSource ? link.target.objectType : link.source.objectType,\n };\n }\n case \"struct\":\n return {\n kind: \"struct\",\n value: {\n fields: expression.value.fields.map((field) => ({\n name: field.name,\n displayName: field.name,\n type: (() => {\n const resolved = resolveExpressionType(\n field.value,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n return resolved && resolved.kind !== \"ontologyObject\"\n ? resolved\n : {\n kind: \"unknown\" as const,\n value: {},\n };\n })(),\n })),\n },\n };\n case \"map\": {\n const sourceType = resolveExpressionType(\n expression.value.source,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n const listType =\n sourceType && sourceType.kind !== \"ontologyObject\"\n ? unwrapOptionalType(sourceType, valueTypes)\n : undefined;\n if (listType?.kind !== \"list\") {\n return undefined;\n }\n const bodyLocals = new Map(locals);\n bodyLocals.set(expression.value.binding, listType.value.elementType);\n const bodyType = resolveExpressionType(\n expression.value.body,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n bodyLocals\n );\n return bodyType && bodyType.kind !== \"ontologyObject\"\n ? {\n kind: \"list\",\n value: { elementType: bodyType },\n }\n : undefined;\n }\n case \"literal\":\n return { kind: \"unknown\", value: {} };\n case \"uuid\":\n return { kind: \"string\", value: {} };\n case \"now\":\n return { kind: \"timestamp\", value: {} };\n }\n}\n\nfunction validateExpression(\n expression: Expression,\n parameters: ReadonlyMap<string, ActionParameterDef>,\n path: (string | number)[],\n valueTypes: ReadonlyMap<string, TypeDef>,\n objectTypes: ReadonlyMap<string, ObjectTypeDef>,\n linkTypes: readonly LinkTypeDef[],\n contextType: TypeDef | undefined,\n locals: ReadonlyMap<string, TypeDef> = new Map()\n): ValidationIssue[] {\n switch (expression.kind) {\n case \"inputReference\": {\n const parameter = parameters.get(expression.value.name);\n if (!parameter) {\n return [\n {\n message: `Unknown action parameter: \"${expression.value.name}\".`,\n path: [...path, \"name\"],\n },\n ];\n }\n return [];\n }\n case \"contextReference\":\n if (!contextType) {\n return [];\n }\n return resolveFieldType(contextType, [expression.value.name], valueTypes)\n ? []\n : [\n {\n message: `Unknown context value: \"${expression.value.name}\".`,\n path: [...path, \"name\"],\n },\n ];\n case \"localReference\": {\n const local = locals.get(expression.value.name);\n if (!local) {\n return [\n {\n message: `Unknown expression binding: \"${expression.value.name}\".`,\n path: [...path, \"name\"],\n },\n ];\n }\n return [];\n }\n case \"getAt\":\n case \"objectLookup\":\n case \"linkHop\": {\n const childKey = expression.kind === \"objectLookup\" ? \"reference\" : \"source\";\n const child =\n expression.kind === \"objectLookup\" ? expression.value.reference : expression.value.source;\n const errors = validateExpression(\n child,\n parameters,\n [...path, childKey],\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n if (expression.kind === \"getAt\" && expression.value.path.length === 0) {\n errors.push({\n message: \"Get-at expression paths must not be empty.\",\n path: [...path, \"path\"],\n });\n }\n const resolved = resolveExpressionType(\n expression,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n if (!resolved) {\n errors.push({\n message:\n expression.kind === \"getAt\"\n ? \"Get-at expression source and path must resolve structurally.\"\n : expression.kind === \"objectLookup\"\n ? \"Object lookup references must resolve to an object reference.\"\n : \"Link hop must resolve to a named to-one link.\",\n path,\n });\n }\n return errors;\n }\n case \"struct\": {\n const errors: ValidationIssue[] = [];\n const names = new Set<string>();\n for (let index = 0; index < expression.value.fields.length; index++) {\n const field = expression.value.fields[index]!;\n if (names.has(field.name)) {\n errors.push({\n message: `Duplicate struct expression field: \"${field.name}\".`,\n path: [...path, \"fields\", index, \"name\"],\n });\n }\n names.add(field.name);\n errors.push(\n ...validateExpression(\n field.value,\n parameters,\n [...path, \"fields\", index, \"value\"],\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n )\n );\n }\n return errors;\n }\n case \"map\": {\n const errors = validateExpression(\n expression.value.source,\n parameters,\n [...path, \"source\"],\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n const sourceType = resolveExpressionType(\n expression.value.source,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n locals\n );\n const listType =\n sourceType && sourceType.kind !== \"ontologyObject\"\n ? unwrapOptionalType(sourceType, valueTypes)\n : undefined;\n if (sourceType && listType?.kind !== \"list\") {\n errors.push({\n message: \"Map expression source must resolve to a list.\",\n path: [...path, \"source\"],\n });\n }\n if (!expression.value.binding) {\n errors.push({\n message: \"Map expression binding must not be empty.\",\n path: [...path, \"binding\"],\n });\n }\n const bodyLocals = new Map(locals);\n bodyLocals.set(\n expression.value.binding,\n listType?.kind === \"list\" ? listType.value.elementType : { kind: \"unknown\", value: {} }\n );\n errors.push(\n ...validateExpression(\n expression.value.body,\n parameters,\n [...path, \"body\"],\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n bodyLocals\n )\n );\n return errors;\n }\n case \"uuid\":\n case \"now\":\n case \"literal\":\n return [];\n }\n}\n\nfunction unwrapOptionalType(type: TypeDef, valueTypes: ReadonlyMap<string, TypeDef>): TypeDef | undefined {\n const resolved = resolveType(type, valueTypes);\n return resolved?.kind === \"optional\" ? unwrapOptionalType(resolved.value.type, valueTypes) : resolved;\n}\n\nfunction areDefaultTypesCompatible(\n target: TypeDef,\n source: TypeDef,\n valueTypes: ReadonlyMap<string, TypeDef>\n): boolean {\n const targetType = unwrapOptionalType(target, valueTypes);\n const sourceType = unwrapOptionalType(source, valueTypes);\n if (!targetType || !sourceType) return false;\n if (targetType.kind === \"unknown\" || sourceType.kind === \"unknown\") return true;\n if (targetType.kind !== sourceType.kind) return false;\n if (targetType.kind === \"objectReference\" && sourceType.kind === \"objectReference\") {\n return targetType.value.objectType === sourceType.value.objectType;\n }\n if (targetType.kind === \"list\" && sourceType.kind === \"list\") {\n return areDefaultTypesCompatible(\n targetType.value.elementType,\n sourceType.value.elementType,\n valueTypes\n );\n }\n return true;\n}\n\nfunction validateActionObjectReference(\n reference: InputReferenceExpression,\n parameters: ReadonlyMap<string, ActionParameterDef>,\n path: (string | number)[],\n valueTypes: ReadonlyMap<string, TypeDef>,\n objectTypes: ReadonlyMap<string, ObjectTypeDef>\n): { errors: ValidationIssue[]; objectType?: ObjectTypeDef } {\n const parameterName = reference.name;\n const parameter = parameters.get(parameterName);\n if (!parameter) {\n return {\n errors: [\n {\n message: `Unknown action parameter: \"${parameterName}\".`,\n path: [...path, \"name\"],\n },\n ],\n };\n }\n\n const resolved = resolveType(parameter.type, valueTypes);\n if (!resolved || resolved.kind !== \"objectReference\") {\n return {\n errors: [\n {\n message: `Action target parameter \"${parameterName}\" must be an object reference.`,\n path: [...path, \"name\"],\n },\n ],\n };\n }\n\n const targetObjectType = objectTypes.get(resolved.value.objectType);\n return targetObjectType\n ? { errors: [], objectType: targetObjectType }\n : {\n errors: [\n {\n message: `Unknown object type reference: \"${resolved.value.objectType}\".`,\n path: [...path, \"name\"],\n },\n ],\n };\n}\n\nfunction validateActionPropertyAssignment(\n assignment: PropertyAssignment,\n target: ObjectTypeDef,\n parameters: ReadonlyMap<string, ActionParameterDef>,\n path: (string | number)[],\n valueTypes: ReadonlyMap<string, TypeDef>,\n objectTypes: ReadonlyMap<string, ObjectTypeDef>,\n linkTypes: readonly LinkTypeDef[],\n contextType: TypeDef | undefined\n): ValidationIssue[] {\n if (assignment.property.length === 0) {\n return [\n { message: \"Action property assignments must specify a property.\", path: [...path, \"property\"] },\n ];\n }\n\n const [propertyName, ...rest] = assignment.property;\n const property = target.properties.find((candidate) => candidate.name === propertyName);\n if (!property) {\n return [\n {\n message: `Unknown property \"${propertyName}\" on object type \"${target.name}\".`,\n path: [...path, \"property\"],\n },\n ];\n }\n\n const resolved = resolveFieldType(property.type, rest, valueTypes);\n const errors = validateExpression(\n assignment.value,\n parameters,\n [...path, \"value\"],\n valueTypes,\n objectTypes,\n linkTypes,\n contextType\n );\n\n return resolved\n ? errors\n : [\n ...errors,\n {\n message: `Invalid property \"${assignment.property.join(\".\")}\" on object type \"${target.name}\".`,\n path: [...path, \"property\"],\n },\n ];\n}\n\nfunction validateAction(\n action: ActionTypeDef,\n path: (string | number)[],\n valueTypes: ReadonlyMap<string, TypeDef>,\n objectTypes: ReadonlyMap<string, ObjectTypeDef>,\n linkTypes: readonly LinkTypeDef[],\n contextType: TypeDef | undefined\n): ValidationIssue[] {\n const errors: ValidationIssue[] = [];\n const parameters = new Map(action.parameters.map((parameter) => [parameter.name, parameter]));\n const seenParameters = new Set<string>();\n\n for (let index = 0; index < action.parameters.length; index++) {\n const parameter = action.parameters[index]!;\n const parameterPath = [...path, \"parameters\", index];\n\n if (seenParameters.has(parameter.name)) {\n errors.push({\n message: `Duplicate action parameter name: \"${parameter.name}\".`,\n path: [...parameterPath, \"name\"],\n });\n }\n seenParameters.add(parameter.name);\n\n errors.push(\n ...validateTypeDef(\n parameter.type,\n [...parameterPath, \"type\"],\n new Set(valueTypes.keys()),\n new Set(objectTypes.keys())\n )\n );\n\n if (parameter.defaultValue) {\n errors.push(\n ...validateExpression(\n parameter.defaultValue,\n parameters,\n [...parameterPath, \"defaultValue\"],\n valueTypes,\n objectTypes,\n linkTypes,\n contextType\n )\n );\n const sourceType = resolveExpressionType(\n parameter.defaultValue,\n parameters,\n valueTypes,\n objectTypes,\n linkTypes,\n contextType,\n new Map()\n );\n if (\n sourceType &&\n sourceType.kind !== \"ontologyObject\" &&\n !areDefaultTypesCompatible(parameter.type, sourceType, valueTypes)\n ) {\n errors.push({\n message: `Default value for \"${parameter.name}\" has an incompatible type.`,\n path: [...parameterPath, \"defaultValue\"],\n });\n }\n }\n }\n\n for (let index = 0; index < action.logic.length; index++) {\n const step = action.logic[index]!;\n const stepPath = [...path, \"logic\", index];\n\n switch (step.kind) {\n case \"createObject\": {\n const objectType = objectTypes.get(step.value.objectType);\n if (!objectType) {\n errors.push({\n message: `Unknown object type \"${step.value.objectType}\" in action \"${action.name}\".`,\n path: [...stepPath, \"value\", \"objectType\"],\n });\n continue;\n }\n for (let valueIndex = 0; valueIndex < step.value.values.length; valueIndex++) {\n errors.push(\n ...validateActionPropertyAssignment(\n step.value.values[valueIndex]!,\n objectType,\n parameters,\n [...stepPath, \"value\", \"values\", valueIndex],\n valueTypes,\n objectTypes,\n linkTypes,\n contextType\n )\n );\n }\n break;\n }\n case \"updateObject\": {\n const target = validateActionObjectReference(\n step.value.object,\n parameters,\n [...stepPath, \"value\", \"object\"],\n valueTypes,\n objectTypes\n );\n errors.push(...target.errors);\n if (!target.objectType) {\n continue;\n }\n for (let valueIndex = 0; valueIndex < step.value.values.length; valueIndex++) {\n errors.push(\n ...validateActionPropertyAssignment(\n step.value.values[valueIndex]!,\n target.objectType,\n parameters,\n [...stepPath, \"value\", \"values\", valueIndex],\n valueTypes,\n objectTypes,\n linkTypes,\n contextType\n )\n );\n }\n break;\n }\n case \"deleteObject\":\n errors.push(\n ...validateActionObjectReference(\n step.value.object,\n parameters,\n [...stepPath, \"value\", \"object\"],\n valueTypes,\n objectTypes\n ).errors\n );\n break;\n }\n }\n\n return errors;\n}\n\nfunction validateQueryFunctionType(\n queryFunctionType: QueryFunctionTypeDef,\n path: (string | number)[],\n valueTypeNames: Set<string>,\n objectTypeNames: Set<string>\n): ValidationIssue[] {\n const errors: ValidationIssue[] = [];\n const seenParameters = new Set<string>();\n\n for (let index = 0; index < queryFunctionType.parameters.length; index++) {\n const parameter = queryFunctionType.parameters[index]!;\n const parameterPath = [...path, \"parameters\", index];\n\n if (seenParameters.has(parameter.name)) {\n errors.push({\n message: `Duplicate query function parameter name: \"${parameter.name}\".`,\n path: [...parameterPath, \"name\"],\n });\n }\n seenParameters.add(parameter.name);\n\n errors.push(\n ...validateTypeDef(parameter.type, [...parameterPath, \"type\"], valueTypeNames, objectTypeNames)\n );\n }\n\n errors.push(\n ...validateTypeDef(\n queryFunctionType.returnType,\n [...path, \"returnType\"],\n valueTypeNames,\n objectTypeNames\n )\n );\n\n return errors;\n}\n\nexport function validate(ontology: OntologyIR): ValidationResult {\n const errors: ValidationIssue[] = [];\n\n // Collect value type names for ref resolution\n const valueTypeNames = new Set<string>();\n for (let i = 0; i < ontology.types.length; i++) {\n const vt = ontology.types[i]!;\n if (valueTypeNames.has(vt.name)) {\n errors.push({\n message: `Duplicate value type name: \"${vt.name}\".`,\n path: [\"types\", i, \"name\"],\n });\n }\n valueTypeNames.add(vt.name);\n }\n\n const objectTypeNames = new Set<string>();\n for (let i = 0; i < ontology.objectTypes.length; i++) {\n const ot = ontology.objectTypes[i]!;\n if (objectTypeNames.has(ot.name)) {\n errors.push({\n message: `Duplicate object type name: \"${ot.name}\".`,\n path: [\"objectTypes\", i, \"name\"],\n });\n }\n objectTypeNames.add(ot.name);\n }\n\n const valueTypes = new Map(ontology.types.map((type) => [type.name, type.type]));\n const objectTypes = new Map(ontology.objectTypes.map((objectType) => [objectType.name, objectType]));\n\n if (ontology.contextType) {\n errors.push(\n ...validateTypeDef(ontology.contextType, [\"contextType\"], valueTypeNames, objectTypeNames)\n );\n const resolvedContextType = resolveType(ontology.contextType, valueTypes);\n if (resolvedContextType?.kind === \"struct\") {\n const userField = resolvedContextType.value.fields.find((field) => field.name === \"user\");\n const unwrappedUserType = userField ? unwrapType(userField.type).type : undefined;\n const resolvedUserType = unwrappedUserType\n ? resolveType(unwrappedUserType, valueTypes)\n : undefined;\n if (userField && resolvedUserType?.kind !== \"objectReference\") {\n errors.push({\n message: 'Reserved context field \"user\" must be an object reference.',\n path: [\n \"contextType\",\n \"fields\",\n resolvedContextType.value.fields.indexOf(userField),\n \"type\",\n ],\n });\n }\n }\n }\n\n // Validate value type definitions once both namespaces are known.\n for (let i = 0; i < ontology.types.length; i++) {\n const vt = ontology.types[i]!;\n errors.push(...validateTypeDef(vt.type, [\"types\", i, \"type\"], valueTypeNames, objectTypeNames));\n }\n\n // Validate object types\n for (let i = 0; i < ontology.objectTypes.length; i++) {\n const ot = ontology.objectTypes[i]!;\n const otPath = [\"objectTypes\", i] as (string | number)[];\n\n // Validate properties\n errors.push(\n ...validateProperties(ot.properties, [...otPath, \"properties\"], valueTypeNames, objectTypeNames)\n );\n\n // Validate primary key references a valid property\n const propertyNames = new Set(ot.properties.map((p) => p.name));\n if (!propertyNames.has(ot.primaryKey)) {\n errors.push({\n message: `Primary key \"${ot.primaryKey}\" does not reference a valid property.`,\n path: [...otPath, \"primaryKey\"],\n });\n }\n if (ot.title && !propertyNames.has(ot.title)) {\n errors.push({\n message: `Title \"${ot.title}\" does not reference a valid property.`,\n path: [...otPath, \"title\"],\n });\n }\n }\n\n // Validate link types\n const linkIds = new Set<string>();\n const linkNames = new Set<string>();\n for (let i = 0; i < ontology.linkTypes.length; i++) {\n const lt = ontology.linkTypes[i]!;\n const ltPath = [\"linkTypes\", i] as (string | number)[];\n\n if (linkIds.has(lt.id)) {\n errors.push({\n message: `Duplicate link type id: \"${lt.id}\".`,\n path: [...ltPath, \"id\"],\n });\n }\n linkIds.add(lt.id);\n\n // Relationship names from a source object are keyed by target.name.\n const linkName = `${lt.source.objectType}:${lt.target.name}`;\n if (linkNames.has(linkName)) {\n errors.push({\n message: `Duplicate link type target name: \"${lt.target.name}\" on \"${lt.source.objectType}\".`,\n path: [...ltPath, \"target\", \"name\"],\n });\n }\n linkNames.add(linkName);\n\n if (!objectTypeNames.has(lt.source.objectType)) {\n errors.push({\n message: `Source object type \"${lt.source.objectType}\" does not exist.`,\n path: [...ltPath, \"source\", \"objectType\"],\n });\n }\n\n if (!objectTypeNames.has(lt.target.objectType)) {\n errors.push({\n message: `Target object type \"${lt.target.objectType}\" does not exist.`,\n path: [...ltPath, \"target\", \"objectType\"],\n });\n }\n\n const foreignKeyRoot = lt.foreignKey.split(\".\")[0]!;\n const sourceType = ontology.objectTypes.find((candidate) => candidate.name === lt.source.objectType);\n const sourceHasFk =\n sourceType?.properties.some((property) => property.name === foreignKeyRoot) ?? false;\n if (sourceType && !sourceHasFk) {\n errors.push({\n message: `Foreign key \"${lt.foreignKey}\" does not exist on source object type \"${lt.source.objectType}\" for link \"${lt.id}\".`,\n path: [...ltPath, \"foreignKey\"],\n });\n }\n }\n\n const actionNames = new Set<string>();\n for (let i = 0; i < ontology.actionTypes.length; i++) {\n const action = ontology.actionTypes[i]!;\n const actionPath = [\"actionTypes\", i] as (string | number)[];\n\n if (actionNames.has(action.name)) {\n errors.push({\n message: `Duplicate action type name: \"${action.name}\".`,\n path: [...actionPath, \"name\"],\n });\n }\n actionNames.add(action.name);\n\n errors.push(\n ...validateAction(\n action,\n actionPath,\n valueTypes,\n objectTypes,\n ontology.linkTypes,\n ontology.contextType\n )\n );\n }\n\n const queryFunctionTypeNames = new Set<string>();\n for (let i = 0; i < ontology.queryFunctionTypes.length; i++) {\n const queryFunctionType = ontology.queryFunctionTypes[i]!;\n const queryFunctionTypePath = [\"queryFunctionTypes\", i] as (string | number)[];\n\n if (queryFunctionTypeNames.has(queryFunctionType.name)) {\n errors.push({\n message: `Duplicate query function type name: \"${queryFunctionType.name}\".`,\n path: [...queryFunctionTypePath, \"name\"],\n });\n }\n queryFunctionTypeNames.add(queryFunctionType.name);\n\n errors.push(\n ...validateQueryFunctionType(\n queryFunctionType,\n queryFunctionTypePath,\n valueTypeNames,\n objectTypeNames\n )\n );\n }\n\n return errors.length === 0 ? { kind: \"ok\", value: undefined } : { kind: \"err\", value: errors };\n}\n"],"mappings":";;;;AAsBA,SAAS,yBACL,OACA,MACiB;CACjB,IAAI,CAAC,OAAO,OAAO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AE3B,OAAO,KACH,GAAG,eACC,QACA,YACA,YACA,aACA,SAAS,WACT,SAAS,WACb,CACJ;CACJ;CAEA,MAAM,yCAAyB,IAAI,IAAY;CAC/C,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,mBAAmB,QAAQ,KAAK;EACzD,MAAM,oBAAoB,SAAS,mBAAmB;EACtD,MAAM,wBAAwB,CAAC,sBAAsB,CAAC;EAEtD,IAAI,uBAAuB,IAAI,kBAAkB,IAAI,GACjD,OAAO,KAAK;GACR,SAAS,wCAAwC,kBAAkB,KAAK;GACxE,MAAM,CAAC,GAAG,uBAAuB,MAAM;EAC3C,CAAC;EAEL,uBAAuB,IAAI,kBAAkB,IAAI;EAEjD,OAAO,KACH,GAAG,0BACC,mBACA,uBACA,gBACA,eACJ,CACJ;CACJ;CAEA,OAAO,OAAO,WAAW,IAAI;EAAE,MAAM;EAAM,OAAO,KAAA;CAAU,IAAI;EAAE,MAAM;EAAO,OAAO;CAAO;AACjG"}
|
package/lib/json/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/json/index.ts"],"mappings":";;;YAaY,WAAW,WAAW,cAC5B,mBAAmB,MACnB,qBAAqB,MACrB,+BAA+B,MAC/B,sCAAsC,MACtC,kCAAkC;wBAiLxB,OAAO,WAAW,YAAY;EAC1C,IAAI;EACJ,QAAQ,WAAW;EACnB;;wBA2BY,OAAO,WAAW,YAAY;EAC1C,IAAI;EACJ,QAAQ,WAAW;EACnB"}
|
package/lib/json/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/json/index.ts"],"sourcesContent":["import { invariant } from \"@bobbyfidz/panic\";\nimport { Temporal } from \"temporal-polyfill\";\nimport { resolveType } from \"../utils/types.js\";\nimport type { OntologyIR, TypeDef } from \"../ir/generated/types.js\";\nimport type { OntologyObject } from \"../live/objects/OntologyObject.js\";\nimport type {\n OntologyActionParametersTarget,\n OntologyObjectTarget,\n OntologyQueryFunctionParametersTarget,\n OntologyQueryFunctionReturnTarget,\n OntologyTypeTarget,\n} from \"../utils/targets.js\";\n\nexport type JsonTarget<IR extends OntologyIR> =\n | OntologyTypeTarget<IR>\n | OntologyObjectTarget<IR>\n | OntologyActionParametersTarget<IR>\n | OntologyQueryFunctionParametersTarget<IR>\n | OntologyQueryFunctionReturnTarget<IR>;\n\nfunction assertRecord(value: unknown): asserts value is OntologyObject {\n invariant(typeof value === \"object\" && value !== null && !Array.isArray(value), \"Expected JSON object.\");\n}\n\nfunction assertArray(value: unknown): asserts value is unknown[] {\n invariant(Array.isArray(value), \"Expected JSON array.\");\n}\n\nfunction getNamedType(ir: OntologyIR, name: string): TypeDef {\n const namedType = ir.types.find((candidate) => candidate.name === name);\n invariant(namedType, `Unknown ontology type \"${name}\".`);\n return namedType.type;\n}\n\nfunction getObjectType(ir: OntologyIR, name: string): OntologyIR[\"objectTypes\"][number] {\n const objectType = ir.objectTypes.find((candidate) => candidate.name === name);\n invariant(objectType, `Unknown object type \"${name}\".`);\n return objectType;\n}\n\nfunction getActionType(ir: OntologyIR, name: string): OntologyIR[\"actionTypes\"][number] {\n const actionType = ir.actionTypes.find((candidate) => candidate.name === name);\n invariant(actionType, `Unknown action type \"${name}\".`);\n return actionType;\n}\n\nfunction getQueryFunctionType(ir: OntologyIR, name: string): OntologyIR[\"queryFunctionTypes\"][number] {\n const queryFunctionType = ir.queryFunctionTypes.find((candidate) => candidate.name === name);\n invariant(queryFunctionType, `Unknown query function type \"${name}\".`);\n return queryFunctionType;\n}\n\nfunction resolveTargetType<IR extends OntologyIR>(ir: IR, target: JsonTarget<IR>): TypeDef | undefined {\n switch (target.kind) {\n case \"type\":\n return getNamedType(ir, target.name);\n case \"object\":\n case \"actionParameters\":\n case \"queryFunctionParameters\":\n return undefined;\n case \"queryFunctionReturn\":\n return getQueryFunctionType(ir, target.queryFunctionType).returnType;\n }\n}\n\nfunction decodeValue(ir: OntologyIR, type: TypeDef, value: unknown, normalizeOptionalNull = false): unknown {\n const resolvedType = resolveType(ir, type);\n if (value === undefined) return undefined;\n if (value === null) {\n return normalizeOptionalNull && resolvedType.kind === \"optional\" ? undefined : null;\n }\n\n switch (resolvedType.kind) {\n case \"timestamp\":\n return typeof value === \"string\" ? Temporal.Instant.from(value) : value;\n case \"date\":\n return typeof value === \"string\" ? Temporal.PlainDate.from(value) : value;\n case \"optional\":\n return decodeValue(ir, resolvedType.value.type, value, normalizeOptionalNull);\n case \"list\":\n assertArray(value);\n return value.map((item) =>\n decodeValue(ir, resolvedType.value.elementType, item, normalizeOptionalNull)\n );\n case \"map\":\n assertRecord(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [\n key,\n decodeValue(ir, resolvedType.value.valueType, entry, normalizeOptionalNull),\n ])\n );\n case \"struct\":\n assertRecord(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => {\n const field = resolvedType.value.fields.find((candidate) => candidate.name === key);\n return [key, field ? decodeValue(ir, field.type, entry, normalizeOptionalNull) : entry];\n })\n );\n default:\n return value;\n }\n}\n\nfunction encodeValue(ir: OntologyIR, type: TypeDef, value: unknown): unknown {\n if (value === undefined || value === null) return value;\n const resolvedType = resolveType(ir, type);\n\n switch (resolvedType.kind) {\n case \"timestamp\":\n case \"date\":\n invariant(\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { toString?: unknown }).toString === \"function\",\n `Expected ${resolvedType.kind} value.`\n );\n return (value as { toString: () => string }).toString();\n case \"optional\":\n return encodeValue(ir, resolvedType.value.type, value);\n case \"list\":\n assertArray(value);\n return value.map((item) => encodeValue(ir, resolvedType.value.elementType, item));\n case \"map\":\n assertRecord(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [\n key,\n encodeValue(ir, resolvedType.value.valueType, entry),\n ])\n );\n case \"struct\":\n assertRecord(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => {\n const field = resolvedType.value.fields.find((candidate) => candidate.name === key);\n return [key, field ? encodeValue(ir, field.type, entry) : entry];\n })\n );\n default:\n return value;\n }\n}\n\nfunction decodeObject(ir: OntologyIR, objectTypeName: string, value: unknown): OntologyObject {\n assertRecord(value);\n const objectType = getObjectType(ir, objectTypeName);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => {\n const property = objectType.properties.find((candidate) => candidate.name === key);\n return [key, property ? decodeValue(ir, property.type, entry, true) : entry];\n })\n );\n}\n\nfunction encodeObject(ir: OntologyIR, objectTypeName: string, value: unknown): OntologyObject {\n assertRecord(value);\n const objectType = getObjectType(ir, objectTypeName);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => {\n const property = objectType.properties.find((candidate) => candidate.name === key);\n return [key, property ? encodeValue(ir, property.type, entry) : entry];\n })\n );\n}\n\nfunction decodeParameters(\n ir: OntologyIR,\n parameters: { name: string; type: TypeDef }[],\n value: unknown\n): OntologyObject {\n assertRecord(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => {\n const parameter = parameters.find((candidate) => candidate.name === key);\n return [key, parameter ? decodeValue(ir, parameter.type, entry) : entry];\n })\n );\n}\n\nfunction encodeParameters(\n ir: OntologyIR,\n parameters: { name: string; type: TypeDef }[],\n value: unknown\n): OntologyObject {\n assertRecord(value);\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => {\n const parameter = parameters.find((candidate) => candidate.name === key);\n return [key, parameter ? encodeValue(ir, parameter.type, entry) : entry];\n })\n );\n}\n\nexport function decode<IR extends OntologyIR>(opts: {\n ir: IR;\n target: JsonTarget<IR>;\n value: unknown;\n}): unknown {\n if (opts.target.kind === \"object\") {\n return decodeObject(opts.ir, opts.target.name, opts.value);\n }\n if (opts.target.kind === \"actionParameters\") {\n return decodeParameters(\n opts.ir,\n getActionType(opts.ir, opts.target.actionType).parameters,\n opts.value\n );\n }\n if (opts.target.kind === \"queryFunctionParameters\") {\n return decodeParameters(\n opts.ir,\n getQueryFunctionType(opts.ir, opts.target.queryFunctionType).parameters,\n opts.value\n );\n }\n return decodeValue(\n opts.ir,\n resolveTargetType(opts.ir, opts.target)!,\n opts.value,\n opts.target.kind === \"queryFunctionReturn\"\n );\n}\n\nexport function encode<IR extends OntologyIR>(opts: {\n ir: IR;\n target: JsonTarget<IR>;\n value: unknown;\n}): unknown {\n if (opts.target.kind === \"object\") {\n return encodeObject(opts.ir, opts.target.name, opts.value);\n }\n if (opts.target.kind === \"actionParameters\") {\n return encodeParameters(\n opts.ir,\n getActionType(opts.ir, opts.target.actionType).parameters,\n opts.value\n );\n }\n if (opts.target.kind === \"queryFunctionParameters\") {\n return encodeParameters(\n opts.ir,\n getQueryFunctionType(opts.ir, opts.target.queryFunctionType).parameters,\n opts.value\n );\n }\n return encodeValue(opts.ir, resolveTargetType(opts.ir, opts.target)!, opts.value);\n}\n"],"mappings":";;;;AAoBA,SAAS,aAAa,OAAiD;CACnE,UAAU,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,GAAG,uBAAuB;AAC3G;AAEA,SAAS,YAAY,OAA4C;CAC7D,UAAU,MAAM,QAAQ,KAAK,GAAG,sBAAsB;AAC1D;AAEA,SAAS,aAAa,IAAgB,MAAuB;CACzD,MAAM,YAAY,GAAG,MAAM,MAAM,cAAc,UAAU,SAAS,IAAI;CACtE,UAAU,WAAW,0BAA0B,KAAK,GAAG;CACvD,OAAO,UAAU;AACrB;AAEA,SAAS,cAAc,IAAgB,MAAiD;CACpF,MAAM,aAAa,GAAG,YAAY,MAAM,cAAc,UAAU,SAAS,IAAI;CAC7E,UAAU,YAAY,wBAAwB,KAAK,GAAG;CACtD,OAAO;AACX;AAEA,SAAS,cAAc,IAAgB,MAAiD;CACpF,MAAM,aAAa,GAAG,YAAY,MAAM,cAAc,UAAU,SAAS,IAAI;CAC7E,UAAU,YAAY,wBAAwB,KAAK,GAAG;CACtD,OAAO;AACX;AAEA,SAAS,qBAAqB,IAAgB,MAAwD;CAClG,MAA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K,OAAO,UAAU,CAAC,CAAC,YAC/C,KAAK,KACT;CAEJ,IAAI,KAAK,OAAO,SAAS,2BACrB,OAAO,iBACH,KAAK,IACL,qBAAqB,KAAK,IAAI,KAAK,OAAO,iBAAiB,CAAC,CAAC,YAC7D,KAAK,KACT;CAEJ,OAAO,YACH,KAAK,IACL,kBAAkB,KAAK,IAAI,KAAK,MAAM,GACtC,KAAK,OACL,KAAK,OAAO,SAAS,qBACzB;AACJ;AAEA,SAAgB,OAA8B,MAIlC;CACR,IAAI,KAAK,OAAO,SAAS,UACrB,OAAO,aAAa,KAAK,IAAI,KAAK,OAAO,MAAM,KAAK,KAAK;CAE7D,IAAI,KAAK,OAAO,SAAS,oBACrB,OAAO,iBACH,KAAK,IACL,cAAc,KAAK,IAAI,KAAK,OAAO,UAAU,CAAC,CAAC,YAC/C,KAAK,KACT;CAEJ,IAAI,KAAK,OAAO,SAAS,2BACrB,OAAO,iBACH,KAAK,IACL,qBAAqB,KAAK,IAAI,KAAK,OAAO,iBAAiB,CAAC,CAAC,YAC7D,KAAK,KACT;CAEJ,OAAO,YAAY,KAAK,IAAI,kBAAkB,KAAK,IAAI,KAAK,MAAM,GAAI,KAAK,KAAK;AACpF"}
|
package/lib/lenses.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Lens, ObjectTypeDef } from "./ir/generated/types.js";
|
|
2
|
-
import "./ir/index.js";
|
|
3
|
-
//#region src/lenses.d.ts
|
|
4
|
-
export interface ApplyObjectTypeLensOptions {
|
|
5
|
-
name: string;
|
|
6
|
-
displayName?: string;
|
|
7
|
-
pluralDisplayName?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare function applyLensToObjectType(source: ObjectTypeDef, lens: Lens, options: ApplyObjectTypeLensOptions): ObjectTypeDef;
|
|
10
|
-
export declare function applyLensToObject<Source extends Record<string, unknown>, Target extends Record<string, unknown>>(source: Source, lens: Lens): Target;
|
|
11
|
-
/**
|
|
12
|
-
* Maps a target-model field path back to its source-model path so simple
|
|
13
|
-
* target-side queries can be pushed through a lens. This is path provenance,
|
|
14
|
-
* not a general inverse for values or schemas: selected-out data cannot be
|
|
15
|
-
* reconstructed. A future lens query compiler can use this as its direct-path
|
|
16
|
-
* primitive while handling computed/list operations, local evaluation, and
|
|
17
|
-
* unsupported query rewrites at the expression or query-plan level.
|
|
18
|
-
*/
|
|
19
|
-
export declare function mapTargetPathToSourceWithLens(path: readonly string[], lens: Lens): string[];
|
|
20
|
-
//#endregion
|
|
21
|
-
//# sourceMappingURL=lenses.d.ts.map
|
package/lib/lenses.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lenses.d.ts","names":[],"sources":["../src/lenses.ts"],"mappings":";;;iBAIiB;EACb;EACA;EACA;;wBAiDY,sBACZ,QAAQ,eACR,MAAM,MACN,SAAS,6BACV;wBAoDa,kBACZ,eAAe,yBACf,eAAe,yBACjB,QAAQ,QAAQ,MAAM,OAAO;;;;;;;;;wBA8Bf,8BAA8B,yBAAyB,MAAM"}
|
package/lib/lenses.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { getAtPath, setAtPath, unsetAtPath } from "./utils/paths.js";
|
|
2
|
-
import { capitalCase } from "change-case";
|
|
3
|
-
//#region src/lenses.ts
|
|
4
|
-
function structFields(type) {
|
|
5
|
-
if (type.kind === "struct") return type.value.fields;
|
|
6
|
-
if (type.kind === "optional" && type.value.type.kind === "struct") return type.value.type.value.fields;
|
|
7
|
-
}
|
|
8
|
-
function removeField(fields, path) {
|
|
9
|
-
const [name, ...rest] = path;
|
|
10
|
-
if (!name) throw new Error("Lens paths must not be empty.");
|
|
11
|
-
const index = fields.findIndex((field) => field.name === name);
|
|
12
|
-
if (index < 0) throw new Error(`Lens source path "${path.join(".")}" does not exist.`);
|
|
13
|
-
if (rest.length === 0) return fields.splice(index, 1)[0];
|
|
14
|
-
const nested = structFields(fields[index].type);
|
|
15
|
-
if (!nested) throw new Error(`Lens source path "${path.join(".")}" does not traverse a struct.`);
|
|
16
|
-
return removeField(nested, rest);
|
|
17
|
-
}
|
|
18
|
-
function insertField(fields, path, field) {
|
|
19
|
-
const [name, ...rest] = path;
|
|
20
|
-
if (!name) throw new Error("Lens paths must not be empty.");
|
|
21
|
-
if (rest.length === 0) {
|
|
22
|
-
if (fields.some((candidate) => candidate.name === name)) throw new Error(`Lens target path "${path.join(".")}" already exists.`);
|
|
23
|
-
fields.push({
|
|
24
|
-
...field,
|
|
25
|
-
name,
|
|
26
|
-
displayName: capitalCase(name)
|
|
27
|
-
});
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const parent = fields.find((candidate) => candidate.name === name);
|
|
31
|
-
if (!parent) throw new Error(`Lens target parent "${path.slice(0, -1).join(".")}" does not exist.`);
|
|
32
|
-
const nested = structFields(parent.type);
|
|
33
|
-
if (!nested) throw new Error(`Lens target path "${path.join(".")}" does not traverse a struct.`);
|
|
34
|
-
insertField(nested, rest, field);
|
|
35
|
-
}
|
|
36
|
-
function applyLensToObjectType(source, lens, options) {
|
|
37
|
-
const target = structuredClone(source);
|
|
38
|
-
target.name = options.name;
|
|
39
|
-
target.displayName = options.displayName ?? capitalCase(options.name);
|
|
40
|
-
target.pluralDisplayName = options.pluralDisplayName ?? `${target.displayName}s`;
|
|
41
|
-
for (const operation of lens.operations) switch (operation.kind) {
|
|
42
|
-
case "move": {
|
|
43
|
-
const field = removeField(target.properties, operation.value.from);
|
|
44
|
-
insertField(target.properties, operation.value.to, field);
|
|
45
|
-
if (operation.value.from.length === 1 && operation.value.from[0] === target.primaryKey) {
|
|
46
|
-
if (operation.value.to.length !== 1) throw new Error("An object primary key cannot be moved into a nested path.");
|
|
47
|
-
target.primaryKey = operation.value.to[0];
|
|
48
|
-
}
|
|
49
|
-
if (operation.value.from.length === 1 && operation.value.from[0] === target.title) target.title = operation.value.to.length === 1 ? operation.value.to[0] : void 0;
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
case "select": {
|
|
53
|
-
const selected = new Set(operation.value.properties);
|
|
54
|
-
target.properties = target.properties.filter((property) => selected.has(property.name));
|
|
55
|
-
if (!selected.has(target.primaryKey)) throw new Error(`Lens selection must retain primary key "${target.primaryKey}".`);
|
|
56
|
-
if (target.title && !selected.has(target.title)) target.title = void 0;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return target;
|
|
61
|
-
}
|
|
62
|
-
function cloneLensValue(value) {
|
|
63
|
-
if (Array.isArray(value)) return value.map(cloneLensValue);
|
|
64
|
-
if (value && typeof value === "object") {
|
|
65
|
-
const prototype = Object.getPrototypeOf(value);
|
|
66
|
-
if (prototype === Object.prototype || prototype === null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cloneLensValue(entry)]));
|
|
67
|
-
}
|
|
68
|
-
return value;
|
|
69
|
-
}
|
|
70
|
-
function applyLensToObject(source, lens) {
|
|
71
|
-
let target = cloneLensValue(source);
|
|
72
|
-
for (const operation of lens.operations) switch (operation.kind) {
|
|
73
|
-
case "move": {
|
|
74
|
-
const value = getAtPath(target, operation.value.from);
|
|
75
|
-
target = unsetAtPath(target, operation.value.from);
|
|
76
|
-
target = setAtPath(target, operation.value.to, value);
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
case "select": {
|
|
80
|
-
const selected = new Set(operation.value.properties);
|
|
81
|
-
for (const property of Object.keys(target)) if (!selected.has(property)) delete target[property];
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return target;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Maps a target-model field path back to its source-model path so simple
|
|
89
|
-
* target-side queries can be pushed through a lens. This is path provenance,
|
|
90
|
-
* not a general inverse for values or schemas: selected-out data cannot be
|
|
91
|
-
* reconstructed. A future lens query compiler can use this as its direct-path
|
|
92
|
-
* primitive while handling computed/list operations, local evaluation, and
|
|
93
|
-
* unsupported query rewrites at the expression or query-plan level.
|
|
94
|
-
*/
|
|
95
|
-
function mapTargetPathToSourceWithLens(path, lens) {
|
|
96
|
-
let rewritten = [...path];
|
|
97
|
-
for (const operation of [...lens.operations].reverse()) switch (operation.kind) {
|
|
98
|
-
case "move": {
|
|
99
|
-
const target = operation.value.to;
|
|
100
|
-
if (rewritten.length >= target.length && target.every((segment, index) => rewritten[index] === segment)) rewritten = [...operation.value.from, ...rewritten.slice(target.length)];
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
case "select": if (rewritten[0] && !operation.value.properties.includes(rewritten[0])) throw new Error(`Lens target path "${path.join(".")}" is not selected.`);
|
|
104
|
-
}
|
|
105
|
-
return rewritten;
|
|
106
|
-
}
|
|
107
|
-
//#endregion
|
|
108
|
-
export { applyLensToObject, applyLensToObjectType, mapTargetPathToSourceWithLens };
|
|
109
|
-
|
|
110
|
-
//# sourceMappingURL=lenses.js.map
|
package/lib/lenses.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lenses.js","names":[],"sources":["../src/lenses.ts"],"sourcesContent":["import { capitalCase } from \"change-case\";\nimport { getAtPath, setAtPath, unsetAtPath } from \"./utils/paths.js\";\nimport type { FieldDef, Lens, ObjectTypeDef, PropertyDef, TypeDef } from \"./ir/index.js\";\n\nexport interface ApplyObjectTypeLensOptions {\n name: string;\n displayName?: string;\n pluralDisplayName?: string;\n}\n\nfunction structFields(type: TypeDef): FieldDef[] | undefined {\n if (type.kind === \"struct\") return type.value.fields;\n if (type.kind === \"optional\" && type.value.type.kind === \"struct\") {\n return type.value.type.value.fields;\n }\n return undefined;\n}\n\nfunction removeField(fields: PropertyDef[] | FieldDef[], path: readonly string[]): PropertyDef | FieldDef {\n const [name, ...rest] = path;\n if (!name) throw new Error(\"Lens paths must not be empty.\");\n const index = fields.findIndex((field) => field.name === name);\n if (index < 0) throw new Error(`Lens source path \"${path.join(\".\")}\" does not exist.`);\n if (rest.length === 0) return fields.splice(index, 1)[0]!;\n\n const nested = structFields(fields[index]!.type);\n if (!nested) throw new Error(`Lens source path \"${path.join(\".\")}\" does not traverse a struct.`);\n return removeField(nested, rest);\n}\n\nfunction insertField(\n fields: PropertyDef[] | FieldDef[],\n path: readonly string[],\n field: PropertyDef | FieldDef\n): void {\n const [name, ...rest] = path;\n if (!name) throw new Error(\"Lens paths must not be empty.\");\n if (rest.length === 0) {\n if (fields.some((candidate) => candidate.name === name)) {\n throw new Error(`Lens target path \"${path.join(\".\")}\" already exists.`);\n }\n fields.push({\n ...field,\n name,\n displayName: capitalCase(name),\n });\n return;\n }\n\n const parent = fields.find((candidate) => candidate.name === name);\n if (!parent) throw new Error(`Lens target parent \"${path.slice(0, -1).join(\".\")}\" does not exist.`);\n const nested = structFields(parent.type);\n if (!nested) throw new Error(`Lens target path \"${path.join(\".\")}\" does not traverse a struct.`);\n insertField(nested, rest, field);\n}\n\nexport function applyLensToObjectType(\n source: ObjectTypeDef,\n lens: Lens,\n options: ApplyObjectTypeLensOptions\n): ObjectTypeDef {\n const target = structuredClone(source);\n target.name = options.name;\n target.displayName = options.displayName ?? capitalCase(options.name);\n target.pluralDisplayName = options.pluralDisplayName ?? `${target.displayName}s`;\n\n for (const operation of lens.operations) {\n switch (operation.kind) {\n case \"move\": {\n const field = removeField(target.properties, operation.value.from);\n insertField(target.properties, operation.value.to, field);\n if (operation.value.from.length === 1 && operation.value.from[0] === target.primaryKey) {\n if (operation.value.to.length !== 1) {\n throw new Error(\"An object primary key cannot be moved into a nested path.\");\n }\n target.primaryKey = operation.value.to[0]!;\n }\n if (operation.value.from.length === 1 && operation.value.from[0] === target.title) {\n target.title = operation.value.to.length === 1 ? operation.value.to[0] : undefined;\n }\n break;\n }\n case \"select\": {\n const selected = new Set(operation.value.properties);\n target.properties = target.properties.filter((property) => selected.has(property.name));\n if (!selected.has(target.primaryKey)) {\n throw new Error(`Lens selection must retain primary key \"${target.primaryKey}\".`);\n }\n if (target.title && !selected.has(target.title)) target.title = undefined;\n break;\n }\n }\n }\n\n return target;\n}\n\nfunction cloneLensValue(value: unknown): unknown {\n if (Array.isArray(value)) {\n return value.map(cloneLensValue);\n }\n if (value && typeof value === \"object\") {\n const prototype = Object.getPrototypeOf(value) as unknown;\n if (prototype === Object.prototype || prototype === null) {\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [key, cloneLensValue(entry)])\n );\n }\n }\n return value;\n}\n\nexport function applyLensToObject<\n Source extends Record<string, unknown>,\n Target extends Record<string, unknown>,\n>(source: Source, lens: Lens): Target {\n let target = cloneLensValue(source) as Record<string, unknown>;\n for (const operation of lens.operations) {\n switch (operation.kind) {\n case \"move\": {\n const value = getAtPath(target, operation.value.from);\n target = unsetAtPath(target, operation.value.from);\n target = setAtPath(target, operation.value.to, value);\n break;\n }\n case \"select\": {\n const selected = new Set(operation.value.properties);\n for (const property of Object.keys(target)) {\n if (!selected.has(property)) delete target[property];\n }\n break;\n }\n }\n }\n return target as Target;\n}\n\n/**\n * Maps a target-model field path back to its source-model path so simple\n * target-side queries can be pushed through a lens. This is path provenance,\n * not a general inverse for values or schemas: selected-out data cannot be\n * reconstructed. A future lens query compiler can use this as its direct-path\n * primitive while handling computed/list operations, local evaluation, and\n * unsupported query rewrites at the expression or query-plan level.\n */\nexport function mapTargetPathToSourceWithLens(path: readonly string[], lens: Lens): string[] {\n let rewritten = [...path];\n for (const operation of [...lens.operations].reverse()) {\n switch (operation.kind) {\n case \"move\": {\n const target = operation.value.to;\n if (\n rewritten.length >= target.length &&\n target.every((segment, index) => rewritten[index] === segment)\n ) {\n rewritten = [...operation.value.from, ...rewritten.slice(target.length)];\n }\n break;\n }\n case \"select\":\n if (rewritten[0] && !operation.value.properties.includes(rewritten[0])) {\n throw new Error(`Lens target path \"${path.join(\".\")}\" is not selected.`);\n }\n break;\n }\n }\n return rewritten;\n}\n"],"mappings":";;;AAUA,SAAS,aAAa,MAAuC;CACzD,IAAI,KAAK,SAAS,UAAU,OAAO,KAAK,MAAM;CAC9C,IAAI,KAAK,SAAS,cA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CAGnF;CAEJ,OAAO;AACX"}
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { Result, attachment } from "../utils/values.js";
|
|
2
|
-
import { AttachmentTypeDef, OntologyIR } from "../ir/generated/types.js";
|
|
3
|
-
import { ValidationIssue } from "../utils/validation.js";
|
|
4
|
-
import "../ir/index.js";
|
|
5
|
-
import { Uncertain } from "../utils/uncertain.js";
|
|
6
|
-
import { PartialAttachmentMetadata } from "./attachments/types.js";
|
|
7
|
-
import { Collection, CollectionConfig, UtilsRecord } from "@tanstack/db";
|
|
8
|
-
//#region src/live/OntologyBackendAdapter.d.ts
|
|
9
|
-
export interface OntologyCollectionUtils extends UtilsRecord {
|
|
10
|
-
/** Fetch and atomically replace the source snapshot, when supported by the adapter. */
|
|
11
|
-
refresh?: () => Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
export type OntologyCollectionOptions = Omit<CollectionConfig<Record<string, unknown>, string | number, never, OntologyCollectionUtils>, "getKey">;
|
|
14
|
-
export interface OntologyAttachmentUpload {
|
|
15
|
-
/**
|
|
16
|
-
* The attachment referenced by the prepared action parameters. Its ID is an
|
|
17
|
-
* opaque local handle and is not guaranteed to be valid for the backend.
|
|
18
|
-
*/
|
|
19
|
-
attachment: attachment;
|
|
20
|
-
blob: Blob;
|
|
21
|
-
target?: AttachmentTypeDef;
|
|
22
|
-
}
|
|
23
|
-
export interface OntologyAttachmentIdMapping {
|
|
24
|
-
/** The opaque attachment ID used before the backend canonicalized it. */
|
|
25
|
-
localId: string;
|
|
26
|
-
/** The canonical attachment ID returned by the backend. */
|
|
27
|
-
remoteId: string;
|
|
28
|
-
}
|
|
29
|
-
export interface OntologyApplyActionResult {
|
|
30
|
-
/**
|
|
31
|
-
* Mappings for uploaded attachments whose canonical backend IDs differ from
|
|
32
|
-
* the local IDs supplied in `ApplyActionLiveOpts.attachmentUploads`.
|
|
33
|
-
*/
|
|
34
|
-
attachmentIdMappings?: OntologyAttachmentIdMapping[];
|
|
35
|
-
}
|
|
36
|
-
export interface ApplyActionLiveOpts {
|
|
37
|
-
objects: Record<string, Collection<Record<string, unknown>>>;
|
|
38
|
-
context?: Record<string, unknown>;
|
|
39
|
-
/**
|
|
40
|
-
* Attachments that must be uploaded as part of action execution. Adapters
|
|
41
|
-
* must treat their IDs as opaque local handles, substitute any backend IDs or
|
|
42
|
-
* references required by the action invocation, and return an ID mapping for
|
|
43
|
-
* every upload whose canonical backend ID differs.
|
|
44
|
-
*/
|
|
45
|
-
attachmentUploads?: OntologyAttachmentUpload[];
|
|
46
|
-
idempotencyKey?: string;
|
|
47
|
-
}
|
|
48
|
-
export interface ValidateActionLiveOpts {
|
|
49
|
-
objects: Record<string, Collection<Record<string, unknown>>>;
|
|
50
|
-
context?: Record<string, unknown>;
|
|
51
|
-
}
|
|
52
|
-
export interface ValidateActionDraftLiveOpts extends ValidateActionLiveOpts {
|
|
53
|
-
knownParameters: readonly string[];
|
|
54
|
-
}
|
|
55
|
-
export interface RunQueryLiveOpts {
|
|
56
|
-
objects: Record<string, Collection<Record<string, unknown>>>;
|
|
57
|
-
context?: Record<string, unknown>;
|
|
58
|
-
}
|
|
59
|
-
export interface OntologyAttachmentsAdapter {
|
|
60
|
-
/**
|
|
61
|
-
* Generates a preferred ID for an attachment created directly against this adapter.
|
|
62
|
-
*
|
|
63
|
-
* This is a hint, not an invariant. Attachments can arrive with IDs generated elsewhere,
|
|
64
|
-
* so adapters must accept IDs downstream that were not produced by this function.
|
|
65
|
-
*/
|
|
66
|
-
generateAttachmentId?: (blob: Blob, opts: {
|
|
67
|
-
target?: AttachmentTypeDef;
|
|
68
|
-
}) => Promise<string> | string;
|
|
69
|
-
canMaterializeAttachment?: (attachment: attachment, opts: {
|
|
70
|
-
target?: AttachmentTypeDef;
|
|
71
|
-
}) => boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Materializes an attachment in the backend.
|
|
74
|
-
*
|
|
75
|
-
* The incoming attachment ID is opaque and may not be valid for this backend. When
|
|
76
|
-
* the backend assigns or requires another ID, return an attachment containing that
|
|
77
|
-
* canonical ID so the caller can rewrite parameters and bind the resulting mapping.
|
|
78
|
-
*/
|
|
79
|
-
materializeAttachment?: (attachment: attachment, blob: Blob, opts: {
|
|
80
|
-
target?: AttachmentTypeDef;
|
|
81
|
-
}) => Promise<attachment | void>;
|
|
82
|
-
getAttachmentContent: (attachment: attachment) => Promise<Blob>;
|
|
83
|
-
getAttachmentMetadata?: (attachment: attachment, selection: readonly (keyof PartialAttachmentMetadata)[]) => Promise<PartialAttachmentMetadata>;
|
|
84
|
-
}
|
|
85
|
-
export interface OntologyBackendAdapter {
|
|
86
|
-
name: string;
|
|
87
|
-
/**
|
|
88
|
-
* Whether this adapter participates in long-lived synchronization.
|
|
89
|
-
*
|
|
90
|
-
* Defaults to true. Non-live adapters support confirmed request/response
|
|
91
|
-
* operations but cannot safely back optimistic actions.
|
|
92
|
-
*/
|
|
93
|
-
live?: boolean;
|
|
94
|
-
getCollectionOptions: (objectType: string) => OntologyCollectionOptions;
|
|
95
|
-
applyAction: (name: string, parameters: Record<string, unknown>, live: ApplyActionLiveOpts) => Promise<OntologyApplyActionResult | void>;
|
|
96
|
-
validateAction?: (name: string, parameters: Record<string, unknown>, live: ValidateActionLiveOpts) => Promise<Uncertain<Result<void, readonly ValidationIssue[]>>>;
|
|
97
|
-
validateActionDraft?: (name: string, parameters: Record<string, unknown>, live: ValidateActionDraftLiveOpts) => Promise<Uncertain<Result<void, readonly ValidationIssue[]>>>;
|
|
98
|
-
runQueryFunction: (name: string, parameters: Record<string, unknown>, live: RunQueryLiveOpts) => Promise<unknown>;
|
|
99
|
-
attachments?: OntologyAttachmentsAdapter;
|
|
100
|
-
cleanup?: () => void | Promise<void>;
|
|
101
|
-
}
|
|
102
|
-
export type OntologyBackendAdapterProvider<Context extends Record<string, unknown> = Record<string, unknown>> = (ir: OntologyIR, context: Context) => OntologyBackendAdapter | Promise<OntologyBackendAdapter>;
|
|
103
|
-
//#endregion
|
|
104
|
-
//# sourceMappingURL=OntologyBackendAdapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"OntologyBackendAdapter.d.ts","names":["v.attachment","v.Result"],"sources":["../../src/live/OntologyBackendAdapter.ts"],"mappings":";;;;;;;;iBAOiB,gCAAgC;;EAE7C,gBAAgB;;YAGR,4BAA4B,KACpC,iBAAiB,iDAAiD;iBAIrD;;;;;EAKb,YAAYA;EACZ,MAAM;EACN,SAAS;;iBAGI;;EAEb;;EAEA;;iBAGa;;;;;EAKb,uBAAuB;;iBAGV;EACb,SAAS,eAAe,WAAW;EACnC,UAAU;;;;;;;EAOV,oBAAoB;EACpB;;iBAGa;EACb,SAAS,eAAe,WAAW;EACnC,UAAU;;iBAGG,oCAAoC;EACjD;;iBAGa;EACb,SAAS,eAAe,WAAW;EACnC,UAAU;;iBAGG;;;;;;;EAOb,wBACI,MAAM,MACN;IACI,SAAS;QAEZ;EACL,4BACI,YAAYA,YACZ;IACI,SAAS;;;;;;;;;EAUjB,yBACI,YAAYA,YACZ,MAAM,MACN;IACI,SAAS;QAEZ,QAAQA;EACb,uBAAuB,YAAYA,eAAiB,QAAQ;EAC5D,yBACI,YAAYA,YACZ,2BAA2B,iCAC1B,QAAQ;;iBAGA;EACb;;;;;;;EAOA;EACA,uBAAuB,uBAAuB;EAC9C,cACI,cACA,YAAY,yBACZ,MAAM,wBACL,QAAQ;EACb,kBACI,cACA,YAAY,yBACZ,MAAM,2BACL,QAAQ,UAAUC,sBAAwB;EAC/C,uBACI,cACA,YAAY,yBACZ,MAAM,gCACL,QAAQ,UAAUA,sBAAwB;EAC/C,mBACI,cACA,YAAY,yBACZ,MAAM,qBACL;EACL,cAAc;EACd,uBAAuB;;YAIf,+BACR,gBAAgB,0BAA0B,4BACzC,IAAI,YAAY,SAAS,YAAY,yBAAyB,QAAQ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { OntologyIR } from "../../ir/generated/types.js";
|
|
2
|
-
import "../../ir/index.js";
|
|
3
|
-
import { OntologyBackendAdapter } from "../OntologyBackendAdapter.js";
|
|
4
|
-
import { OntologyObject } from "../objects/OntologyObject.js";
|
|
5
|
-
import { OntologyCollection } from "../objects/createLiveOntologyObjectCollection.js";
|
|
6
|
-
import { OntologyOutbox } from "../outbox/types.js";
|
|
7
|
-
import { LiveOntologyAction } from "./createLiveOntologyAction.js";
|
|
8
|
-
import { LiveOntologyWrites } from "../LiveOntology.js";
|
|
9
|
-
import { BlobManager } from "@party-stack/blobs";
|
|
10
|
-
import { RuntimeAdapter } from "@party-stack/runtime";
|
|
11
|
-
import { ConnectionMonitor } from "@party-stack/connections";
|
|
12
|
-
//#region src/live/actions/createLiveOntologyActions.d.ts
|
|
13
|
-
export interface LiveOntologyActionsSubsystem {
|
|
14
|
-
actions: Record<string, LiveOntologyAction>;
|
|
15
|
-
outbox: OntologyOutbox;
|
|
16
|
-
}
|
|
17
|
-
export declare function createLiveOntologyActions(options: {
|
|
18
|
-
ir: OntologyIR;
|
|
19
|
-
backendAdapter: OntologyBackendAdapter;
|
|
20
|
-
runtime: RuntimeAdapter;
|
|
21
|
-
context: Record<string, unknown>;
|
|
22
|
-
objects: Record<string, OntologyCollection<OntologyObject>>;
|
|
23
|
-
blobManager: BlobManager;
|
|
24
|
-
writes?: LiveOntologyWrites;
|
|
25
|
-
connection?: ConnectionMonitor;
|
|
26
|
-
}): LiveOntologyActionsSubsystem;
|
|
27
|
-
//#endregion
|
|
28
|
-
//# sourceMappingURL=createLiveOntologyActions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createLiveOntologyActions.d.ts","names":[],"sources":["../../../src/live/actions/createLiveOntologyActions.ts"],"mappings":";;;;;;;;;;;;iBAyBiB;EACb,SAAS,eAAe;EACxB,QAAQ;;wBAGI,0BAA0B;EACtC,IAAI;EACJ,gBAAgB;EAChB,SAAS;EACT,SAAS;EACT,SAAS,eAAe,mBAAmB;EAC3C,aAAa;EACb,SAAS;EACT,aAAa;IACb"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { resolveActionParameters } from "../expression.js";
|
|
2
|
-
import { createReadTx } from "../mutators/createMutatorTx.js";
|
|
3
|
-
import { runOptimisticAction } from "../mutators/runOptimisticAction.js";
|
|
4
|
-
import { createOntologyOutbox } from "../outbox/createOntologyOutbox.js";
|
|
5
|
-
import { createLiveOntologyAction } from "./createLiveOntologyAction.js";
|
|
6
|
-
import { prepareActionParameters } from "./prepareActionParameters.js";
|
|
7
|
-
import { createTransaction } from "@tanstack/db";
|
|
8
|
-
//#region src/live/actions/createLiveOntologyActions.ts
|
|
9
|
-
function createLiveOntologyActions(options) {
|
|
10
|
-
const defaultMode = options.writes?.defaultMode ?? "direct";
|
|
11
|
-
const defaultVisibility = options.writes?.defaultVisibility ?? "confirmed";
|
|
12
|
-
const executeRemote = async (request) => {
|
|
13
|
-
const prepared = await prepareActionParameters({
|
|
14
|
-
ir: options.ir,
|
|
15
|
-
actionTypeName: request.actionTypeName,
|
|
16
|
-
parameters: request.parameters,
|
|
17
|
-
backendAdapter: options.backendAdapter,
|
|
18
|
-
blobManager: options.blobManager
|
|
19
|
-
});
|
|
20
|
-
const result = await options.backendAdapter.applyAction(request.actionTypeName, prepared.parameters, {
|
|
21
|
-
objects: options.objects,
|
|
22
|
-
context: options.context,
|
|
23
|
-
attachmentUploads: prepared.attachmentUploads,
|
|
24
|
-
idempotencyKey: request.idempotencyKey
|
|
25
|
-
});
|
|
26
|
-
const backendMappings = result?.attachmentIdMappings ?? [];
|
|
27
|
-
const attachmentIdMappings = [...prepared.attachmentIdMappings, ...backendMappings];
|
|
28
|
-
await Promise.all(attachmentIdMappings.map((mapping) => options.blobManager.bindRemoteId(mapping.localId, mapping.remoteId)));
|
|
29
|
-
return attachmentIdMappings.length > 0 ? {
|
|
30
|
-
...result,
|
|
31
|
-
attachmentIdMappings
|
|
32
|
-
} : result;
|
|
33
|
-
};
|
|
34
|
-
const applyOptimisticAction = async (transaction, request) => {
|
|
35
|
-
try {
|
|
36
|
-
const parameters = await resolveActionParameters({
|
|
37
|
-
ir: options.ir,
|
|
38
|
-
actionTypeName: request.actionTypeName,
|
|
39
|
-
initialParameters: request.parameters,
|
|
40
|
-
context: options.context,
|
|
41
|
-
tx: createReadTx(options.objects)
|
|
42
|
-
});
|
|
43
|
-
await runOptimisticAction({
|
|
44
|
-
transaction,
|
|
45
|
-
ir: options.ir,
|
|
46
|
-
actionTypeName: request.actionTypeName,
|
|
47
|
-
parameters,
|
|
48
|
-
context: options.context,
|
|
49
|
-
idempotencyKey: request.idempotencyKey,
|
|
50
|
-
objects: options.objects,
|
|
51
|
-
mutators: options.writes?.mutators
|
|
52
|
-
});
|
|
53
|
-
} catch (error) {
|
|
54
|
-
if (transaction.state === "pending") transaction.rollback();
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
57
|
-
return transaction.mutations.length > 0;
|
|
58
|
-
};
|
|
59
|
-
const project = async (entry) => {
|
|
60
|
-
if ((entry.visibility ?? defaultVisibility) !== "optimistic") return;
|
|
61
|
-
let resolve;
|
|
62
|
-
let reject;
|
|
63
|
-
const completion = new Promise((resolvePromise, rejectPromise) => {
|
|
64
|
-
resolve = resolvePromise;
|
|
65
|
-
reject = rejectPromise;
|
|
66
|
-
});
|
|
67
|
-
const transaction = createTransaction({
|
|
68
|
-
autoCommit: false,
|
|
69
|
-
mutationFn: () => completion
|
|
70
|
-
});
|
|
71
|
-
if (!await applyOptimisticAction(transaction, entry.request)) return;
|
|
72
|
-
transaction.commit().catch(() => void 0);
|
|
73
|
-
transaction.isPersisted.promise.catch(() => void 0);
|
|
74
|
-
return { settle(error) {
|
|
75
|
-
if (error) reject(error);
|
|
76
|
-
else resolve();
|
|
77
|
-
return transaction.isPersisted.promise.then(() => void 0, () => void 0);
|
|
78
|
-
} };
|
|
79
|
-
};
|
|
80
|
-
const outbox = createOntologyOutbox({
|
|
81
|
-
runtime: options.runtime,
|
|
82
|
-
execute: (entry) => executeRemote(entry.request),
|
|
83
|
-
project,
|
|
84
|
-
failureStrategy: options.writes?.outbox?.failureStrategy ?? "discard-all",
|
|
85
|
-
maxRetries: options.writes?.outbox?.maxRetries,
|
|
86
|
-
connection: options.connection
|
|
87
|
-
});
|
|
88
|
-
const executeDirect = async (request, visibility) => {
|
|
89
|
-
if (visibility === "confirmed") return executeRemote(request);
|
|
90
|
-
let result = void 0;
|
|
91
|
-
const transaction = createTransaction({
|
|
92
|
-
autoCommit: false,
|
|
93
|
-
mutationFn: async () => {
|
|
94
|
-
result = await executeRemote(request);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
if (!await applyOptimisticAction(transaction, request)) return executeRemote(request);
|
|
98
|
-
await transaction.commit();
|
|
99
|
-
return result;
|
|
100
|
-
};
|
|
101
|
-
const submit = async (request, actionOptions) => {
|
|
102
|
-
const mode = actionOptions?.mode ?? defaultMode;
|
|
103
|
-
const visibility = actionOptions?.visibility ?? defaultVisibility;
|
|
104
|
-
if (visibility === "optimistic" && options.backendAdapter.live === false) throw new Error(`Ontology backend adapter "${options.backendAdapter.name}" is not live and cannot reconcile optimistic actions.`);
|
|
105
|
-
if (mode === "outbox") return (await outbox.enqueue(request, { visibility })).completed;
|
|
106
|
-
return executeDirect(request, visibility);
|
|
107
|
-
};
|
|
108
|
-
const validate = (actionTypeName, parameters) => {
|
|
109
|
-
if (!options.backendAdapter.validateAction) return Promise.resolve({ certain: false });
|
|
110
|
-
return options.backendAdapter.validateAction(actionTypeName, parameters, {
|
|
111
|
-
objects: options.objects,
|
|
112
|
-
context: options.context
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
const validateDraft = (actionTypeName, parameters, validationOptions) => {
|
|
116
|
-
if (!options.backendAdapter.validateActionDraft) return Promise.resolve({ certain: false });
|
|
117
|
-
return options.backendAdapter.validateActionDraft(actionTypeName, parameters, {
|
|
118
|
-
objects: options.objects,
|
|
119
|
-
context: options.context,
|
|
120
|
-
knownParameters: validationOptions?.knownParameters ?? []
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
return {
|
|
124
|
-
actions: Object.fromEntries(options.ir.actionTypes.map((action) => [action.name, createLiveOntologyAction({
|
|
125
|
-
ir: options.ir,
|
|
126
|
-
action,
|
|
127
|
-
context: options.context,
|
|
128
|
-
objects: options.objects,
|
|
129
|
-
submit,
|
|
130
|
-
validate,
|
|
131
|
-
validateDraft
|
|
132
|
-
})])),
|
|
133
|
-
outbox
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
//#endregion
|
|
137
|
-
export { createLiveOntologyActions };
|
|
138
|
-
|
|
139
|
-
//# sourceMappingURL=createLiveOntologyActions.js.map
|