@dxos/compute 0.8.4-main.c85a9c8dae → 0.8.4-main.cb12b3f963
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 +36 -1
- package/dist/lib/neutral/StorageService.mjs +22 -0
- package/dist/lib/neutral/StorageService.mjs.map +7 -0
- package/dist/lib/neutral/chunk-4N4JAXCP.mjs +17 -0
- package/dist/lib/neutral/chunk-4N4JAXCP.mjs.map +7 -0
- package/dist/lib/neutral/chunk-DDEBBRCI.mjs +62 -0
- package/dist/lib/neutral/chunk-DDEBBRCI.mjs.map +7 -0
- package/dist/lib/neutral/chunk-FEABF5XY.mjs +25 -0
- package/dist/lib/neutral/chunk-FEABF5XY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-H6EHIVDN.mjs +21 -0
- package/dist/lib/neutral/chunk-H6EHIVDN.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/neutral/chunk-N462A6NO.mjs +138 -0
- package/dist/lib/neutral/chunk-N462A6NO.mjs.map +7 -0
- package/dist/lib/neutral/chunk-QPCDM7MF.mjs +179 -0
- package/dist/lib/neutral/chunk-QPCDM7MF.mjs.map +7 -0
- package/dist/lib/neutral/chunk-S24LL2D5.mjs +52 -0
- package/dist/lib/neutral/chunk-S24LL2D5.mjs.map +7 -0
- package/dist/lib/neutral/fib-HDHBZHPE.mjs +10 -0
- package/dist/lib/neutral/fib-HDHBZHPE.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1030 -51
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/lib/neutral/reply-XSQMXAPX.mjs +10 -0
- package/dist/lib/neutral/reply-XSQMXAPX.mjs.map +7 -0
- package/dist/lib/neutral/sleep-WHTJQ56P.mjs +10 -0
- package/dist/lib/neutral/sleep-WHTJQ56P.mjs.map +7 -0
- package/dist/lib/neutral/testing/index.mjs +27 -193
- package/dist/lib/neutral/testing/index.mjs.map +4 -4
- package/dist/types/src/Blueprint.d.ts +148 -0
- package/dist/types/src/Blueprint.d.ts.map +1 -0
- package/dist/types/src/Credential.d.ts +27 -0
- package/dist/types/src/Credential.d.ts.map +1 -0
- package/dist/types/src/Operation.d.ts +303 -0
- package/dist/types/src/Operation.d.ts.map +1 -0
- package/dist/types/src/OperationHandlerSet.d.ts +60 -0
- package/dist/types/src/OperationHandlerSet.d.ts.map +1 -0
- package/dist/types/src/OperationRegistry.d.ts +23 -0
- package/dist/types/src/OperationRegistry.d.ts.map +1 -0
- package/dist/types/src/Process.d.ts +247 -0
- package/dist/types/src/Process.d.ts.map +1 -0
- package/dist/types/src/Routine.d.ts +61 -0
- package/dist/types/src/Routine.d.ts.map +1 -0
- package/dist/types/src/Script.d.ts +22 -0
- package/dist/types/src/Script.d.ts.map +1 -0
- package/dist/types/src/ServiceResolver.d.ts +74 -0
- package/dist/types/src/ServiceResolver.d.ts.map +1 -0
- package/dist/types/src/StorageService.d.ts +58 -0
- package/dist/types/src/StorageService.d.ts.map +1 -0
- package/dist/types/src/Template.d.ts +56 -0
- package/dist/types/src/Template.d.ts.map +1 -0
- package/dist/types/src/Trace.d.ts +174 -0
- package/dist/types/src/Trace.d.ts.map +1 -0
- package/dist/types/src/Trigger.d.ts +150 -0
- package/dist/types/src/Trigger.d.ts.map +1 -0
- package/dist/types/src/TriggerEvent.d.ts +75 -0
- package/dist/types/src/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/errors.d.ts +239 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +15 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/testing/definitions.d.ts +11 -0
- package/dist/types/src/testing/definitions.d.ts.map +1 -0
- package/dist/types/src/testing/fib.d.ts +8 -0
- package/dist/types/src/testing/fib.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +6 -4
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/reply.d.ts +4 -0
- package/dist/types/src/testing/reply.d.ts.map +1 -0
- package/dist/types/src/testing/sleep.d.ts +6 -0
- package/dist/types/src/testing/sleep.d.ts.map +1 -0
- package/dist/types/src/umbrella.test.d.ts +2 -0
- package/dist/types/src/umbrella.test.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -34
- package/src/Blueprint.ts +221 -0
- package/src/Credential.ts +51 -0
- package/src/Operation.ts +513 -0
- package/src/OperationHandlerSet.ts +132 -0
- package/src/OperationRegistry.ts +48 -0
- package/src/Process.ts +490 -0
- package/src/Routine.ts +84 -0
- package/src/Script.ts +38 -0
- package/src/ServiceResolver.ts +174 -0
- package/src/StorageService.ts +99 -0
- package/src/Template.ts +105 -0
- package/src/Trace.ts +231 -0
- package/src/Trigger.ts +207 -0
- package/src/TriggerEvent.ts +62 -0
- package/src/errors.ts +50 -0
- package/src/index.ts +16 -6
- package/src/testing/definitions.ts +49 -0
- package/src/testing/fib.ts +22 -0
- package/src/testing/index.ts +13 -5
- package/src/testing/reply.ts +18 -0
- package/src/testing/sleep.ts +16 -0
- package/src/umbrella.test.ts +51 -0
- package/dist/lib/neutral/chunk-KGBGT4NT.mjs +0 -3106
- package/dist/lib/neutral/chunk-KGBGT4NT.mjs.map +0 -7
- package/dist/types/src/compute-graph-registry.d.ts +0 -37
- package/dist/types/src/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/compute-graph-registry.test.d.ts +0 -2
- package/dist/types/src/compute-graph-registry.test.d.ts.map +0 -1
- package/dist/types/src/compute-graph.d.ts +0 -67
- package/dist/types/src/compute-graph.d.ts.map +0 -1
- package/dist/types/src/compute-graph.test.d.ts +0 -2
- package/dist/types/src/compute-graph.test.d.ts.map +0 -1
- package/dist/types/src/compute-node.d.ts +0 -24
- package/dist/types/src/compute-node.d.ts.map +0 -1
- package/dist/types/src/functions/async-function.d.ts +0 -68
- package/dist/types/src/functions/async-function.d.ts.map +0 -1
- package/dist/types/src/functions/edge-function.d.ts +0 -20
- package/dist/types/src/functions/edge-function.d.ts.map +0 -1
- package/dist/types/src/functions/function-defs.d.ts +0 -11
- package/dist/types/src/functions/function-defs.d.ts.map +0 -1
- package/dist/types/src/functions/index.d.ts +0 -4
- package/dist/types/src/functions/index.d.ts.map +0 -1
- package/dist/types/src/hyperformula.test.d.ts +0 -2
- package/dist/types/src/hyperformula.test.d.ts.map +0 -1
- package/dist/types/src/testing/test-builder.d.ts +0 -15
- package/dist/types/src/testing/test-builder.d.ts.map +0 -1
- package/dist/types/src/testing/test-plugin.d.ts +0 -35
- package/dist/types/src/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/testing/test-runtime.d.ts +0 -10
- package/dist/types/src/testing/test-runtime.d.ts.map +0 -1
- package/dist/types/src/testing/util.d.ts +0 -2
- package/dist/types/src/testing/util.d.ts.map +0 -1
- package/dist/types/src/types/hyperformula.d.ts +0 -8
- package/dist/types/src/types/hyperformula.d.ts.map +0 -1
- package/dist/types/src/types/index.d.ts +0 -3
- package/dist/types/src/types/index.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -20
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/dist/types/src/types/types.test.d.ts +0 -2
- package/dist/types/src/types/types.test.d.ts.map +0 -1
- package/dist/types/src/util.d.ts +0 -2
- package/dist/types/src/util.d.ts.map +0 -1
- package/src/compute-graph-registry.test.ts +0 -158
- package/src/compute-graph-registry.ts +0 -97
- package/src/compute-graph.test.ts +0 -107
- package/src/compute-graph.ts +0 -264
- package/src/compute-node.ts +0 -59
- package/src/functions/async-function.ts +0 -184
- package/src/functions/edge-function.ts +0 -113
- package/src/functions/function-defs.ts +0 -2427
- package/src/functions/index.ts +0 -7
- package/src/hyperformula.test.ts +0 -14
- package/src/testing/test-builder.ts +0 -60
- package/src/testing/test-plugin.ts +0 -98
- package/src/testing/test-runtime.ts +0 -35
- package/src/testing/util.ts +0 -9
- package/src/types/hyperformula.ts +0 -19
- package/src/types/index.ts +0 -6
- package/src/types/types.test.ts +0 -91
- package/src/types/types.ts +0 -80
- package/src/util.ts +0 -8
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Operation.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\nimport * as Pipeable from 'effect/Pipeable';\nimport * as Schema$ from 'effect/Schema';\nimport type * as Types from 'effect/Types';\n\nimport { Annotation, JsonSchema, Obj, Ref, Type, type DXN, type Key } from '@dxos/echo';\n\nimport type { NoHandlerError } from './errors';\nimport type { Operation } from './index';\n\n// @import-as-namespace\n\n/**\n * Schema type that accepts any Encoded form but requires no Context.\n * This allows ECHO object schemas where Type !== Encoded due to [KindId] symbol.\n */\ntype Schema<T> = Schema$.Schema<T, any, never>;\n\nexport const DefinitionTypeId = '~@dxos/operation/OperationDefinition' as const;\nexport type DefinitionTypeId = typeof DefinitionTypeId;\n\n/**\n * Serializable definition of an Operation.\n * Contains schema and metadata, but no runtime logic.\n */\nexport interface Definition<I, O, S = any> extends Pipeable.Pipeable, Definition.Variance<I, O, S> {\n /**\n * Input schema for the operation.\n */\n readonly input: Schema<I>;\n /**\n * Output schema for the operation.\n */\n readonly output: Schema<O>;\n\n readonly meta: {\n readonly key: string;\n readonly name?: string;\n readonly version?: string;\n readonly description?: string;\n /**\n * Deployment ID for remote invocation.\n * Assigned by the EDGE function service when deployed.\n */\n readonly deployedId?: string;\n };\n\n /**\n * Execution mode for the operation.\n * - 'sync': Operation completes synchronously (fast, UI-blocking acceptable).\n * - 'async': Operation may take time (should not block UI).\n */\n readonly executionMode: 'sync' | 'async';\n\n /**\n * ECHO types the operation uses.\n * Ensures types are available when the operation is executed remotely.\n */\n readonly types: readonly Type.AnyEntity[];\n\n /**\n * Effect services required by this operation.\n * These services will be automatically provided to the handler at invocation time.\n */\n readonly services: readonly Context.Tag<any, any>[];\n}\n\n/**\n * Namespace for OperationDefinition helper types.\n */\nexport declare namespace Definition {\n export interface Variance<I, O, S> {\n [DefinitionTypeId]: {\n readonly _Input: Types.Contravariant<I>;\n readonly _Output: Types.Covariant<O>;\n readonly _Services: Types.Covariant<S>;\n };\n }\n\n /**\n * Any operation definition, regardless of input/output types.\n */\n export type Any = Definition<any, any, any>;\n\n /**\n * Extract the input type from an operation definition.\n */\n export type Input<T extends Any> = T extends Variance<infer I, infer _O, infer _S> ? I : never;\n\n /**\n * Extract the output type from an operation definition.\n */\n export type Output<T extends Any> = T extends Variance<infer _I, infer O, infer _S> ? O : never;\n\n /**\n * Extract the service identifier types from an operation's services array.\n * Returns `never` if the operation has no services declared.\n */\n export type Services<T extends Any> = T extends Variance<infer _I, infer _O, infer S> ? S : never;\n\n export type HandlerType<T extends Any> =\n T extends Variance<infer I, infer O, infer S> ? Handler<I, O, any, S> : never;\n}\n\n/**\n * Runtime handler for an Operation.\n */\nexport type Handler<I, O, E = Error, R = never> = (input: I) => Effect.Effect<O, E, R>;\n\nexport type WithHandler<T extends Definition.Any> = T & {\n handler: Definition.HandlerType<T>;\n};\n\n/**\n * Checks if a value is an operation definition.\n */\nexport const isOperationDefinition = (value: unknown): value is Definition.Any => {\n return typeof value === 'object' && value !== null && DefinitionTypeId in value;\n};\n\n/**\n * Checks if a value is an operation with a handler.\n */\nexport const isOperationWithHandler = (value: unknown): value is WithHandler<Definition.Any> => {\n return isOperationDefinition(value) && 'handler' in value;\n};\n\n/**a\n * Props for creating an Operation definition.\n * Derived from OperationDefinition with executionMode made optional (defaults to 'async').\n */\nexport type Props<I, O> = Omit<Definition<I, O>, DefinitionTypeId | 'pipe' | 'executionMode' | 'types' | 'services'> & {\n readonly executionMode?: 'sync' | 'async';\n readonly types?: Definition<I, O>['types'];\n readonly services?: Definition<I, O>['services'];\n};\n\n/**\n * Creates a new Operation definition.\n * Applies default executionMode of 'async' if not specified.\n * The returned type preserves the literal types of props (including services).\n */\nexport const make = <const P extends Types.NoExcessProperties<Props<any, any>, P>>(\n props: P,\n): Definition<\n Schema$.Schema.Type<P['input']>,\n Schema$.Schema.Type<P['output']>,\n Context.Tag.Identifier<NonNullable<P['services']>[number]>\n> => {\n return {\n [DefinitionTypeId]: {},\n ...props,\n executionMode: props.executionMode ?? 'async',\n types: props.types ?? [],\n services: props.services ?? [],\n pipe() {\n // eslint-disable-next-line prefer-rest-params\n return Pipeable.pipeArguments(this, arguments);\n },\n } as any;\n};\n\n/**\n * Attaches a handler to an Operation definition.\n * The handler may use any services declared in the operation, plus Operation.Service (always available).\n * Dual API: can be called directly or used in a pipe.\n *\n * @example\n * ```ts\n * const MyOp = Operation.make({\n * input: Schema.Void,\n * output: Schema.Void,\n * meta: { key: 'my-op' },\n * services: [DatabaseService],\n * });\n *\n * // Direct call - handler can use DatabaseService\n * const op = Operation.withHandler(MyOp, (input) =>\n * Effect.gen(function* () {\n * const db = yield* DatabaseService;\n * return {};\n * }),\n * );\n *\n * // Piped call\n * const op = MyOp.pipe(Operation.withHandler((input) => Effect.succeed({})));\n * ```\n */\nexport const withHandler: {\n <Def extends Definition<any, any>, E = never>(\n handler: Handler<Definition.Input<Def>, Definition.Output<Def>, E, Definition.Services<Def> | Service>,\n ): (op: Def) => WithHandler<Def>;\n <Def extends Definition<any, any>, E = never>(\n op: Def,\n handler: Handler<Definition.Input<Def>, Definition.Output<Def>, E, Definition.Services<Def> | Service>,\n ): WithHandler<Def>;\n} = <Def extends Definition<any, any>, E = never>(\n opOrHandler: Def | Handler<Definition.Input<Def>, Definition.Output<Def>, E, Definition.Services<Def> | Service>,\n handler?: Handler<Definition.Input<Def>, Definition.Output<Def>, E, Definition.Services<Def> | Service>,\n): WithHandler<Def> => {\n // If called with just handler (piped usage).\n if (handler === undefined) {\n const handlerFn = opOrHandler as Handler<\n Definition.Input<Def>,\n Definition.Output<Def>,\n E,\n Definition.Services<Def> | Service\n >;\n return ((op: Def) => ({\n ...op,\n handler: handlerFn,\n })) as any;\n }\n\n // If called with both op and handler (direct usage).\n const op = opOrHandler as Def;\n return {\n ...op,\n handler,\n } as any;\n};\n\n/**\n * Helper to make the handler type opaque.\n * Workaround for TypeScript's inability to infer the handler type from the operation definition:\n * ```\n * error TS2742: The inferred type of 'default' cannot be named without a reference.\n * ```\n *\n * Most of the time the exact handler type is not needed.\n *\n * @example\n * ```ts\n * const MyOp = Operation.make({\n * input: Schema.Void,\n * output: Schema.Void,\n * meta: { key: 'my-op' },\n * services: [DatabaseService],\n * });\n *\n * export default MyOp.pipe(\n * Operation.withHandler(\n * Effect.fn(function* (input) {\n * return { result: 'ok' };\n * }),\n * ),\n * Operation.opaqueHandler,\n * );\n * ```\n */\nexport const opaqueHandler = <T extends Operation.Definition.Any>(\n handler: Operation.WithHandler<T>,\n): Operation.WithHandler<Operation.Definition.Any> => handler;\n\n//\n// Invocation Interfaces\n//\n\n/**\n * Local invocation of an operation.\n */\nexport type Invoke = <I, O, E>(op: Definition<I, O>, input: I) => Effect.Effect<O, E>;\n\n/**\n * Remote invocation of an operation.\n */\nexport type InvokeRemote = <I, O, E>(\n op: Definition<I, O>,\n input: I,\n options?: { timeout?: number },\n) => Effect.Effect<O, E>;\n\n/**\n * Database record of an operation.\n */\nexport const PersistentOperation = Schema$.Struct({\n /**\n * Global registry ID.\n * NOTE: The `key` property refers to the original registry entry.\n */\n // TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.\n // TODO(dmaretskyi): Consider making it part of ECHO meta.\n // TODO(dmaretskyi): Make required.\n key: Schema$.optional(Schema$.String).annotations({\n description: 'Unique registration key for the blueprint',\n }),\n\n name: Schema$.NonEmptyString,\n version: Schema$.String,\n\n description: Schema$.optional(Schema$.String),\n\n /**\n * ISO date string of the last deployment.\n */\n updated: Schema$.optional(Schema$.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: Schema$.optional(Ref.Ref(Obj.Unknown)),\n\n inputSchema: Schema$.optional(JsonSchema.JsonSchema),\n outputSchema: Schema$.optional(JsonSchema.JsonSchema),\n\n /**\n * List of required services.\n * Match the Context.Tag keys of the FunctionServices variants.\n */\n services: Schema$.optional(Schema$.Array(Schema$.String)),\n\n // Local binding to a function name.\n // TODO(dmaretskyi): Add this field to Operation.Definition.\n binding: Schema$.optional(Schema$.String),\n}).pipe(\n // TODO(dmaretskyi): Keep typename as 'org.dxos.type.function' (not 'operation') to maintain\n // backward compatibility with existing data and avoid requiring data migration.\n Type.object({\n typename: 'org.dxos.type.function',\n version: '0.1.0',\n }),\n Annotation.LabelAnnotation.set(['name']),\n Annotation.IconAnnotation.set({ icon: 'ph--function--regular', hue: 'blue' }),\n Annotation.SystemTypeAnnotation.set(true),\n);\nexport interface PersistentOperation extends Schema$.Schema.Type<typeof PersistentOperation> {}\n\n/**\n * Serialize an operation definition to a persistent operation record.\n */\nexport const serialize = (operation: Definition.Any): PersistentOperation => {\n return Obj.make(PersistentOperation, {\n key: operation.meta.key,\n name: operation.meta.name ?? '',\n version: operation.meta.version ?? '0.0.0',\n description: operation.meta.description,\n updated: undefined,\n source: undefined,\n inputSchema: JsonSchema.toJsonSchema(operation.input),\n outputSchema: JsonSchema.toJsonSchema(operation.output),\n services: operation.services.map((service) => service.key),\n });\n};\n\n/**\n * Deserialize a persistent operation record to an operation definition.\n */\nexport const deserialize = (record: PersistentOperation): Definition.Any => {\n // Extract deployed function ID from ECHO meta keys (matches FUNCTIONS_META_KEY in @dxos/functions).\n const deployedId = Obj.getMeta(record).keys.find((key) => key.source === 'org.dxos.service.function')?.id;\n return make({\n input: record.inputSchema ? JsonSchema.toEffectSchema(record.inputSchema) : Schema$.Unknown,\n output: record.outputSchema ? JsonSchema.toEffectSchema(record.outputSchema) : Schema$.Unknown,\n services: record.services?.map((service) => Context.GenericTag(service)) ?? [],\n executionMode: 'async',\n types: [],\n meta: {\n key: record.key ?? record.name,\n name: record.name,\n version: record.version,\n description: record.description,\n deployedId,\n },\n });\n};\n\n/**\n * Update properties on the target operation record from the source operation record.\n */\nexport const setFrom = (target: PersistentOperation, source: PersistentOperation) => {\n Obj.update(target, (target) => {\n target.key = source.key ?? target.key;\n target.name = source.name ?? target.name;\n target.version = source.version;\n target.description = source.description;\n target.updated = source.updated;\n // TODO(dmaretskyi): A workaround for an ECHO bug.\n target.inputSchema = source.inputSchema ? JSON.parse(JSON.stringify(source.inputSchema)) : undefined;\n target.outputSchema = source.outputSchema ? JSON.parse(JSON.stringify(source.outputSchema)) : undefined;\n Obj.getMeta(target).keys = JSON.parse(JSON.stringify(Obj.getMeta(source).keys));\n });\n};\n\n/**\n * Options for operation invocation.\n */\nexport interface InvokeOptions {\n /**\n * Space ID to provide database context for the handler.\n */\n spaceId?: Key.SpaceId;\n /**\n * DXN string of the conversation feed (queue).\n * Passed to the process environment so nested operations can resolve AiContextService and related services.\n */\n conversation?: DXN.String;\n /**\n * Optional process-runtime tracing metadata (consumed by `@dxos/functions-runtime` when wired).\n */\n tracing?: unknown;\n}\n\n/**\n * Operation service interface - provides unified access to operation invocation and scheduling.\n * This service is automatically provided to operation handlers.\n */\nexport interface OperationService {\n /**\n * Invoke an operation as an Effect.\n * Returns an Effect that resolves to the operation output.\n */\n invoke: <I, O>(\n op: Operation.Definition<I, O>,\n ...args: void extends I ? [input?: I, options?: InvokeOptions] : [input: I, options?: InvokeOptions]\n ) => Effect.Effect<O, NoHandlerError>;\n\n /**\n * Schedule an operation to run as a followup.\n * The followup is tracked and won't be cancelled when the parent operation completes.\n * Returns an Effect that completes immediately after scheduling.\n */\n schedule: <I, O>(\n op: Operation.Definition<I, O>,\n ...args: void extends I ? [input?: I] : [input: I]\n ) => Effect.Effect<void>;\n\n /**\n * Invoke an operation and return a Promise.\n * Useful for async contexts where Effect is not available.\n */\n invokePromise: <I, O>(\n op: Operation.Definition<I, O>,\n ...args: void extends I ? [input?: I, options?: InvokeOptions] : [input: I, options?: InvokeOptions]\n ) => Promise<{ data?: O; error?: Error }>;\n}\n\n/**\n * Context tag for the Operation service.\n * Operation handlers can yield this to invoke other operations or schedule followups.\n *\n * @example\n * ```ts\n * const handler = (input) => Effect.gen(function* () {\n * // Schedule a followup (fire and forget)\n * yield* Operation.schedule(AnalyticsOperation, { event: 'completed' });\n *\n * // Invoke another operation\n * return yield* Operation.invoke(OtherOperation, { data: input.data });\n * });\n * ```\n */\n// TODO(dmaretskyi): Rename Operation.Invoker\nexport class Service extends Context.Tag('@dxos/operation/Service')<Service, OperationService>() {}\n\n//\n// Namespace functions - ergonomic access to Operation.Service methods.\n//\n\n/**\n * Invoke an operation as an Effect.\n * Yields the Operation.Service internally.\n *\n * @example\n * ```ts\n * yield* Operation.invoke(MyOperation, { data: 'test' });\n * ```\n */\nexport const invoke = <I, O>(\n op: Operation.Definition<I, O>,\n ...args: void extends I ? [input?: I, options?: InvokeOptions] : [input: I, options?: InvokeOptions]\n): Effect.Effect<O, NoHandlerError, Service> =>\n Effect.flatMap(Service, (ops) => ops.invoke(op, ...(args as [I, InvokeOptions?]))).pipe(\n Effect.withSpan('Operation.invoke'),\n );\n\n/**\n * Schedule an operation to run as a followup.\n * Yields the Operation.Service internally.\n *\n * @example\n * ```ts\n * yield* Operation.schedule(AnalyticsOperation, { event: 'completed' });\n * yield* Operation.schedule(VoidOperation); // input optional when void\n * ```\n */\nexport const schedule = <I, O>(\n op: Operation.Definition<I, O>,\n ...args: void extends I ? [input?: I] : [input: I]\n): Effect.Effect<void, never, Service> =>\n Effect.flatMap(Service, (ops) => ops.schedule(op, args[0] as I)).pipe(Effect.withSpan('Operation.schedule'));\n\n/**\n * Provides additional invocation options to all invocations.\n */\nexport const withInvocationOptions = (options: InvokeOptions): Layer.Layer<Service, never, Service> =>\n Layer.effect(\n Service,\n Effect.gen(function* () {\n const service = yield* Service;\n return Service.of({\n invoke: ((op: Operation.Definition.Any, input: any, invocationOptions: InvokeOptions) =>\n service.invoke(op, input, { ...options, ...invocationOptions })) as any,\n invokePromise: ((op: Operation.Definition.Any, input: any, invocationOptions: InvokeOptions) =>\n service.invokePromise(op, input, { ...options, ...invocationOptions })) as any,\n schedule: service.schedule,\n });\n }),\n );\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA;;;;;;;;;;;;;;;;;AAIA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,WAAW;AACvB,YAAYC,cAAc;AAC1B,YAAYC,aAAa;AAGzB,SAASC,YAAYC,YAAYC,KAAKC,KAAKC,YAAgC;AAapE,IAAMC,mBAAmB;AAkGzB,IAAMC,wBAAwB,CAACC,UAAAA;AACpC,SAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQF,oBAAoBE;AAC5E;AAKO,IAAMC,yBAAyB,CAACD,UAAAA;AACrC,SAAOD,sBAAsBC,KAAAA,KAAU,aAAaA;AACtD;AAiBO,IAAME,OAAO,CAClBC,UAAAA;AAMA,SAAO;IACL,CAACL,gBAAAA,GAAmB,CAAC;IACrB,GAAGK;IACHC,eAAeD,MAAMC,iBAAiB;IACtCC,OAAOF,MAAME,SAAS,CAAA;IACtBC,UAAUH,MAAMG,YAAY,CAAA;IAC5BC,OAAAA;AAEE,aAAgBC,uBAAc,MAAMC,SAAAA;IACtC;EACF;AACF;AA4BO,IAAMC,cAQT,CACFC,aACAC,YAAAA;AAGA,MAAIA,YAAYC,QAAW;AACzB,UAAMC,YAAYH;AAMlB,WAAQ,CAACI,SAAa;MACpB,GAAGA;MACHH,SAASE;IACX;EACF;AAGA,QAAMC,KAAKJ;AACX,SAAO;IACL,GAAGI;IACHH;EACF;AACF;AA8BO,IAAMI,gBAAgB,CAC3BJ,YACoDA;AAuB/C,IAAMK,sBAA8BC,eAAO;;;;;;;;EAQhDC,KAAaC,iBAAiBC,cAAM,EAAEC,YAAY;IAChDC,aAAa;EACf,CAAA;EAEAC,MAAcC;EACdC,SAAiBL;EAEjBE,aAAqBH,iBAAiBC,cAAM;;;;EAK5CM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AA,CAAE,CAAA,EAAQ7D,KAAYgE,gBAAS,oBAAA,CAAA;AAKjF,IAAME,wBAAwB,CAACC,YAC9BC,aACJV,SACOW,WAAI,aAAA;AACT,QAAM3B,UAAU,OAAOgB;AACvB,SAAOA,QAAQY,GAAG;IAChBV,QAAS,CAACpD,IAA8B+B,OAAYgC,sBAClD7B,QAAQkB,OAAOpD,IAAI+B,OAAO;MAAE,GAAG4B;MAAS,GAAGI;IAAkB,CAAA;IAC/DC,eAAgB,CAAChE,IAA8B+B,OAAYgC,sBACzD7B,QAAQ8B,cAAchE,IAAI+B,OAAO;MAAE,GAAG4B;MAAS,GAAGI;IAAkB,CAAA;IACtEN,UAAUvB,QAAQuB;EACpB,CAAA;AACF,CAAA,CAAA;",
|
|
6
|
+
"names": ["Context", "Effect", "Layer", "Pipeable", "Schema$", "Annotation", "JsonSchema", "Obj", "Ref", "Type", "DefinitionTypeId", "isOperationDefinition", "value", "isOperationWithHandler", "make", "props", "executionMode", "types", "services", "pipe", "pipeArguments", "arguments", "withHandler", "opOrHandler", "handler", "undefined", "handlerFn", "op", "opaqueHandler", "PersistentOperation", "Struct", "key", "optional", "String", "annotations", "description", "name", "NonEmptyString", "version", "updated", "source", "Unknown", "inputSchema", "outputSchema", "Array", "binding", "object", "typename", "LabelAnnotation", "set", "IconAnnotation", "icon", "hue", "SystemTypeAnnotation", "serialize", "operation", "meta", "toJsonSchema", "input", "output", "map", "service", "deserialize", "record", "deployedId", "getMeta", "keys", "find", "id", "toEffectSchema", "GenericTag", "setFrom", "target", "update", "JSON", "parse", "stringify", "Service", "Tag", "invoke", "args", "flatMap", "ops", "withSpan", "schedule", "withInvocationOptions", "options", "effect", "gen", "of", "invocationOptions", "invokePromise"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
make
|
|
3
|
+
} from "./chunk-QPCDM7MF.mjs";
|
|
4
|
+
|
|
5
|
+
// src/testing/definitions.ts
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
var Fibonacci = make({
|
|
8
|
+
meta: {
|
|
9
|
+
key: "org.example.function.fib",
|
|
10
|
+
name: "Fibonacci",
|
|
11
|
+
description: "Function that calculates a Fibonacci number"
|
|
12
|
+
},
|
|
13
|
+
input: Schema.Struct({
|
|
14
|
+
iterations: Schema.optional(Schema.Number).annotations({
|
|
15
|
+
description: "Number of iterations",
|
|
16
|
+
default: 1e5
|
|
17
|
+
})
|
|
18
|
+
}),
|
|
19
|
+
output: Schema.Struct({
|
|
20
|
+
result: Schema.String
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
var Reply = make({
|
|
24
|
+
meta: {
|
|
25
|
+
key: "org.example.function.reply",
|
|
26
|
+
name: "Reply",
|
|
27
|
+
description: "Function that echoes the input"
|
|
28
|
+
},
|
|
29
|
+
input: Schema.Any,
|
|
30
|
+
output: Schema.Any
|
|
31
|
+
});
|
|
32
|
+
var Sleep = make({
|
|
33
|
+
meta: {
|
|
34
|
+
key: "org.example.function.sleep",
|
|
35
|
+
name: "Sleep",
|
|
36
|
+
description: "Function that sleeps for a given amount of time"
|
|
37
|
+
},
|
|
38
|
+
input: Schema.Struct({
|
|
39
|
+
duration: Schema.optional(Schema.Number).annotations({
|
|
40
|
+
description: "Milliseconds to sleep",
|
|
41
|
+
default: 1e5
|
|
42
|
+
})
|
|
43
|
+
}),
|
|
44
|
+
output: Schema.Void
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
Fibonacci,
|
|
49
|
+
Reply,
|
|
50
|
+
Sleep
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=chunk-S24LL2D5.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/testing/definitions.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Schema from 'effect/Schema';\n\nimport * as Operation from '../Operation';\n\nexport const Fibonacci = Operation.make({\n meta: {\n key: 'org.example.function.fib',\n name: 'Fibonacci',\n description: 'Function that calculates a Fibonacci number',\n },\n input: Schema.Struct({\n iterations: Schema.optional(Schema.Number).annotations({\n description: 'Number of iterations',\n default: 100_000,\n }),\n }),\n output: Schema.Struct({\n result: Schema.String,\n }),\n});\n\nexport const Reply = Operation.make({\n meta: {\n key: 'org.example.function.reply',\n name: 'Reply',\n description: 'Function that echoes the input',\n },\n input: Schema.Any,\n output: Schema.Any,\n});\n\nexport const Sleep = Operation.make({\n meta: {\n key: 'org.example.function.sleep',\n name: 'Sleep',\n description: 'Function that sleeps for a given amount of time',\n },\n input: Schema.Struct({\n duration: Schema.optional(Schema.Number).annotations({\n description: 'Milliseconds to sleep',\n default: 100_000,\n }),\n }),\n output: Schema.Void,\n});\n"],
|
|
5
|
+
"mappings": ";;;;;AAIA,YAAYA,YAAY;AAIjB,IAAMC,YAAsBC,KAAK;EACtCC,MAAM;IACJC,KAAK;IACLC,MAAM;IACNC,aAAa;EACf;EACAC,OAAcC,cAAO;IACnBC,YAAmBC,gBAAgBC,aAAM,EAAEC,YAAY;MACrDN,aAAa;MACbO,SAAS;IACX,CAAA;EACF,CAAA;EACAC,QAAeN,cAAO;IACpBO,QAAeC;EACjB,CAAA;AACF,CAAA;AAEO,IAAMC,QAAkBf,KAAK;EAClCC,MAAM;IACJC,KAAK;IACLC,MAAM;IACNC,aAAa;EACf;EACAC,OAAcW;EACdJ,QAAeI;AACjB,CAAA;AAEO,IAAMC,QAAkBjB,KAAK;EAClCC,MAAM;IACJC,KAAK;IACLC,MAAM;IACNC,aAAa;EACf;EACAC,OAAcC,cAAO;IACnBY,UAAiBV,gBAAgBC,aAAM,EAAEC,YAAY;MACnDN,aAAa;MACbO,SAAS;IACX,CAAA;EACF,CAAA;EACAC,QAAeO;AACjB,CAAA;",
|
|
6
|
+
"names": ["Schema", "Fibonacci", "make", "meta", "key", "name", "description", "input", "Struct", "iterations", "optional", "Number", "annotations", "default", "output", "result", "String", "Reply", "Any", "Sleep", "duration", "Void"]
|
|
7
|
+
}
|