liminal 0.4.0 → 0.5.1
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/Action.ts +29 -0
- package/Actor.ts +20 -0
- package/CHANGELOG.md +14 -0
- package/Exec.ts +63 -0
- package/L.ts +27 -0
- package/LiminalAssertionError.ts +3 -0
- package/LiminalConfig.ts +7 -0
- package/Message.ts +94 -0
- package/Model.ts +20 -0
- package/PathLike.ts +19 -0
- package/Scope.ts +133 -0
- package/Spec.ts +29 -0
- package/Tool.ts +58 -0
- package/_.ts +11 -0
- package/actions/abort.ts +23 -0
- package/actions/actions_common/updateModels.ts +23 -0
- package/actions/actions_derived/__snapshots__/declareModel.test.ts.snap +89 -0
- package/actions/actions_derived/clear.ts +6 -0
- package/actions/actions_derived/declareModel.test.ts +33 -0
- package/actions/actions_derived/declareModel.ts +9 -0
- package/actions/actions_derived/declareModel.type-test.ts +70 -0
- package/actions/actions_derived/getMessages.ts +9 -0
- package/actions/actions_derived/messages.test.ts +88 -0
- package/actions/actions_derived/messages.ts +19 -0
- package/actions/actions_derived/metatype.ts +9 -0
- package/actions/appendMessage.ts +30 -0
- package/actions/await.ts +13 -0
- package/actions/branch.ts +108 -0
- package/actions/catch.ts +42 -0
- package/actions/declareArg.ts +14 -0
- package/actions/disableTool.ts +26 -0
- package/actions/embed.ts +28 -0
- package/actions/emit.ts +21 -0
- package/actions/enableTool.ts +75 -0
- package/actions/enableTool.type-test.ts +118 -0
- package/actions/getScope.ts +11 -0
- package/actions/getSignal.ts +10 -0
- package/actions/getTools.ts +11 -0
- package/actions/infer.ts +37 -0
- package/actions/pushModel.ts +32 -0
- package/actions/removeMessage.ts +22 -0
- package/actions/removeModel.ts +31 -0
- package/actions/setMessages.ts +66 -0
- package/actions/throw.ts +18 -0
- package/cli/WriteHandler.ts +35 -0
- package/cli/cli_common.ts +3 -0
- package/cli/main.ts +19 -0
- package/cli/runExec.ts +68 -0
- package/dist/Action.d.ts +15 -0
- package/dist/Action.js +13 -0
- package/dist/Action.js.map +1 -0
- package/dist/Actor.d.ts +14 -0
- package/dist/Actor.js +2 -0
- package/dist/Actor.js.map +1 -0
- package/dist/Exec.d.ts +27 -0
- package/dist/Exec.js +22 -0
- package/dist/Exec.js.map +1 -0
- package/dist/L.d.ts +26 -0
- package/dist/L.js +27 -0
- package/dist/L.js.map +1 -0
- package/dist/LiminalAssertionError.d.ts +3 -0
- package/dist/LiminalAssertionError.js +4 -0
- package/dist/LiminalAssertionError.js.map +1 -0
- package/dist/LiminalConfig.d.ts +6 -0
- package/dist/LiminalConfig.js +2 -0
- package/dist/LiminalConfig.js.map +1 -0
- package/dist/Message.d.ts +82 -0
- package/dist/Message.js +2 -0
- package/dist/Message.js.map +1 -0
- package/dist/Model.d.ts +16 -0
- package/dist/Model.js +2 -0
- package/dist/Model.js.map +1 -0
- package/dist/PathLike.d.ts +14 -0
- package/dist/PathLike.js +2 -0
- package/dist/PathLike.js.map +1 -0
- package/dist/Scope.d.ts +36 -0
- package/dist/Scope.js +90 -0
- package/dist/Scope.js.map +1 -0
- package/dist/Spec.d.ts +20 -0
- package/dist/Spec.js +2 -0
- package/dist/Spec.js.map +1 -0
- package/dist/Tool.d.ts +21 -0
- package/dist/Tool.js +32 -0
- package/dist/Tool.js.map +1 -0
- package/dist/_.d.ts +5 -0
- package/dist/_.js +7 -0
- package/dist/_.js.map +1 -0
- package/dist/actions/abort.d.ts +9 -0
- package/dist/actions/abort.js +15 -0
- package/dist/actions/abort.js.map +1 -0
- package/dist/actions/actions_common/updateModels.d.ts +3 -0
- package/dist/actions/actions_common/updateModels.js +17 -0
- package/dist/actions/actions_common/updateModels.js.map +1 -0
- package/dist/actions/actions_derived/clear.d.ts +8 -0
- package/dist/actions/actions_derived/clear.js +5 -0
- package/dist/actions/actions_derived/clear.js.map +1 -0
- package/dist/actions/actions_derived/declareModel.d.ts +5 -0
- package/dist/actions/actions_derived/declareModel.js +7 -0
- package/dist/actions/actions_derived/declareModel.js.map +1 -0
- package/dist/actions/actions_derived/declareModel.test.d.ts +1 -0
- package/dist/actions/actions_derived/declareModel.test.js +32 -0
- package/dist/actions/actions_derived/declareModel.test.js.map +1 -0
- package/dist/actions/actions_derived/declareModel.type-test.d.ts +1 -0
- package/dist/actions/actions_derived/declareModel.type-test.js +66 -0
- package/dist/actions/actions_derived/declareModel.type-test.js.map +1 -0
- package/dist/actions/actions_derived/getMessages.d.ts +3 -0
- package/dist/actions/actions_derived/getMessages.js +8 -0
- package/dist/actions/actions_derived/getMessages.js.map +1 -0
- package/dist/actions/actions_derived/messages.d.ts +6 -0
- package/dist/actions/actions_derived/messages.js +15 -0
- package/dist/actions/actions_derived/messages.js.map +1 -0
- package/dist/actions/actions_derived/messages.test.d.ts +1 -0
- package/dist/actions/actions_derived/messages.test.js +72 -0
- package/dist/actions/actions_derived/messages.test.js.map +1 -0
- package/dist/actions/actions_derived/metatype.d.ts +9 -0
- package/dist/actions/actions_derived/metatype.js +7 -0
- package/dist/actions/actions_derived/metatype.js.map +1 -0
- package/dist/actions/appendMessage.d.ts +10 -0
- package/dist/actions/appendMessage.js +20 -0
- package/dist/actions/appendMessage.js.map +1 -0
- package/dist/actions/await.d.ts +5 -0
- package/dist/actions/await.js +10 -0
- package/dist/actions/await.js.map +1 -0
- package/dist/actions/branch.d.ts +35 -0
- package/dist/actions/branch.js +40 -0
- package/dist/actions/branch.js.map +1 -0
- package/dist/actions/catch.d.ts +10 -0
- package/dist/actions/catch.js +27 -0
- package/dist/actions/catch.js.map +1 -0
- package/dist/actions/declareArg.d.ts +8 -0
- package/dist/actions/declareArg.js +10 -0
- package/dist/actions/declareArg.js.map +1 -0
- package/dist/actions/disableTool.d.ts +10 -0
- package/dist/actions/disableTool.js +17 -0
- package/dist/actions/disableTool.js.map +1 -0
- package/dist/actions/embed.d.ts +9 -0
- package/dist/actions/embed.js +23 -0
- package/dist/actions/embed.js.map +1 -0
- package/dist/actions/emit.d.ts +9 -0
- package/dist/actions/emit.js +14 -0
- package/dist/actions/emit.js.map +1 -0
- package/dist/actions/enableTool.d.ts +20 -0
- package/dist/actions/enableTool.js +26 -0
- package/dist/actions/enableTool.js.map +1 -0
- package/dist/actions/enableTool.type-test.d.ts +1 -0
- package/dist/actions/enableTool.type-test.js +30 -0
- package/dist/actions/enableTool.type-test.js.map +1 -0
- package/dist/actions/getScope.d.ts +5 -0
- package/dist/actions/getScope.js +8 -0
- package/dist/actions/getScope.js.map +1 -0
- package/dist/actions/getSignal.d.ts +4 -0
- package/dist/actions/getSignal.js +8 -0
- package/dist/actions/getSignal.js.map +1 -0
- package/dist/actions/getTools.d.ts +5 -0
- package/dist/actions/getTools.js +8 -0
- package/dist/actions/getTools.js.map +1 -0
- package/dist/actions/infer.d.ts +13 -0
- package/dist/actions/infer.js +21 -0
- package/dist/actions/infer.js.map +1 -0
- package/dist/actions/pushModel.d.ts +11 -0
- package/dist/actions/pushModel.js +21 -0
- package/dist/actions/pushModel.js.map +1 -0
- package/dist/actions/removeMessage.d.ts +9 -0
- package/dist/actions/removeMessage.js +17 -0
- package/dist/actions/removeMessage.js.map +1 -0
- package/dist/actions/removeModel.d.ts +10 -0
- package/dist/actions/removeModel.js +20 -0
- package/dist/actions/removeModel.js.map +1 -0
- package/dist/actions/setMessages.d.ts +16 -0
- package/dist/actions/setMessages.js +31 -0
- package/dist/actions/setMessages.js.map +1 -0
- package/dist/actions/throw.d.ts +9 -0
- package/dist/actions/throw.js +13 -0
- package/dist/actions/throw.js.map +1 -0
- package/dist/cli/WriteHandler.d.ts +9 -0
- package/dist/cli/WriteHandler.js +24 -0
- package/dist/cli/WriteHandler.js.map +1 -0
- package/dist/cli/cli_common.d.ts +3 -0
- package/dist/cli/cli_common.js +2 -0
- package/dist/cli/cli_common.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +15 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/runExec.d.ts +2 -0
- package/dist/cli/runExec.js +69 -0
- package/dist/cli/runExec.js.map +1 -0
- package/dist/events/Aborted.d.ts +4 -0
- package/dist/events/Aborted.js +2 -0
- package/dist/events/Aborted.js.map +1 -0
- package/dist/events/Embedded.d.ts +5 -0
- package/dist/events/Embedded.js +2 -0
- package/dist/events/Embedded.js.map +1 -0
- package/dist/events/EmbeddingRequested.d.ts +4 -0
- package/dist/events/EmbeddingRequested.js +2 -0
- package/dist/events/EmbeddingRequested.js.map +1 -0
- package/dist/events/Emitted.d.ts +4 -0
- package/dist/events/Emitted.js +2 -0
- package/dist/events/Emitted.js.map +1 -0
- package/dist/events/EventBase.d.ts +3 -0
- package/dist/events/EventBase.js +2 -0
- package/dist/events/EventBase.js.map +1 -0
- package/dist/events/EventHandler.d.ts +2 -0
- package/dist/events/EventHandler.js +2 -0
- package/dist/events/EventHandler.js.map +1 -0
- package/dist/events/EventResolved.d.ts +19 -0
- package/dist/events/EventResolved.js +2 -0
- package/dist/events/EventResolved.js.map +1 -0
- package/dist/events/Forked.d.ts +3 -0
- package/dist/events/Forked.js +2 -0
- package/dist/events/Forked.js.map +1 -0
- package/dist/events/InferenceRequested.d.ts +3 -0
- package/dist/events/InferenceRequested.js +2 -0
- package/dist/events/InferenceRequested.js.map +1 -0
- package/dist/events/Inferred.d.ts +5 -0
- package/dist/events/Inferred.js +2 -0
- package/dist/events/Inferred.js.map +1 -0
- package/dist/events/LEvent.d.ts +18 -0
- package/dist/events/LEvent.js +2 -0
- package/dist/events/LEvent.js.map +1 -0
- package/dist/events/MessageAppended.d.ts +5 -0
- package/dist/events/MessageAppended.js +2 -0
- package/dist/events/MessageAppended.js.map +1 -0
- package/dist/events/MessageRemoved.d.ts +5 -0
- package/dist/events/MessageRemoved.js +2 -0
- package/dist/events/MessageRemoved.js.map +1 -0
- package/dist/events/MessagesSet.d.ts +5 -0
- package/dist/events/MessagesSet.js +2 -0
- package/dist/events/MessagesSet.js.map +1 -0
- package/dist/events/ModelPushed.d.ts +7 -0
- package/dist/events/ModelPushed.js +2 -0
- package/dist/events/ModelPushed.js.map +1 -0
- package/dist/events/ModelRemoved.d.ts +7 -0
- package/dist/events/ModelRemoved.js +2 -0
- package/dist/events/ModelRemoved.js.map +1 -0
- package/dist/events/Returned.d.ts +4 -0
- package/dist/events/Returned.js +2 -0
- package/dist/events/Returned.js.map +1 -0
- package/dist/events/Threw.d.ts +4 -0
- package/dist/events/Threw.js +2 -0
- package/dist/events/Threw.js.map +1 -0
- package/dist/events/ToolCalled.d.ts +6 -0
- package/dist/events/ToolCalled.js +2 -0
- package/dist/events/ToolCalled.js.map +1 -0
- package/dist/events/ToolDisabled.d.ts +5 -0
- package/dist/events/ToolDisabled.js +2 -0
- package/dist/events/ToolDisabled.js.map +1 -0
- package/dist/events/ToolEnabled.d.ts +7 -0
- package/dist/events/ToolEnabled.js +2 -0
- package/dist/events/ToolEnabled.js.map +1 -0
- package/dist/events/isScopeChildEvent.d.ts +6 -0
- package/dist/events/isScopeChildEvent.js +9 -0
- package/dist/events/isScopeChildEvent.js.map +1 -0
- package/dist/events/isScopeDescendantEvent.d.ts +14 -0
- package/dist/events/isScopeDescendantEvent.js +12 -0
- package/dist/events/isScopeDescendantEvent.js.map +1 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/testing/ActorAssertions.d.ts +9 -0
- package/dist/testing/ActorAssertions.js +6 -0
- package/dist/testing/ActorAssertions.js.map +1 -0
- package/dist/testing/TestEmbeddingModel.d.ts +6 -0
- package/dist/testing/TestEmbeddingModel.js +10 -0
- package/dist/testing/TestEmbeddingModel.js.map +1 -0
- package/dist/testing/TestLanguageModel.d.ts +8 -0
- package/dist/testing/TestLanguageModel.js +21 -0
- package/dist/testing/TestLanguageModel.js.map +1 -0
- package/dist/testing/index.d.ts +4 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/takeFirstAction.d.ts +3 -0
- package/dist/testing/takeFirstAction.js +6 -0
- package/dist/testing/takeFirstAction.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/AssertDiagnostics.d.ts +18 -0
- package/dist/types/AssertDiagnostics.js +152 -0
- package/dist/types/AssertDiagnostics.js.map +1 -0
- package/dist/types/JSONRootType.d.ts +6 -0
- package/dist/types/JSONRootType.js +2 -0
- package/dist/types/JSONRootType.js.map +1 -0
- package/dist/types/JSONType.d.ts +16 -0
- package/dist/types/JSONType.js +2 -0
- package/dist/types/JSONType.js.map +1 -0
- package/dist/types/JSONTypeBase.d.ts +3 -0
- package/dist/types/JSONTypeBase.js +2 -0
- package/dist/types/JSONTypeBase.js.map +1 -0
- package/dist/types/Metatype/MetatypeDescriptor.d.ts +41 -0
- package/dist/types/Metatype/MetatypeDescriptor.js +38 -0
- package/dist/types/Metatype/MetatypeDescriptor.js.map +1 -0
- package/dist/types/Metatype/fromMetatypeDescriptor.d.ts +6 -0
- package/dist/types/Metatype/fromMetatypeDescriptor.js +43 -0
- package/dist/types/Metatype/fromMetatypeDescriptor.js.map +1 -0
- package/dist/types/Type.d.ts +30 -0
- package/dist/types/Type.js +5 -0
- package/dist/types/Type.js.map +1 -0
- package/dist/types/TypeContext.d.ts +7 -0
- package/dist/types/TypeContext.js +17 -0
- package/dist/types/TypeContext.js.map +1 -0
- package/dist/types/TypeLike.d.ts +23 -0
- package/dist/types/TypeLike.js +23 -0
- package/dist/types/TypeLike.js.map +1 -0
- package/dist/types/TypeVisitor.d.ts +14 -0
- package/dist/types/TypeVisitor.js +12 -0
- package/dist/types/TypeVisitor.js.map +1 -0
- package/dist/types/array.d.ts +10 -0
- package/dist/types/array.js +9 -0
- package/dist/types/array.js.map +1 -0
- package/dist/types/boolean.d.ts +6 -0
- package/dist/types/boolean.js +3 -0
- package/dist/types/boolean.js.map +1 -0
- package/dist/types/const.d.ts +8 -0
- package/dist/types/const.js +7 -0
- package/dist/types/const.js.map +1 -0
- package/dist/types/declareType.d.ts +2 -0
- package/dist/types/declareType.js +57 -0
- package/dist/types/declareType.js.map +1 -0
- package/dist/types/enum.d.ts +8 -0
- package/dist/types/enum.js +7 -0
- package/dist/types/enum.js.map +1 -0
- package/dist/types/factories.d.ts +8 -0
- package/dist/types/factories.js +9 -0
- package/dist/types/factories.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/integer.d.ts +6 -0
- package/dist/types/integer.js +3 -0
- package/dist/types/integer.js.map +1 -0
- package/dist/types/intrinsics.d.ts +11 -0
- package/dist/types/intrinsics.js +12 -0
- package/dist/types/intrinsics.js.map +1 -0
- package/dist/types/match.d.ts +3 -0
- package/dist/types/match.js +11 -0
- package/dist/types/match.js.map +1 -0
- package/dist/types/non_factories.d.ts +21 -0
- package/dist/types/non_factories.js +9 -0
- package/dist/types/non_factories.js.map +1 -0
- package/dist/types/null.d.ts +7 -0
- package/dist/types/null.js +4 -0
- package/dist/types/null.js.map +1 -0
- package/dist/types/number.d.ts +6 -0
- package/dist/types/number.js +3 -0
- package/dist/types/number.js.map +1 -0
- package/dist/types/object.d.ts +16 -0
- package/dist/types/object.js +10 -0
- package/dist/types/object.js.map +1 -0
- package/dist/types/ref.d.ts +7 -0
- package/dist/types/ref.js +5 -0
- package/dist/types/ref.js.map +1 -0
- package/dist/types/string.d.ts +6 -0
- package/dist/types/string.js +3 -0
- package/dist/types/string.js.map +1 -0
- package/dist/types/toJSON.d.ts +5 -0
- package/dist/types/toJSON.js +97 -0
- package/dist/types/toJSON.js.map +1 -0
- package/dist/types/type_common.d.ts +10 -0
- package/dist/types/type_common.js +12 -0
- package/dist/types/type_common.js.map +1 -0
- package/dist/types/types_derived/option.d.ts +5 -0
- package/dist/types/types_derived/option.js +6 -0
- package/dist/types/types_derived/option.js.map +1 -0
- package/dist/types/types_derived/taggedUnion.d.ts +19 -0
- package/dist/types/types_derived/taggedUnion.js +8 -0
- package/dist/types/types_derived/taggedUnion.js.map +1 -0
- package/dist/types/types_derived/wrapper.d.ts +8 -0
- package/dist/types/types_derived/wrapper.js +5 -0
- package/dist/types/types_derived/wrapper.js.map +1 -0
- package/dist/types/union.d.ts +9 -0
- package/dist/types/union.js +9 -0
- package/dist/types/union.js.map +1 -0
- package/dist/util/ArrayOfLength.d.ts +1 -0
- package/dist/util/ArrayOfLength.js +2 -0
- package/dist/util/ArrayOfLength.js.map +1 -0
- package/dist/util/DeferredOr.d.ts +1 -0
- package/dist/util/DeferredOr.js +2 -0
- package/dist/util/DeferredOr.js.map +1 -0
- package/dist/util/EnsureNarrow.d.ts +2 -0
- package/dist/util/EnsureNarrow.js +2 -0
- package/dist/util/EnsureNarrow.js.map +1 -0
- package/dist/util/EnsureRecord.d.ts +2 -0
- package/dist/util/EnsureRecord.js +2 -0
- package/dist/util/EnsureRecord.js.map +1 -0
- package/dist/util/Expand.d.ts +3 -0
- package/dist/util/Expand.js +2 -0
- package/dist/util/Expand.js.map +1 -0
- package/dist/util/Falsy.d.ts +1 -0
- package/dist/util/Falsy.js +2 -0
- package/dist/util/Falsy.js.map +1 -0
- package/dist/util/FromEntries.d.ts +3 -0
- package/dist/util/FromEntries.js +2 -0
- package/dist/util/FromEntries.js.map +1 -0
- package/dist/util/IteratorLike.d.ts +1 -0
- package/dist/util/IteratorLike.js +2 -0
- package/dist/util/IteratorLike.js.map +1 -0
- package/dist/util/JSONEntry.d.ts +2 -0
- package/dist/util/JSONEntry.js +2 -0
- package/dist/util/JSONEntry.js.map +1 -0
- package/dist/util/JSONKey.d.ts +1 -0
- package/dist/util/JSONKey.js +2 -0
- package/dist/util/JSONKey.js.map +1 -0
- package/dist/util/JSONObject.d.ts +5 -0
- package/dist/util/JSONObject.js +2 -0
- package/dist/util/JSONObject.js.map +1 -0
- package/dist/util/JSONSchemaMemo.d.ts +2 -0
- package/dist/util/JSONSchemaMemo.js +13 -0
- package/dist/util/JSONSchemaMemo.js.map +1 -0
- package/dist/util/JSONValue.d.ts +2 -0
- package/dist/util/JSONValue.js +2 -0
- package/dist/util/JSONValue.js.map +1 -0
- package/dist/util/PromiseOr.d.ts +1 -0
- package/dist/util/PromiseOr.js +2 -0
- package/dist/util/PromiseOr.js.map +1 -0
- package/dist/util/Result.d.ts +7 -0
- package/dist/util/Result.js +2 -0
- package/dist/util/Result.js.map +1 -0
- package/dist/util/Taggable.d.ts +9 -0
- package/dist/util/Taggable.js +8 -0
- package/dist/util/Taggable.js.map +1 -0
- package/dist/util/TupleToRecord.d.ts +5 -0
- package/dist/util/TupleToRecord.js +2 -0
- package/dist/util/TupleToRecord.js.map +1 -0
- package/dist/util/assert.d.ts +1 -0
- package/dist/util/assert.js +7 -0
- package/dist/util/assert.js.map +1 -0
- package/dist/util/dedent.d.ts +1 -0
- package/dist/util/dedent.js +5 -0
- package/dist/util/dedent.js.map +1 -0
- package/dist/util/fixTemplateStrings.d.ts +11 -0
- package/dist/util/fixTemplateStrings.js +83 -0
- package/dist/util/fixTemplateStrings.js.map +1 -0
- package/dist/util/fixTemplateStrings.test.d.ts +1 -0
- package/dist/util/fixTemplateStrings.test.js +221 -0
- package/dist/util/fixTemplateStrings.test.js.map +1 -0
- package/dist/util/isAsyncIterator.d.ts +1 -0
- package/dist/util/isAsyncIterator.js +7 -0
- package/dist/util/isAsyncIterator.js.map +1 -0
- package/dist/util/isIterator.d.ts +1 -0
- package/dist/util/isIterator.js +7 -0
- package/dist/util/isIterator.js.map +1 -0
- package/dist/util/isJSONValue.d.ts +2 -0
- package/dist/util/isJSONValue.js +16 -0
- package/dist/util/isJSONValue.js.map +1 -0
- package/dist/util/isPropertyKey.d.ts +1 -0
- package/dist/util/isPropertyKey.js +4 -0
- package/dist/util/isPropertyKey.js.map +1 -0
- package/dist/util/isTemplateStringsArray.d.ts +1 -0
- package/dist/util/isTemplateStringsArray.js +4 -0
- package/dist/util/isTemplateStringsArray.js.map +1 -0
- package/dist/util/jsonEquals.d.ts +2 -0
- package/dist/util/jsonEquals.js +33 -0
- package/dist/util/jsonEquals.js.map +1 -0
- package/dist/util/nullaryMemo.d.ts +1 -0
- package/dist/util/nullaryMemo.js +12 -0
- package/dist/util/nullaryMemo.js.map +1 -0
- package/dist/util/unimplemented.d.ts +1 -0
- package/dist/util/unimplemented.js +5 -0
- package/dist/util/unimplemented.js.map +1 -0
- package/dist/util/unreachable.d.ts +1 -0
- package/dist/util/unreachable.js +5 -0
- package/dist/util/unreachable.js.map +1 -0
- package/dist/util/unwrapDeferred.d.ts +2 -0
- package/dist/util/unwrapDeferred.js +4 -0
- package/dist/util/unwrapDeferred.js.map +1 -0
- package/dist/util/util.d.ts +10 -0
- package/dist/util/util.js +11 -0
- package/dist/util/util.js.map +1 -0
- package/events/Aborted.ts +5 -0
- package/events/Embedded.ts +6 -0
- package/events/EmbeddingRequested.ts +5 -0
- package/events/Emitted.ts +5 -0
- package/events/EventBase.ts +3 -0
- package/events/EventHandler.ts +3 -0
- package/events/EventResolved.ts +30 -0
- package/events/Forked.ts +3 -0
- package/events/InferenceRequested.ts +3 -0
- package/events/Inferred.ts +6 -0
- package/events/LEvent.ts +36 -0
- package/events/MessageAppended.ts +6 -0
- package/events/MessageRemoved.ts +6 -0
- package/events/MessagesSet.ts +6 -0
- package/events/ModelPushed.ts +10 -0
- package/events/ModelRemoved.ts +10 -0
- package/events/Returned.ts +5 -0
- package/events/Threw.ts +5 -0
- package/events/ToolCalled.ts +7 -0
- package/events/ToolDisabled.ts +6 -0
- package/events/ToolEnabled.ts +8 -0
- package/events/isScopeChildEvent.ts +15 -0
- package/events/isScopeDescendantEvent.ts +30 -0
- package/index.ts +41 -0
- package/package.json +28 -19
- package/testing/ActorAssertions.ts +19 -0
- package/testing/TestEmbeddingModel.ts +18 -0
- package/testing/TestLanguageModel.ts +32 -0
- package/testing/index.ts +4 -0
- package/testing/takeFirstAction.ts +8 -0
- package/tsconfig.json +4 -8
- package/types/AssertDiagnostics.ts +183 -0
- package/types/JSONRootType.ts +8 -0
- package/types/JSONType.ts +27 -0
- package/types/JSONTypeBase.ts +3 -0
- package/types/Metatype/MetatypeDescriptor.ts +80 -0
- package/types/Metatype/fromMetatypeDescriptor.ts +52 -0
- package/types/Type.ts +46 -0
- package/types/TypeContext.ts +19 -0
- package/types/TypeLike.ts +60 -0
- package/types/TypeVisitor.ts +49 -0
- package/types/array.ts +20 -0
- package/types/boolean.ts +9 -0
- package/types/const.ts +17 -0
- package/types/declareType.ts +71 -0
- package/types/enum.ts +14 -0
- package/types/factories.ts +8 -0
- package/types/index.ts +2 -0
- package/types/integer.ts +9 -0
- package/types/intrinsics.ts +11 -0
- package/types/match.ts +13 -0
- package/types/non_factories.ts +26 -0
- package/types/null.ts +10 -0
- package/types/number.ts +9 -0
- package/types/object.ts +27 -0
- package/types/ref.ts +12 -0
- package/types/string.ts +9 -0
- package/types/toJSON.ts +111 -0
- package/types/type_common.ts +21 -0
- package/types/types_derived/option.ts +10 -0
- package/types/types_derived/taggedUnion.ts +30 -0
- package/types/types_derived/wrapper.ts +10 -0
- package/types/union.ts +19 -0
- package/util/ArrayOfLength.ts +5 -0
- package/util/DeferredOr.ts +1 -0
- package/util/EnsureNarrow.ts +5 -0
- package/util/EnsureRecord.ts +3 -0
- package/util/Expand.ts +1 -0
- package/util/Falsy.ts +1 -0
- package/util/FromEntries.ts +3 -0
- package/util/IteratorLike.ts +1 -0
- package/util/JSONEntry.ts +3 -0
- package/util/JSONKey.ts +1 -0
- package/util/JSONObject.ts +6 -0
- package/util/JSONSchemaMemo.ts +15 -0
- package/util/JSONValue.ts +3 -0
- package/util/PromiseOr.ts +1 -0
- package/util/Result.ts +7 -0
- package/util/Taggable.ts +18 -0
- package/util/TupleToRecord.ts +5 -0
- package/util/assert.ts +7 -0
- package/util/dedent.ts +5 -0
- package/util/fixTemplateStrings.test.ts +250 -0
- package/util/fixTemplateStrings.ts +99 -0
- package/util/isAsyncIterator.ts +6 -0
- package/util/isIterator.ts +6 -0
- package/util/isJSONValue.ts +20 -0
- package/util/isPropertyKey.ts +3 -0
- package/util/isTemplateStringsArray.ts +3 -0
- package/util/jsonEquals.ts +41 -0
- package/util/nullaryMemo.ts +11 -0
- package/util/unimplemented.ts +5 -0
- package/util/unreachable.ts +5 -0
- package/util/unwrapDeferred.ts +5 -0
- package/util/util.ts +10 -0
- package/LICENSE +0 -15
- package/README.md +0 -94
- package/jest.config.js +0 -4
- package/lib/array/array.d.ts +0 -6
- package/lib/array/array.js +0 -21
- package/lib/array/index.d.ts +0 -11
- package/lib/array/index.js +0 -17
- package/lib/composition/composition.d.ts +0 -6
- package/lib/composition/composition.js +0 -37
- package/lib/composition/index.d.ts +0 -9
- package/lib/composition/index.js +0 -13
- package/lib/composition/types.d.ts +0 -2
- package/lib/composition/types.js +0 -2
- package/lib/dispatch/getType.d.ts +0 -2
- package/lib/dispatch/getType.js +0 -15
- package/lib/dispatch/identity.d.ts +0 -2
- package/lib/dispatch/identity.js +0 -4
- package/lib/dispatch/index.d.ts +0 -22
- package/lib/dispatch/index.js +0 -13
- package/lib/dispatch/types.d.ts +0 -14
- package/lib/dispatch/types.js +0 -16
- package/lib/error/error.d.ts +0 -24
- package/lib/error/error.js +0 -25
- package/lib/error/index.d.ts +0 -2
- package/lib/error/index.js +0 -4
- package/lib/index.d.ts +0 -67
- package/lib/index.js +0 -19
- package/lib/multimethod/index.d.ts +0 -7
- package/lib/multimethod/index.js +0 -9
- package/lib/multimethod/multimethod.d.ts +0 -3
- package/lib/multimethod/multimethod.js +0 -101
- package/src/array/array.ts +0 -29
- package/src/array/index.ts +0 -12
- package/src/composition/composition.ts +0 -45
- package/src/composition/index.ts +0 -10
- package/src/composition/types.ts +0 -6
- package/src/dispatch/getType.ts +0 -17
- package/src/dispatch/identity.ts +0 -3
- package/src/dispatch/index.ts +0 -11
- package/src/dispatch/types.ts +0 -15
- package/src/error/error.ts +0 -26
- package/src/error/index.ts +0 -3
- package/src/index.ts +0 -15
- package/src/multimethod/index.ts +0 -8
- package/src/multimethod/multimethod.test.ts +0 -10
- package/src/multimethod/multimethod.ts +0 -148
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { JSONArrayType } from "./array.ts"
|
|
2
|
+
import type { JSONBooleanType } from "./boolean.ts"
|
|
3
|
+
import type { JSONConstType } from "./const.ts"
|
|
4
|
+
import type { JSONEnumType } from "./enum.ts"
|
|
5
|
+
import type { JSONIntegerType } from "./integer.ts"
|
|
6
|
+
import type { JSONNullType } from "./null.ts"
|
|
7
|
+
import type { JSONNumberType } from "./number.ts"
|
|
8
|
+
import type { JSONObjectType } from "./object.ts"
|
|
9
|
+
import type { JSONRefType } from "./ref.ts"
|
|
10
|
+
import type { JSONStringType } from "./string.ts"
|
|
11
|
+
import type { JSONUnionType } from "./union.ts"
|
|
12
|
+
|
|
13
|
+
export type JSONIdentifiedType = JSONArrayType | JSONObjectType | JSONUnionType
|
|
14
|
+
|
|
15
|
+
export type JSONAnonymousType =
|
|
16
|
+
| JSONNullType
|
|
17
|
+
| JSONBooleanType
|
|
18
|
+
| JSONIntegerType
|
|
19
|
+
| JSONNumberType
|
|
20
|
+
| JSONStringType
|
|
21
|
+
| JSONEnumType
|
|
22
|
+
|
|
23
|
+
export type ConstableType = JSONAnonymousType | JSONIdentifiedType
|
|
24
|
+
|
|
25
|
+
export type JSONRootableType = ConstableType | JSONConstType
|
|
26
|
+
|
|
27
|
+
export type JSONType = JSONRootableType | JSONRefType
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { array } from "../array.ts"
|
|
2
|
+
import { enum as enum_ } from "../enum.ts"
|
|
3
|
+
import { type JSONObjectType, object } from "../object.ts"
|
|
4
|
+
import { ref } from "../ref.ts"
|
|
5
|
+
import { string } from "../string.ts"
|
|
6
|
+
import type { Type } from "../Type.ts"
|
|
7
|
+
import { taggedUnion } from "../types_derived/taggedUnion.ts"
|
|
8
|
+
import type { JSONUnionType } from "../union.ts"
|
|
9
|
+
|
|
10
|
+
export type MetatypeRootDescriptor = {
|
|
11
|
+
type: "record"
|
|
12
|
+
value: {
|
|
13
|
+
description: string
|
|
14
|
+
fields: Array<{
|
|
15
|
+
description: string
|
|
16
|
+
key: string
|
|
17
|
+
value: MetatypeDescriptor
|
|
18
|
+
}>
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const recordFields = {
|
|
23
|
+
description: string,
|
|
24
|
+
fields: array({
|
|
25
|
+
description: string,
|
|
26
|
+
key: string,
|
|
27
|
+
value: ref(() => MetatypeDescriptor),
|
|
28
|
+
}),
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const MetatypeRootDescriptor: Type<MetatypeRootDescriptor, JSONObjectType> = object({
|
|
32
|
+
type: "record",
|
|
33
|
+
value: recordFields,
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export type MetatypeDescriptor = MetatypeRootDescriptor | {
|
|
37
|
+
type: "atom"
|
|
38
|
+
value: {
|
|
39
|
+
description: string
|
|
40
|
+
atomType: "boolean" | "integer" | "number" | "string"
|
|
41
|
+
}
|
|
42
|
+
} | {
|
|
43
|
+
type: "enum"
|
|
44
|
+
value: {
|
|
45
|
+
description: string
|
|
46
|
+
variants: Array<string>
|
|
47
|
+
}
|
|
48
|
+
} | {
|
|
49
|
+
type: "array"
|
|
50
|
+
value: {
|
|
51
|
+
description: string
|
|
52
|
+
items: MetatypeDescriptor
|
|
53
|
+
}
|
|
54
|
+
} | {
|
|
55
|
+
type: "union"
|
|
56
|
+
value: {
|
|
57
|
+
description: string
|
|
58
|
+
members: Array<MetatypeDescriptor>
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const MetatypeDescriptor: Type<MetatypeDescriptor, JSONUnionType> = taggedUnion({
|
|
63
|
+
atom: {
|
|
64
|
+
description: string,
|
|
65
|
+
atomType: enum_("boolean", "integer", "number", "string"),
|
|
66
|
+
},
|
|
67
|
+
enum: {
|
|
68
|
+
description: string,
|
|
69
|
+
variants: array(string),
|
|
70
|
+
},
|
|
71
|
+
array: {
|
|
72
|
+
description: string,
|
|
73
|
+
items: ref(() => MetatypeDescriptor),
|
|
74
|
+
},
|
|
75
|
+
record: recordFields,
|
|
76
|
+
union: {
|
|
77
|
+
description: string,
|
|
78
|
+
members: array(ref(() => MetatypeDescriptor)),
|
|
79
|
+
},
|
|
80
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { JSONObject } from "../../util/JSONObject.ts"
|
|
2
|
+
import { array } from "../array.ts"
|
|
3
|
+
import { boolean } from "../boolean.ts"
|
|
4
|
+
import { enum as enum_ } from "../enum.ts"
|
|
5
|
+
import { integer } from "../integer.ts"
|
|
6
|
+
import { number } from "../number.ts"
|
|
7
|
+
import { type JSONObjectType, object } from "../object.ts"
|
|
8
|
+
import { string } from "../string.ts"
|
|
9
|
+
import type { Type } from "../Type.ts"
|
|
10
|
+
import { union } from "../union.ts"
|
|
11
|
+
import type { MetatypeDescriptor, MetatypeRootDescriptor } from "./MetatypeDescriptor.ts"
|
|
12
|
+
|
|
13
|
+
export function fromMetatypeRootDescriptor(descriptor: MetatypeRootDescriptor): Type<JSONObject, JSONObjectType> {
|
|
14
|
+
return fromMetatypeDescriptor(descriptor) as never
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function fromMetatypeDescriptor(descriptor: MetatypeDescriptor): Type {
|
|
18
|
+
return make(descriptor)(descriptor.value.description)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function make(descriptor: MetatypeDescriptor): Type {
|
|
22
|
+
switch (descriptor.type) {
|
|
23
|
+
case "atom": {
|
|
24
|
+
switch (descriptor.value.atomType) {
|
|
25
|
+
case "boolean":
|
|
26
|
+
return boolean
|
|
27
|
+
case "integer":
|
|
28
|
+
return integer
|
|
29
|
+
case "number":
|
|
30
|
+
return number
|
|
31
|
+
case "string":
|
|
32
|
+
return string
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
case "array": {
|
|
36
|
+
return array(fromMetatypeDescriptor(descriptor.value.items))
|
|
37
|
+
}
|
|
38
|
+
case "enum": {
|
|
39
|
+
return enum_(...descriptor.value.variants)
|
|
40
|
+
}
|
|
41
|
+
case "record": {
|
|
42
|
+
return object(Object.fromEntries(descriptor.value.fields.map(({
|
|
43
|
+
key,
|
|
44
|
+
value,
|
|
45
|
+
description,
|
|
46
|
+
}) => [key, fromMetatypeDescriptor(value)(description)])))
|
|
47
|
+
}
|
|
48
|
+
case "union": {
|
|
49
|
+
return union(...descriptor.value.members.map(fromMetatypeDescriptor))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
package/types/Type.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec"
|
|
2
|
+
import type { Action } from "../Action.ts"
|
|
3
|
+
import type { InferenceRequested } from "../events/InferenceRequested.ts"
|
|
4
|
+
import type { Inferred } from "../events/Inferred.ts"
|
|
5
|
+
import type { Spec } from "../Spec.ts"
|
|
6
|
+
import type { Falsy } from "../util/Falsy.ts"
|
|
7
|
+
import type { JSONValue } from "../util/JSONValue.ts"
|
|
8
|
+
import type { Taggable } from "../util/Taggable.ts"
|
|
9
|
+
import type { JSONRootType } from "./JSONRootType.ts"
|
|
10
|
+
import type { JSONType } from "./JSONType.ts"
|
|
11
|
+
import type { JSONObjectType } from "./object.ts"
|
|
12
|
+
|
|
13
|
+
export interface Type<T extends JSONValue = JSONValue, J extends JSONType = JSONType>
|
|
14
|
+
extends Taggable<Array<string | Falsy>>, TypeMembers<T, J>
|
|
15
|
+
{
|
|
16
|
+
T: T
|
|
17
|
+
J: J
|
|
18
|
+
|
|
19
|
+
[Symbol.iterator]: J extends JSONObjectType ? () => Iterator<
|
|
20
|
+
Action<
|
|
21
|
+
"infer",
|
|
22
|
+
Spec.Make<{
|
|
23
|
+
Event: InferenceRequested | Inferred
|
|
24
|
+
}>
|
|
25
|
+
>,
|
|
26
|
+
T
|
|
27
|
+
>
|
|
28
|
+
: never
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TypeMembers<T extends JSONValue, J extends JSONType> extends StandardSchemaV1<T> {
|
|
32
|
+
[TypeKey]: true
|
|
33
|
+
declaration: () => Type<T, J> | ((...args: any) => Type<T, J>)
|
|
34
|
+
args?: Array<any>
|
|
35
|
+
descriptions: Array<string>
|
|
36
|
+
description(): string
|
|
37
|
+
toJSON(): JSONRootType<J>
|
|
38
|
+
assert(value: unknown): T
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type TypeKey = typeof TypeKey
|
|
42
|
+
export const TypeKey = Symbol.for("Liminal/Type")
|
|
43
|
+
|
|
44
|
+
export function isType(value: unknown): value is Type {
|
|
45
|
+
return typeof value === "function" && TypeKey in value
|
|
46
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Type } from "./Type.js"
|
|
2
|
+
|
|
3
|
+
export class TypeContext {
|
|
4
|
+
root: Type
|
|
5
|
+
ids: Map<Type, string>
|
|
6
|
+
constructor(root: Type, ids: Map<Type, string> = new Map()) {
|
|
7
|
+
this.root = root
|
|
8
|
+
this.ids = ids
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
id(type: Type): string {
|
|
12
|
+
let id = this.ids.get(type)
|
|
13
|
+
if (id === undefined) {
|
|
14
|
+
id = this.ids.size.toString()
|
|
15
|
+
this.ids.set(type, id)
|
|
16
|
+
}
|
|
17
|
+
return id
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Falsy } from "../util/Falsy.ts"
|
|
2
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
3
|
+
import { const as const_, type JSONConstType } from "./const.ts"
|
|
4
|
+
import { type JSONNullType, null as null_ } from "./null.ts"
|
|
5
|
+
import { _object, type JSONObjectType } from "./object.ts"
|
|
6
|
+
import { type JSONStringType, string } from "./string.ts"
|
|
7
|
+
import { isType, type Type } from "./Type.ts"
|
|
8
|
+
|
|
9
|
+
export type TypeLike = Type | TypeLikes | string | Falsy
|
|
10
|
+
export type TypeLikes = TypeLikeArray | TypeLikeRecord
|
|
11
|
+
|
|
12
|
+
export type TypeLikeArray = Array<TypeLike>
|
|
13
|
+
export type TypeLikeRecord = {
|
|
14
|
+
[key: JSONKey]: TypeLike
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type NormalizeTypeLikesT<F extends TypeLikes> =
|
|
18
|
+
& {
|
|
19
|
+
-readonly [K in keyof F as F extends TypeLikeArray ? K extends `${number}` ? K : never : K]: NormalizeTypeLikeT<
|
|
20
|
+
Extract<F[K], TypeLike>
|
|
21
|
+
>
|
|
22
|
+
}
|
|
23
|
+
& {}
|
|
24
|
+
|
|
25
|
+
export type NormalizeTypeLikeT<V extends TypeLike> = V extends TypeLikes ? NormalizeTypeLikesT<V>
|
|
26
|
+
: V extends string ? V
|
|
27
|
+
: V extends Type<infer T> ? T
|
|
28
|
+
: null
|
|
29
|
+
|
|
30
|
+
export type NormalizeTypeLikesJ<F extends TypeLikes> =
|
|
31
|
+
& {
|
|
32
|
+
-readonly [K in keyof F as F extends TypeLikeArray ? K extends `${number}` ? K : never : K]: NormalizeTypeLikeJ<
|
|
33
|
+
Extract<F[K], TypeLike>
|
|
34
|
+
>
|
|
35
|
+
}
|
|
36
|
+
& {}
|
|
37
|
+
|
|
38
|
+
export type NormalizeTypeLikeJ<V extends TypeLike> = V extends TypeLikes ? JSONObjectType<NormalizeTypeLikesJ<V>>
|
|
39
|
+
: V extends string ? JSONConstType<JSONStringType, V>
|
|
40
|
+
: V extends Type<any, infer J> ? J
|
|
41
|
+
: JSONNullType
|
|
42
|
+
|
|
43
|
+
export function normalizeTypeLikes(fields: TypeLikes): Type {
|
|
44
|
+
return (Array.isArray(fields)
|
|
45
|
+
? _object(fields.map(normalizeTypeLike))
|
|
46
|
+
: _object(Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, normalizeTypeLike(v)]))))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function normalizeTypeLike(value: TypeLike): Type {
|
|
50
|
+
if (!value) {
|
|
51
|
+
return null_
|
|
52
|
+
}
|
|
53
|
+
if (typeof value === "string") {
|
|
54
|
+
return const_(string, value)
|
|
55
|
+
}
|
|
56
|
+
if (isType(value)) {
|
|
57
|
+
return value
|
|
58
|
+
}
|
|
59
|
+
return normalizeTypeLikes(value)
|
|
60
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Type } from "./Type.ts"
|
|
2
|
+
import { type IntrinsicTypes, typeName } from "./type_common.ts"
|
|
3
|
+
|
|
4
|
+
export type VisitorArms<S, R> =
|
|
5
|
+
& {
|
|
6
|
+
hook?: (
|
|
7
|
+
next: (state: S, type: Type) => R,
|
|
8
|
+
state: S,
|
|
9
|
+
type: Type,
|
|
10
|
+
) => R
|
|
11
|
+
}
|
|
12
|
+
& (
|
|
13
|
+
| (
|
|
14
|
+
& IntrinsicVisitorArms<S, R>
|
|
15
|
+
& { fallback?: never }
|
|
16
|
+
)
|
|
17
|
+
| (
|
|
18
|
+
& Partial<IntrinsicVisitorArms<S, R>>
|
|
19
|
+
& { fallback: () => R }
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
export type IntrinsicVisitorArms<S, R> = {
|
|
24
|
+
[K in keyof IntrinsicTypes]: (
|
|
25
|
+
state: S,
|
|
26
|
+
...args: IntrinsicTypes[K] extends Type ? [IntrinsicTypes[K]]
|
|
27
|
+
: IntrinsicTypes[K] extends (...args: infer A) => infer T ? [T, ...A]
|
|
28
|
+
: never
|
|
29
|
+
) => R
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type TypeVisitor<S, R> = (state: S, type: Type) => R
|
|
33
|
+
|
|
34
|
+
export function TypeVisitor<S, R>(arms: VisitorArms<S, R>): (state: S, type: Type) => R {
|
|
35
|
+
const { hook } = arms
|
|
36
|
+
if (hook) {
|
|
37
|
+
return (state, type) => hook(next, state, type)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return next
|
|
41
|
+
|
|
42
|
+
function next(state: S, type: Type): R {
|
|
43
|
+
return (arms[typeName(type)] as any ?? arms.fallback)(
|
|
44
|
+
state,
|
|
45
|
+
type,
|
|
46
|
+
...(type.args ?? []),
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
}
|
package/types/array.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { declareType } from "./declareType.ts"
|
|
2
|
+
import type { JSONType } from "./JSONType.ts"
|
|
3
|
+
import type { JSONTypeBase } from "./JSONTypeBase.ts"
|
|
4
|
+
import type { Type } from "./Type.ts"
|
|
5
|
+
import { normalizeTypeLike, type NormalizeTypeLikeJ, type NormalizeTypeLikeT, type TypeLike } from "./TypeLike.ts"
|
|
6
|
+
|
|
7
|
+
export function array<const F extends TypeLike>(
|
|
8
|
+
element: F,
|
|
9
|
+
): Type<Array<NormalizeTypeLikeT<F>>, JSONArrayType<NormalizeTypeLikeJ<F>>> {
|
|
10
|
+
return _array(normalizeTypeLike(element)) as never
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function _array(element: Type): Type {
|
|
14
|
+
return declareType(() => _array, [element])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface JSONArrayType<E extends JSONType = any> extends JSONTypeBase {
|
|
18
|
+
type: "array"
|
|
19
|
+
items: E
|
|
20
|
+
}
|
package/types/boolean.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { declareType } from "./declareType.ts"
|
|
2
|
+
import type { JSONTypeBase } from "./JSONTypeBase.ts"
|
|
3
|
+
import type { Type } from "./Type.ts"
|
|
4
|
+
|
|
5
|
+
export const boolean: Type<boolean, JSONBooleanType> = declareType(() => boolean)
|
|
6
|
+
|
|
7
|
+
export interface JSONBooleanType extends JSONTypeBase {
|
|
8
|
+
type: "boolean"
|
|
9
|
+
}
|
package/types/const.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { JSONValue } from "../util/JSONValue.ts"
|
|
2
|
+
import { declareType } from "./declareType.ts"
|
|
3
|
+
import type { ConstableType } from "./JSONType.ts"
|
|
4
|
+
import type { Type } from "./Type.ts"
|
|
5
|
+
|
|
6
|
+
function const_<T extends JSONValue, J extends ConstableType, const V extends T>(
|
|
7
|
+
type: Type<T, J>,
|
|
8
|
+
value: V,
|
|
9
|
+
): Type<V, JSONConstType<J, V>> {
|
|
10
|
+
return declareType(() => const_<T, J, V>, [type, value])
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(const_, "name", { value: "const" })
|
|
13
|
+
export { const_ as const }
|
|
14
|
+
|
|
15
|
+
export type JSONConstType<J extends ConstableType = any, V extends JSONValue = JSONValue> = J & {
|
|
16
|
+
const: V
|
|
17
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from "@standard-schema/spec"
|
|
2
|
+
import { infer } from "../actions/infer.ts"
|
|
3
|
+
import { LiminalAssertionError } from "../LiminalAssertionError.ts"
|
|
4
|
+
import type { Falsy } from "../util/Falsy.ts"
|
|
5
|
+
import { applyTemplateWithIndentation } from "../util/fixTemplateStrings.ts"
|
|
6
|
+
import { isTemplateStringsArray } from "../util/isTemplateStringsArray.ts"
|
|
7
|
+
import type { JSONObject } from "../util/JSONObject.ts"
|
|
8
|
+
import { AssertDiagnostics, formatAssertDiagnostics } from "./AssertDiagnostics.ts"
|
|
9
|
+
import type { JSONObjectType } from "./object.ts"
|
|
10
|
+
import { toJSON } from "./toJSON.ts"
|
|
11
|
+
import { type Type, TypeKey, type TypeMembers } from "./Type.ts"
|
|
12
|
+
|
|
13
|
+
export function declareType<X extends Type>(
|
|
14
|
+
declaration: () => X | ((...args: any) => X),
|
|
15
|
+
args?: Array<unknown>,
|
|
16
|
+
descriptions: Array<string> = [],
|
|
17
|
+
): X {
|
|
18
|
+
const type = Object.assign(
|
|
19
|
+
Type,
|
|
20
|
+
{
|
|
21
|
+
[TypeKey]: true,
|
|
22
|
+
declaration,
|
|
23
|
+
args,
|
|
24
|
+
descriptions,
|
|
25
|
+
description() {
|
|
26
|
+
return descriptions.join("\n")
|
|
27
|
+
},
|
|
28
|
+
"~standard": {
|
|
29
|
+
vendor: "liminal",
|
|
30
|
+
version: 1,
|
|
31
|
+
validate: (value) => {
|
|
32
|
+
const diagnostics = AssertDiagnostics({}, type as never, value)
|
|
33
|
+
if (diagnostics.length) {
|
|
34
|
+
return {
|
|
35
|
+
issues: diagnostics.map(({ path, error }): StandardSchemaV1.Issue => ({
|
|
36
|
+
path,
|
|
37
|
+
message: JSON.stringify(error),
|
|
38
|
+
})),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return { value: value as X["T"] }
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
toJSON,
|
|
45
|
+
assert: (value) => {
|
|
46
|
+
const diagnostics = AssertDiagnostics({}, type as never, value)
|
|
47
|
+
if (diagnostics.length) {
|
|
48
|
+
throw new LiminalAssertionError(formatAssertDiagnostics(diagnostics))
|
|
49
|
+
}
|
|
50
|
+
return value as never
|
|
51
|
+
},
|
|
52
|
+
...{
|
|
53
|
+
*[Symbol.iterator](this: Type<JSONObject, JSONObjectType>) {
|
|
54
|
+
return yield* infer(this)
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
} satisfies TypeMembers<X["T"], X["J"]>,
|
|
58
|
+
) as never as X
|
|
59
|
+
return type
|
|
60
|
+
|
|
61
|
+
function Type(template: TemplateStringsArray, ...substitutions: Array<string>): X
|
|
62
|
+
function Type(...values: Array<Falsy | string>): X
|
|
63
|
+
function Type(e0: TemplateStringsArray | Falsy | string, ...eRest: Array<Falsy | string>): X {
|
|
64
|
+
return declareType(declaration, args, [
|
|
65
|
+
...descriptions,
|
|
66
|
+
...isTemplateStringsArray(e0)
|
|
67
|
+
? [applyTemplateWithIndentation(e0, ...eRest)]
|
|
68
|
+
: [e0, ...eRest].filter((v): v is string => !!v),
|
|
69
|
+
])
|
|
70
|
+
}
|
|
71
|
+
}
|
package/types/enum.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { declareType } from "./declareType.ts"
|
|
2
|
+
import type { JSONTypeBase } from "./JSONTypeBase.ts"
|
|
3
|
+
import type { Type } from "./Type.ts"
|
|
4
|
+
|
|
5
|
+
export { enum_ as enum }
|
|
6
|
+
function enum_<A extends Array<string>>(...values: A): Type<A[number], JSONEnumType<A[number]>> {
|
|
7
|
+
return declareType(() => enum_<A>, values)
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(enum_, "name", { value: "enum" })
|
|
10
|
+
|
|
11
|
+
export interface JSONEnumType<K extends string = string> extends JSONTypeBase {
|
|
12
|
+
type: "string"
|
|
13
|
+
enum: Array<K>
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { array } from "./array.ts"
|
|
2
|
+
export { boolean, const, enum, integer, null, number, ref, string } from "./intrinsics.ts"
|
|
3
|
+
export { MetatypeDescriptor, MetatypeRootDescriptor } from "./Metatype/MetatypeDescriptor.ts"
|
|
4
|
+
export { object } from "./object.ts"
|
|
5
|
+
export { option } from "./types_derived/option.ts"
|
|
6
|
+
export { taggedUnion } from "./types_derived/taggedUnion.ts"
|
|
7
|
+
export { wrapper } from "./types_derived/wrapper.ts"
|
|
8
|
+
export { union } from "./union.ts"
|
package/types/index.ts
ADDED
package/types/integer.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { declareType } from "./declareType.ts"
|
|
2
|
+
import type { JSONTypeBase } from "./JSONTypeBase.ts"
|
|
3
|
+
import type { Type } from "./Type.ts"
|
|
4
|
+
|
|
5
|
+
export const integer: Type<number, JSONIntegerType> = declareType(() => integer)
|
|
6
|
+
|
|
7
|
+
export interface JSONIntegerType extends JSONTypeBase {
|
|
8
|
+
type: "integer"
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { _array } from "./array.ts"
|
|
2
|
+
export { boolean } from "./boolean.ts"
|
|
3
|
+
export { const } from "./const.ts"
|
|
4
|
+
export { enum } from "./enum.ts"
|
|
5
|
+
export { integer } from "./integer.ts"
|
|
6
|
+
export { null } from "./null.ts"
|
|
7
|
+
export { number } from "./number.ts"
|
|
8
|
+
export { _object } from "./object.ts"
|
|
9
|
+
export { ref } from "./ref.ts"
|
|
10
|
+
export { string } from "./string.ts"
|
|
11
|
+
export { _union } from "./union.ts"
|
package/types/match.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { JSONValue } from "../util/JSONValue.ts"
|
|
2
|
+
import { AssertDiagnostics } from "./AssertDiagnostics.ts"
|
|
3
|
+
import type { Type } from "./Type.ts"
|
|
4
|
+
|
|
5
|
+
export function match(value: JSONValue, members: Array<Type>): Type | undefined {
|
|
6
|
+
for (const member of members) {
|
|
7
|
+
const diagnostics = AssertDiagnostics({}, member, value)
|
|
8
|
+
if (!diagnostics.length) {
|
|
9
|
+
return member
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type { JSONArrayType } from "./array.ts"
|
|
2
|
+
export type { JSONBooleanType } from "./boolean.ts"
|
|
3
|
+
export type { JSONConstType } from "./const.ts"
|
|
4
|
+
export type { JSONEnumType } from "./enum.ts"
|
|
5
|
+
export type { JSONIntegerType } from "./integer.ts"
|
|
6
|
+
export * from "./JSONRootType.ts"
|
|
7
|
+
export * from "./JSONType.ts"
|
|
8
|
+
export { match } from "./match.ts"
|
|
9
|
+
export * from "./Metatype/fromMetatypeDescriptor.ts"
|
|
10
|
+
export type { MetatypeDescriptor, MetatypeRootDescriptor } from "./Metatype/MetatypeDescriptor.ts"
|
|
11
|
+
export type { JSONNullType } from "./null.ts"
|
|
12
|
+
export type { JSONNumberType } from "./number.ts"
|
|
13
|
+
export type {
|
|
14
|
+
JSONObjectType,
|
|
15
|
+
ObjectFields as _ObjectFields,
|
|
16
|
+
RecordFields as _RecordFields,
|
|
17
|
+
TupleFields as _TupleFields,
|
|
18
|
+
} from "./object.ts"
|
|
19
|
+
export type { JSONRefType } from "./ref.ts"
|
|
20
|
+
export type { JSONStringType } from "./string.ts"
|
|
21
|
+
export * from "./Type.ts"
|
|
22
|
+
export * from "./TypeContext.ts"
|
|
23
|
+
export * from "./TypeLike.ts"
|
|
24
|
+
export type { TaggedUnionMembers } from "./types_derived/taggedUnion.ts"
|
|
25
|
+
export * from "./TypeVisitor.ts"
|
|
26
|
+
export type { JSONUnionType } from "./union.ts"
|
package/types/null.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { declareType } from "./declareType.ts"
|
|
2
|
+
import type { JSONTypeBase } from "./JSONTypeBase.ts"
|
|
3
|
+
import type { Type } from "./Type.ts"
|
|
4
|
+
|
|
5
|
+
const null_: Type<null, JSONNullType> = declareType(() => null_)
|
|
6
|
+
export { null_ as null }
|
|
7
|
+
|
|
8
|
+
export interface JSONNullType extends JSONTypeBase {
|
|
9
|
+
type: "null"
|
|
10
|
+
}
|
package/types/number.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { declareType } from "./declareType.ts"
|
|
2
|
+
import type { JSONTypeBase } from "./JSONTypeBase.ts"
|
|
3
|
+
import type { Type } from "./Type.ts"
|
|
4
|
+
|
|
5
|
+
export const number: Type<number, JSONNumberType> = declareType(() => number)
|
|
6
|
+
|
|
7
|
+
export interface JSONNumberType extends JSONTypeBase {
|
|
8
|
+
type: "number"
|
|
9
|
+
}
|
package/types/object.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { JSONKey } from "../util/JSONKey.ts"
|
|
2
|
+
import { declareType } from "./declareType.ts"
|
|
3
|
+
import type { JSONType } from "./JSONType.ts"
|
|
4
|
+
import type { JSONTypeBase } from "./JSONTypeBase.ts"
|
|
5
|
+
import { type Type } from "./Type.ts"
|
|
6
|
+
import { normalizeTypeLikes, type NormalizeTypeLikesJ, type NormalizeTypeLikesT, type TypeLikes } from "./TypeLike.ts"
|
|
7
|
+
|
|
8
|
+
export function object<const F extends TypeLikes>(
|
|
9
|
+
fields: F,
|
|
10
|
+
): Type<NormalizeTypeLikesT<F>, JSONObjectType<NormalizeTypeLikesJ<F>>> {
|
|
11
|
+
return normalizeTypeLikes(fields) as never
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function _object(fields: ObjectFields): Type {
|
|
15
|
+
return declareType(() => _object, [fields])
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface JSONObjectType<F extends Record<JSONKey, JSONType> = any> extends JSONTypeBase {
|
|
19
|
+
type: "object"
|
|
20
|
+
properties: F
|
|
21
|
+
required: Array<keyof F>
|
|
22
|
+
additionalProperties: false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type ObjectFields = TupleFields | RecordFields
|
|
26
|
+
export type TupleFields = Array<Type>
|
|
27
|
+
export type RecordFields = Record<JSONKey, Type>
|
package/types/ref.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JSONValue } from "../util/JSONValue.ts"
|
|
2
|
+
import { declareType } from "./declareType.ts"
|
|
3
|
+
import type { ConstableType } from "./JSONType.ts"
|
|
4
|
+
import type { Type } from "./Type.ts"
|
|
5
|
+
|
|
6
|
+
export function ref<T extends JSONValue, J extends ConstableType>(getType: () => Type<T, J>): Type<T, JSONRefType> {
|
|
7
|
+
return declareType(() => ref<T, J>, [getType])
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface JSONRefType {
|
|
11
|
+
$ref: string
|
|
12
|
+
}
|
package/types/string.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { declareType } from "./declareType.ts"
|
|
2
|
+
import type { JSONTypeBase } from "./JSONTypeBase.ts"
|
|
3
|
+
import type { Type } from "./Type.ts"
|
|
4
|
+
|
|
5
|
+
export const string: Type<string, JSONStringType> = declareType(() => string)
|
|
6
|
+
|
|
7
|
+
export interface JSONStringType extends JSONTypeBase {
|
|
8
|
+
type: "string"
|
|
9
|
+
}
|