@dxos/compute 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef
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/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-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 +1034 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- 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 +32 -0
- package/dist/lib/neutral/testing/index.mjs.map +7 -0
- 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 -3
- 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 +27 -39
- 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 -33
- package/src/testing/definitions.ts +49 -0
- package/src/testing/fib.ts +22 -0
- package/src/testing/index.ts +13 -4
- package/src/testing/reply.ts +18 -0
- package/src/testing/sleep.ts +16 -0
- package/src/umbrella.test.ts +51 -0
- package/dist/lib/browser/chunk-XQYPCRZP.mjs +0 -3140
- package/dist/lib/browser/chunk-XQYPCRZP.mjs.map +0 -7
- package/dist/lib/browser/index.mjs +0 -55
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs +0 -186
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-2XWWSGAU.mjs +0 -3142
- package/dist/lib/node-esm/chunk-2XWWSGAU.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -56
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -187
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/compute-graph-registry.d.ts +0 -32
- package/dist/types/src/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/compute-graph.d.ts +0 -64
- 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 -66
- 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/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.ts +0 -88
- package/src/compute-graph.test.ts +0 -88
- package/src/compute-graph.ts +0 -258
- package/src/compute-node.ts +0 -59
- package/src/functions/async-function.ts +0 -183
- package/src/functions/edge-function.ts +0 -111
- 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 -54
- package/src/testing/test-plugin.ts +0 -98
- 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
- /package/dist/lib/{browser/index.mjs.map → neutral/StorageService.mjs.map} +0 -0
- /package/dist/lib/{node-esm/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
1
|
# @dxos/compute
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Umbrella package for AI-aware DXOS compute primitives.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Importing from `@dxos/compute` is equivalent to importing from the underlying
|
|
8
|
+
source packages. Namespaces preserve their nesting — there is no extra wrapping
|
|
9
|
+
or unwrapping:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { Blueprint, Operation, Routine, Process, Script, Trace, Trigger } from '@dxos/compute';
|
|
13
|
+
|
|
14
|
+
Blueprint.make({ /* ... */ });
|
|
15
|
+
Operation.lazy(() => /* ... */);
|
|
16
|
+
Trace.write(Trace.OperationStart, { /* ... */ });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This single surface subsumes:
|
|
20
|
+
|
|
21
|
+
| Re-exported from | Includes |
|
|
22
|
+
| ------------------ | --------------------------------------------------------------- |
|
|
23
|
+
| `@dxos/operation` | `Operation`, `OperationInvoker`, `OperationHandlerSet`, `OperationRegistry`, errors |
|
|
24
|
+
| `@dxos/blueprints` | `Blueprint`, `Routine`, `Template` |
|
|
25
|
+
| `@dxos/functions` | `Process`, `Trigger`, `TriggerEvent`, `Script`, `Trace`, `ServiceResolver`, `StorageService`, `CredentialsService`, `ExampleHandlers`, services, errors, sdk |
|
|
26
|
+
|
|
27
|
+
The HyperFormula-based compute graph that previously lived here moved to
|
|
28
|
+
[`@dxos/compute-hyperformula`](../compute-hyperformula).
|
|
29
|
+
|
|
30
|
+
## Roadmap
|
|
31
|
+
|
|
32
|
+
- Stage 1 (current): re-exports — consumers depend only on `@dxos/compute`
|
|
33
|
+
while the source packages stay in place.
|
|
34
|
+
- Stage 2: migrate source into `@dxos/compute` and remove
|
|
35
|
+
`@dxos/operation`, `@dxos/blueprints`, and `@dxos/functions`.
|
|
36
|
+
- A companion `@dxos/compute-runtime-local` package will host the local
|
|
37
|
+
implementations of the services defined here (currently in
|
|
38
|
+
`@dxos/functions-runtime`).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StorageService,
|
|
3
|
+
clear,
|
|
4
|
+
deleteKey,
|
|
5
|
+
get,
|
|
6
|
+
key,
|
|
7
|
+
list,
|
|
8
|
+
set,
|
|
9
|
+
withDefault
|
|
10
|
+
} from "./chunk-DDEBBRCI.mjs";
|
|
11
|
+
import "./chunk-J5LGTIGS.mjs";
|
|
12
|
+
export {
|
|
13
|
+
StorageService,
|
|
14
|
+
clear,
|
|
15
|
+
deleteKey,
|
|
16
|
+
get,
|
|
17
|
+
key,
|
|
18
|
+
list,
|
|
19
|
+
set,
|
|
20
|
+
withDefault
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=StorageService.mjs.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Sleep
|
|
3
|
+
} from "./chunk-S24LL2D5.mjs";
|
|
4
|
+
import {
|
|
5
|
+
withHandler
|
|
6
|
+
} from "./chunk-QPCDM7MF.mjs";
|
|
7
|
+
|
|
8
|
+
// src/testing/sleep.ts
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
var sleep_default = Sleep.pipe(withHandler(Effect.fn(function* ({ duration = 1e5 }) {
|
|
11
|
+
yield* Effect.sleep(duration);
|
|
12
|
+
})));
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
sleep_default
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=chunk-4N4JAXCP.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/testing/sleep.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport * as Operation from '../Operation';\nimport { Sleep } from './definitions';\n\nexport default Sleep.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ duration = 100_000 }) {\n yield* Effect.sleep(duration);\n }),\n ),\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,YAAYA,YAAY;AAKxB,IAAA,gBAAeC,MAAMC,KACTC,YACDC,UAAG,WAAW,EAAEC,WAAW,IAAO,GAAE;AACzC,SAAcC,aAAMD,QAAAA;AACtB,CAAA,CAAA,CAAA;",
|
|
6
|
+
"names": ["Effect", "Sleep", "pipe", "withHandler", "fn", "duration", "sleep"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
4
|
+
|
|
5
|
+
// src/StorageService.ts
|
|
6
|
+
var StorageService_exports = {};
|
|
7
|
+
__export(StorageService_exports, {
|
|
8
|
+
StorageService: () => StorageService,
|
|
9
|
+
clear: () => clear,
|
|
10
|
+
deleteKey: () => deleteKey,
|
|
11
|
+
get: () => get,
|
|
12
|
+
key: () => key,
|
|
13
|
+
list: () => list,
|
|
14
|
+
set: () => set,
|
|
15
|
+
withDefault: () => withDefault
|
|
16
|
+
});
|
|
17
|
+
import * as Context from "effect/Context";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as Option from "effect/Option";
|
|
20
|
+
import * as Pipeable from "effect/Pipeable";
|
|
21
|
+
var StorageService = class extends Context.Tag("@dxos/functions/StorageService")() {
|
|
22
|
+
};
|
|
23
|
+
var get = Effect.serviceFunctionEffect(StorageService, (_) => _.get);
|
|
24
|
+
var set = Effect.serviceFunctionEffect(StorageService, (_) => _.set);
|
|
25
|
+
var deleteKey = Effect.serviceFunctionEffect(StorageService, (_) => _.delete);
|
|
26
|
+
var list = Effect.serviceFunctionEffect(StorageService, (_) => _.list);
|
|
27
|
+
var clear = Effect.serviceFunctionEffect(StorageService, (_) => _.clear);
|
|
28
|
+
var key = (schema, key2) => {
|
|
29
|
+
return {
|
|
30
|
+
key: key2,
|
|
31
|
+
get: get(schema, key2),
|
|
32
|
+
set: (value) => set(schema, key2, value),
|
|
33
|
+
delete: () => deleteKey(key2),
|
|
34
|
+
pipe(...args) {
|
|
35
|
+
return Pipeable.pipeArguments(this, arguments);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
var withDefault = (getDefault) => (key2) => {
|
|
40
|
+
return {
|
|
41
|
+
key: key2.key,
|
|
42
|
+
get: key2.get.pipe(Effect.map(Option.getOrElse(() => getDefault()))),
|
|
43
|
+
set: (value) => key2.set(value),
|
|
44
|
+
delete: () => key2.delete(),
|
|
45
|
+
pipe(...args) {
|
|
46
|
+
return Pipeable.pipeArguments(this, arguments);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
StorageService,
|
|
53
|
+
get,
|
|
54
|
+
set,
|
|
55
|
+
deleteKey,
|
|
56
|
+
list,
|
|
57
|
+
clear,
|
|
58
|
+
key,
|
|
59
|
+
withDefault,
|
|
60
|
+
StorageService_exports
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=chunk-DDEBBRCI.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/StorageService.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Option from 'effect/Option';\nimport * as Pipeable from 'effect/Pipeable';\nimport * as Schema from 'effect/Schema';\n\nexport interface Service {\n /** Read a value by key. Returns `None` if key does not exist. */\n get<S extends Schema.Schema<any, string, any>>(\n schema: S,\n key: string,\n ): Effect.Effect<Option.Option<Schema.Schema.Type<S>>, never, Schema.Schema.Context<S>>;\n\n /** Write a value for the given key. */\n set<S extends Schema.Schema<any, string, any>>(\n schema: S,\n key: string,\n value: Schema.Schema.Type<S>,\n ): Effect.Effect<void, never, Schema.Schema.Context<S>>;\n\n /** Remove a key. */\n delete(key: string): Effect.Effect<void>;\n\n /** List all keys, optionally filtered by prefix. */\n list(prefix?: string): Effect.Effect<readonly string[]>;\n\n /** Remove all keys managed by this scoped store. */\n clear(): Effect.Effect<void>;\n}\n\n/**\n * Scoped key-value storage service for processes.\n * Each process receives its own namespaced instance via the process manager.\n * Construct a live implementation with `StorageService.layer` from `@dxos/functions-runtime`.\n */\nexport class StorageService extends Context.Tag('@dxos/functions/StorageService')<StorageService, Service>() {}\n\nexport const get = Effect.serviceFunctionEffect(StorageService, (_) => _.get);\nexport const set = Effect.serviceFunctionEffect(StorageService, (_) => _.set);\nexport const deleteKey = Effect.serviceFunctionEffect(StorageService, (_) => _.delete);\nexport const list = Effect.serviceFunctionEffect(StorageService, (_) => _.list);\nexport const clear = Effect.serviceFunctionEffect(StorageService, (_) => _.clear);\n\n/**\n * Typed key in a storage service.\n */\nexport interface Key<T> extends Pipeable.Pipeable {\n readonly key: string;\n\n get: Effect.Effect<Option.Option<T>, never, StorageService>;\n set(value: T): Effect.Effect<void, never, StorageService>;\n delete(): Effect.Effect<void, never, StorageService>;\n}\n\n/**\n * Create a typed key in a storage service.\n */\nexport const key = <S extends Schema.Schema<any, string, any>>(schema: S, key: string): Key<Schema.Schema.Type<S>> => {\n return {\n key,\n get: get(schema, key),\n set: (value: Schema.Schema.Type<S>) => set(schema, key, value),\n delete: () => deleteKey(key),\n pipe(...args: any) {\n return Pipeable.pipeArguments(this, arguments);\n },\n };\n};\n\n/**\n * Typed key in a storage service with a default value.\n */\nexport interface KeyWithDefault<T, U> extends Pipeable.Pipeable {\n readonly key: string;\n get: Effect.Effect<T | U, never, StorageService>;\n set(value: U): Effect.Effect<void, never, StorageService>;\n delete(): Effect.Effect<void, never, StorageService>;\n}\n\n/**\n * Assign a default value to a key if it is not present.\n */\nexport const withDefault =\n <T>(getDefault: () => NoInfer<T>) =>\n (key: Key<T>): KeyWithDefault<T, T> => {\n return {\n key: key.key,\n get: key.get.pipe(Effect.map(Option.getOrElse(() => getDefault()))),\n set: (value) => key.set(value),\n delete: () => key.delete(),\n pipe(...args: any) {\n return Pipeable.pipeArguments(this, arguments);\n },\n };\n };\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA;;;;;;;;;;;AAIA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,YAAY;AACxB,YAAYC,cAAc;AAgCnB,IAAMC,iBAAN,cAAqCC,YAAI,gCAAA,EAAA,EAAA;AAA8D;AAEvG,IAAMC,MAAaC,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEF,GAAG;AACrE,IAAMG,MAAaF,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEC,GAAG;AACrE,IAAMC,YAAmBH,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEG,MAAM;AAC9E,IAAMC,OAAcL,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEI,IAAI;AACvE,IAAMC,QAAeN,6BAAsBH,gBAAgB,CAACI,MAAMA,EAAEK,KAAK;AAgBzE,IAAMC,MAAM,CAA4CC,QAAWD,SAAAA;AACxE,SAAO;IACLA,KAAAA;IACAR,KAAKA,IAAIS,QAAQD,IAAAA;IACjBL,KAAK,CAACO,UAAiCP,IAAIM,QAAQD,MAAKE,KAAAA;IACxDL,QAAQ,MAAMD,UAAUI,IAAAA;IACxBG,QAAQC,MAAS;AACf,aAAgBC,uBAAc,MAAMC,SAAAA;IACtC;EACF;AACF;AAeO,IAAMC,cACX,CAAIC,eACJ,CAACR,SAAAA;AACC,SAAO;IACLA,KAAKA,KAAIA;IACTR,KAAKQ,KAAIR,IAAIW,KAAYM,WAAWC,iBAAU,MAAMF,WAAAA,CAAAA,CAAAA,CAAAA;IACpDb,KAAK,CAACO,UAAUF,KAAIL,IAAIO,KAAAA;IACxBL,QAAQ,MAAMG,KAAIH,OAAM;IACxBM,QAAQC,MAAS;AACf,aAAgBC,uBAAc,MAAMC,SAAAA;IACtC;EACF;AACF;",
|
|
6
|
+
"names": ["Context", "Effect", "Option", "Pipeable", "StorageService", "Tag", "get", "serviceFunctionEffect", "_", "set", "deleteKey", "delete", "list", "clear", "key", "schema", "value", "pipe", "args", "pipeArguments", "arguments", "withDefault", "getDefault", "map", "getOrElse"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Fibonacci
|
|
3
|
+
} from "./chunk-S24LL2D5.mjs";
|
|
4
|
+
import {
|
|
5
|
+
withHandler
|
|
6
|
+
} from "./chunk-QPCDM7MF.mjs";
|
|
7
|
+
|
|
8
|
+
// src/testing/fib.ts
|
|
9
|
+
import * as Effect from "effect/Effect";
|
|
10
|
+
var fib_default = Fibonacci.pipe(withHandler(Effect.fn(function* ({ iterations = 1e5 }) {
|
|
11
|
+
let a = 0n;
|
|
12
|
+
let b = 1n;
|
|
13
|
+
for (let i = 0; i < iterations; i++) {
|
|
14
|
+
a += b;
|
|
15
|
+
b = a - b;
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
result: a.toString()
|
|
19
|
+
};
|
|
20
|
+
})));
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
fib_default
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-FEABF5XY.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/testing/fib.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Effect from 'effect/Effect';\n\nimport * as Operation from '../Operation';\nimport { Fibonacci } from './definitions';\n\nexport default Fibonacci.pipe(\n Operation.withHandler(\n Effect.fn(function* ({ iterations = 100_000 }) {\n let a = 0n;\n let b = 1n;\n for (let i = 0; i < iterations; i++) {\n a += b;\n b = a - b;\n }\n return { result: a.toString() };\n }),\n ),\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,YAAYA,YAAY;AAKxB,IAAA,cAAeC,UAAUC,KACbC,YACDC,UAAG,WAAW,EAAEC,aAAa,IAAO,GAAE;AAC3C,MAAIC,IAAI;AACR,MAAIC,IAAI;AACR,WAASC,IAAI,GAAGA,IAAIH,YAAYG,KAAK;AACnCF,SAAKC;AACLA,QAAID,IAAIC;EACV;AACA,SAAO;IAAEE,QAAQH,EAAEI,SAAQ;EAAG;AAChC,CAAA,CAAA,CAAA;",
|
|
6
|
+
"names": ["Effect", "Fibonacci", "pipe", "withHandler", "fn", "iterations", "a", "b", "i", "result", "toString"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Reply
|
|
3
|
+
} from "./chunk-S24LL2D5.mjs";
|
|
4
|
+
import {
|
|
5
|
+
withHandler
|
|
6
|
+
} from "./chunk-QPCDM7MF.mjs";
|
|
7
|
+
|
|
8
|
+
// src/testing/reply.ts
|
|
9
|
+
import * as Console from "effect/Console";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
var reply_default = Reply.pipe(withHandler(Effect.fn(function* (input) {
|
|
12
|
+
yield* Console.log("reply", {
|
|
13
|
+
input
|
|
14
|
+
});
|
|
15
|
+
return input;
|
|
16
|
+
})));
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
reply_default
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-H6EHIVDN.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/testing/reply.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport * as Console from 'effect/Console';\nimport * as Effect from 'effect/Effect';\n\nimport * as Operation from '../Operation';\nimport { Reply } from './definitions';\n\nexport default Reply.pipe(\n Operation.withHandler(\n Effect.fn(function* (input) {\n yield* Console.log('reply', { input });\n return input;\n }),\n ),\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AAKxB,IAAA,gBAAeC,MAAMC,KACTC,YACDC,UAAG,WAAWC,OAAK;AACxB,SAAeC,YAAI,SAAS;IAAED;EAAM,CAAA;AACpC,SAAOA;AACT,CAAA,CAAA,CAAA;",
|
|
6
|
+
"names": ["Console", "Effect", "Reply", "pipe", "withHandler", "fn", "input", "log"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
4
|
+
|
|
5
|
+
// src/errors.ts
|
|
6
|
+
import { BaseError } from "@dxos/errors";
|
|
7
|
+
var InvokerNotInitializedError = class extends BaseError.extend("InvokerNotInitializedError", "Invoker not initialized") {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var NoHandlerError = class extends BaseError.extend("NoHandlerError", "No handler found for operation. ") {
|
|
13
|
+
constructor(operationKey) {
|
|
14
|
+
super({
|
|
15
|
+
context: {
|
|
16
|
+
operationKey
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var ServiceNotAvailableError = class extends BaseError.extend("ServiceNotAvailable", "Service not available") {
|
|
22
|
+
constructor(service, options) {
|
|
23
|
+
super({
|
|
24
|
+
context: {
|
|
25
|
+
service
|
|
26
|
+
},
|
|
27
|
+
...options,
|
|
28
|
+
message: `Service not available: ${service}`
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var FunctionNotFoundError = class extends BaseError.extend("FunctionNotFound", "Function not found") {
|
|
33
|
+
constructor(functionKey, options) {
|
|
34
|
+
super({
|
|
35
|
+
context: {
|
|
36
|
+
function: functionKey
|
|
37
|
+
},
|
|
38
|
+
...options
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var FunctionError = class extends BaseError.extend("FunctionError", "Function invocation error") {
|
|
43
|
+
};
|
|
44
|
+
var InvalidOperationInputError = class extends BaseError.extend("InvalidOperationInput", "Operation input did not match schema") {
|
|
45
|
+
};
|
|
46
|
+
var InvalidOperationOutputError = class extends BaseError.extend("InvalidOperationOutput", "Operation output did not match schema") {
|
|
47
|
+
};
|
|
48
|
+
var TriggerStateNotFoundError = class extends BaseError.extend("TriggerStateNotFound", "Trigger state not found") {
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/OperationHandlerSet.ts
|
|
52
|
+
var OperationHandlerSet_exports = {};
|
|
53
|
+
__export(OperationHandlerSet_exports, {
|
|
54
|
+
OperationHandlerProvider: () => OperationHandlerProvider,
|
|
55
|
+
TypeId: () => TypeId,
|
|
56
|
+
async: () => async,
|
|
57
|
+
empty: () => empty,
|
|
58
|
+
getHandler: () => getHandler,
|
|
59
|
+
getHandlerByKey: () => getHandlerByKey,
|
|
60
|
+
isOperationHandlerSet: () => isOperationHandlerSet,
|
|
61
|
+
lazy: () => lazy,
|
|
62
|
+
make: () => make,
|
|
63
|
+
merge: () => merge,
|
|
64
|
+
provide: () => provide
|
|
65
|
+
});
|
|
66
|
+
import * as Context from "effect/Context";
|
|
67
|
+
import * as Effect from "effect/Effect";
|
|
68
|
+
import * as Layer from "effect/Layer";
|
|
69
|
+
import { assertArgument } from "@dxos/invariant";
|
|
70
|
+
var TypeId = "~@dxos/operation/OperationHandlerSet";
|
|
71
|
+
var isOperationHandlerSet = (value) => {
|
|
72
|
+
return typeof value === "object" && value !== null && TypeId in value;
|
|
73
|
+
};
|
|
74
|
+
var empty = {
|
|
75
|
+
[TypeId]: TypeId,
|
|
76
|
+
handlers: Effect.succeed([]),
|
|
77
|
+
getHandlers: () => Promise.resolve([])
|
|
78
|
+
};
|
|
79
|
+
var make = (...handlers) => {
|
|
80
|
+
return async(() => Promise.resolve(handlers));
|
|
81
|
+
};
|
|
82
|
+
var async = (getHandlers) => {
|
|
83
|
+
let promise2 = null;
|
|
84
|
+
const getHandlersCached = () => {
|
|
85
|
+
if (!promise2) {
|
|
86
|
+
promise2 = getHandlers();
|
|
87
|
+
}
|
|
88
|
+
return promise2;
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
[TypeId]: TypeId,
|
|
92
|
+
getHandlers,
|
|
93
|
+
handlers: Effect.promise(getHandlersCached)
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
var merge = (...sets) => {
|
|
97
|
+
assertArgument(sets.every(isOperationHandlerSet), "sets", "sets must be an array of OperationHandlerSet");
|
|
98
|
+
return async(() => Promise.all(sets.map((set) => set.getHandlers())).then((handlers) => handlers.flat()));
|
|
99
|
+
};
|
|
100
|
+
var lazy = (...modules) => {
|
|
101
|
+
return async(() => Promise.all(modules.map((module) => module().then(({ default: handler }) => handler))));
|
|
102
|
+
};
|
|
103
|
+
var getHandler = (set, definition) => Effect.gen(function* () {
|
|
104
|
+
const handlers = yield* set.handlers;
|
|
105
|
+
const handler = handlers.find((handler2) => handler2.meta.key === definition.meta.key);
|
|
106
|
+
if (!handler) {
|
|
107
|
+
return yield* Effect.fail(new NoHandlerError(definition.meta.key));
|
|
108
|
+
}
|
|
109
|
+
return handler;
|
|
110
|
+
});
|
|
111
|
+
var getHandlerByKey = (set, key) => Effect.gen(function* () {
|
|
112
|
+
const handlers = yield* set.handlers;
|
|
113
|
+
const handler = handlers.find((handler2) => handler2.meta.key === key);
|
|
114
|
+
if (!handler) {
|
|
115
|
+
return yield* Effect.fail(new NoHandlerError(key));
|
|
116
|
+
}
|
|
117
|
+
return handler;
|
|
118
|
+
});
|
|
119
|
+
var OperationHandlerProvider = class extends Context.Tag("@dxos/operation/OperationHandlerProvider")() {
|
|
120
|
+
};
|
|
121
|
+
var provide = (handlers) => Layer.succeed(OperationHandlerProvider, handlers);
|
|
122
|
+
|
|
123
|
+
export {
|
|
124
|
+
InvokerNotInitializedError,
|
|
125
|
+
NoHandlerError,
|
|
126
|
+
ServiceNotAvailableError,
|
|
127
|
+
FunctionNotFoundError,
|
|
128
|
+
FunctionError,
|
|
129
|
+
InvalidOperationInputError,
|
|
130
|
+
InvalidOperationOutputError,
|
|
131
|
+
TriggerStateNotFoundError,
|
|
132
|
+
lazy,
|
|
133
|
+
getHandler,
|
|
134
|
+
getHandlerByKey,
|
|
135
|
+
OperationHandlerProvider,
|
|
136
|
+
OperationHandlerSet_exports
|
|
137
|
+
};
|
|
138
|
+
//# sourceMappingURL=chunk-N462A6NO.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/errors.ts", "../../../src/OperationHandlerSet.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError, type BaseErrorOptions } from '@dxos/errors';\n\n// Errors from @dxos/operation.\n\nexport class InvokerNotInitializedError extends BaseError.extend(\n 'InvokerNotInitializedError',\n 'Invoker not initialized',\n) {\n constructor() {\n super();\n }\n}\n\nexport class NoHandlerError extends BaseError.extend('NoHandlerError', 'No handler found for operation. ') {\n constructor(operationKey: string) {\n super({ context: { operationKey } });\n }\n}\n\n// Errors from @dxos/functions.\n\nexport class ServiceNotAvailableError extends BaseError.extend('ServiceNotAvailable', 'Service not available') {\n constructor(service: string, options?: Omit<BaseErrorOptions, 'context'>) {\n super({ context: { service }, ...options, message: `Service not available: ${service}` });\n }\n}\n\nexport class FunctionNotFoundError extends BaseError.extend('FunctionNotFound', 'Function not found') {\n constructor(functionKey: string, options?: Omit<BaseErrorOptions, 'context'>) {\n super({ context: { function: functionKey }, ...options });\n }\n}\n\nexport class FunctionError extends BaseError.extend('FunctionError', 'Function invocation error') {}\n\nexport class InvalidOperationInputError extends BaseError.extend(\n 'InvalidOperationInput',\n 'Operation input did not match schema',\n) {}\n\nexport class InvalidOperationOutputError extends BaseError.extend(\n 'InvalidOperationOutput',\n 'Operation output did not match schema',\n) {}\n\nexport class TriggerStateNotFoundError extends BaseError.extend('TriggerStateNotFound', 'Trigger state not found') {}\n", "//\n// Copyright 2026 DXOS.org\n//\n\nimport * as Context from 'effect/Context';\nimport * as Effect from 'effect/Effect';\nimport * as Layer from 'effect/Layer';\n\nimport { assertArgument } from '@dxos/invariant';\n\nimport { NoHandlerError } from './errors';\nimport type * as Operation from './Operation';\n\nexport const TypeId = '~@dxos/operation/OperationHandlerSet' as const;\nexport type TypeId = typeof TypeId;\n\nexport interface OperationHandlerSet {\n [TypeId]: TypeId;\n\n readonly handlers: Effect.Effect<Operation.WithHandler<Operation.Definition.Any>[]>;\n\n getHandlers(): Promise<Operation.WithHandler<Operation.Definition.Any>[]>;\n}\n\nexport const isOperationHandlerSet = (value: unknown): value is OperationHandlerSet => {\n return typeof value === 'object' && value !== null && TypeId in value;\n};\n\nexport const empty: OperationHandlerSet = {\n [TypeId]: TypeId,\n handlers: Effect.succeed([]),\n getHandlers: () => Promise.resolve([]),\n};\n\n/**\n * Creates a new operation handler set from a list of handlers.\n *\n * @example\n * ```ts\n * const set = OperationHandlerSet.make(\n * Operation.withHandler(Operation.make({ input: Schema.Void, output: Schema.Void }), (input) => Effect.succeed({})),\n * Operation.withHandler(Operation.make({ input: Schema.Void, output: Schema.Void }), (input) => Effect.succeed({})),\n * );\n * ```\n */\nexport const make = (...handlers: Operation.WithHandler<Operation.Definition.Any>[]): OperationHandlerSet => {\n return async(() => Promise.resolve(handlers));\n};\n\nexport const async = (\n getHandlers: () => Promise<Operation.WithHandler<Operation.Definition.Any>[]>,\n): OperationHandlerSet => {\n // NOTE: Re-runing async module imports has a big performance penalty in Chrome.\n let promise: Promise<Operation.WithHandler<Operation.Definition.Any>[]> | null = null;\n const getHandlersCached = () => {\n if (!promise) {\n promise = getHandlers();\n }\n return promise;\n };\n return {\n [TypeId]: TypeId,\n getHandlers,\n handlers: Effect.promise(getHandlersCached),\n };\n};\n\n/**\n * Merges multiple operation handler sets into a single set.\n *\n */\nexport const merge = (...sets: OperationHandlerSet[]): OperationHandlerSet => {\n assertArgument(sets.every(isOperationHandlerSet), 'sets', 'sets must be an array of OperationHandlerSet');\n return async(() => Promise.all(sets.map((set) => set.getHandlers())).then((handlers) => handlers.flat()));\n};\n\n/**\n * Creates a new operation handler set from a list of lazy-loaded modules.\n *\n * @example\n * ```ts\n * const set = OperationHandlerSet.lazy(\n * () => import('./my-handler'),\n * () => import('./my-other-handler'),\n * );\n * ```\n */\nexport const lazy = (\n ...modules: (() => Promise<{ default: Operation.WithHandler<Operation.Definition.Any> }>)[]\n): OperationHandlerSet => {\n return async(() => Promise.all(modules.map((module) => module().then(({ default: handler }) => handler))));\n};\n\n/**\n * Gets a handler for an operation by definition.\n */\nexport const getHandler = <const Op extends Operation.Definition.Any>(\n set: OperationHandlerSet,\n definition: Op,\n): Effect.Effect<Operation.WithHandler<Op>, NoHandlerError> =>\n Effect.gen(function* () {\n const handlers = yield* set.handlers;\n const handler = handlers.find((handler) => handler.meta.key === definition.meta.key);\n if (!handler) {\n return yield* Effect.fail(new NoHandlerError(definition.meta.key));\n }\n return handler as any;\n });\n\n/**\n * Gets a handler for an operation by key.\n */\nexport const getHandlerByKey = (\n set: OperationHandlerSet,\n key: string,\n): Effect.Effect<Operation.WithHandler<Operation.Definition.Any>, NoHandlerError> =>\n Effect.gen(function* () {\n const handlers = yield* set.handlers;\n const handler = handlers.find((handler) => handler.meta.key === key);\n if (!handler) {\n return yield* Effect.fail(new NoHandlerError(key));\n }\n return handler as any;\n });\n\nexport class OperationHandlerProvider extends Context.Tag('@dxos/operation/OperationHandlerProvider')<\n OperationHandlerProvider,\n OperationHandlerSet\n>() {}\n\nexport const provide = (handlers: OperationHandlerSet): Layer.Layer<OperationHandlerProvider, never, never> =>\n Layer.succeed(OperationHandlerProvider, handlers);\n"],
|
|
5
|
+
"mappings": ";;;;;AAIA,SAASA,iBAAwC;AAI1C,IAAMC,6BAAN,cAAyCD,UAAUE,OACxD,8BACA,yBAAA,EAAA;EAEA,cAAc;AACZ,UAAK;EACP;AACF;AAEO,IAAMC,iBAAN,cAA6BH,UAAUE,OAAO,kBAAkB,kCAAA,EAAA;EACrE,YAAYE,cAAsB;AAChC,UAAM;MAAEC,SAAS;QAAED;MAAa;IAAE,CAAA;EACpC;AACF;AAIO,IAAME,2BAAN,cAAuCN,UAAUE,OAAO,uBAAuB,uBAAA,EAAA;EACpF,YAAYK,SAAiBC,SAA6C;AACxE,UAAM;MAAEH,SAAS;QAAEE;MAAQ;MAAG,GAAGC;MAASC,SAAS,0BAA0BF,OAAAA;IAAU,CAAA;EACzF;AACF;AAEO,IAAMG,wBAAN,cAAoCV,UAAUE,OAAO,oBAAoB,oBAAA,EAAA;EAC9E,YAAYS,aAAqBH,SAA6C;AAC5E,UAAM;MAAEH,SAAS;QAAEO,UAAUD;MAAY;MAAG,GAAGH;IAAQ,CAAA;EACzD;AACF;AAEO,IAAMK,gBAAN,cAA4Bb,UAAUE,OAAO,iBAAiB,2BAAA,EAAA;AAA8B;AAE5F,IAAMY,6BAAN,cAAyCd,UAAUE,OACxD,yBACA,sCAAA,EAAA;AACC;AAEI,IAAMa,8BAAN,cAA0Cf,UAAUE,OACzD,0BACA,uCAAA,EAAA;AACC;AAEI,IAAMc,4BAAN,cAAwChB,UAAUE,OAAO,wBAAwB,yBAAA,EAAA;AAA4B;;;ACjDpH;;;;;;;;;;;;;;AAIA,YAAYe,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,WAAW;AAEvB,SAASC,sBAAsB;AAKxB,IAAMC,SAAS;AAWf,IAAMC,wBA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AAA;EAClE;AACA,SAAON;AACT,CAAA;AAKK,IAAMS,kBAAkB,CAC7BhB,KACAa,QAEOH,WAAI,aAAA;AACT,QAAMzB,WAAW,OAAOe,IAAIf;AAC5B,QAAMsB,UAAUtB,SAAS0B,KAAK,CAACJ,aAAYA,SAAQK,KAAKC,QAAQA,GAAAA;AAChE,MAAI,CAACN,SAAS;AACZ,WAAO,OAAcO,YAAK,IAAIC,eAAeF,GAAAA,CAAAA;EAC/C;AACA,SAAON;AACT,CAAA;AAEK,IAAMU,2BAAN,cAA+CC,YAAI,0CAAA,EAAA,EAAA;AAGrD;AAEE,IAAMC,UAAU,CAAClC,aAChBC,cAAQ+B,0BAA0BhC,QAAAA;",
|
|
6
|
+
"names": ["BaseError", "InvokerNotInitializedError", "extend", "NoHandlerError", "operationKey", "context", "ServiceNotAvailableError", "service", "options", "message", "FunctionNotFoundError", "functionKey", "function", "FunctionError", "InvalidOperationInputError", "InvalidOperationOutputError", "TriggerStateNotFoundError", "Context", "Effect", "Layer", "assertArgument", "TypeId", "isOperationHandlerSet", "value", "empty", "handlers", "succeed", "getHandlers", "Promise", "resolve", "make", "async", "promise", "getHandlersCached", "merge", "sets", "assertArgument", "every", "all", "map", "set", "then", "flat", "lazy", "modules", "module", "default", "handler", "getHandler", "definition", "gen", "find", "meta", "key", "fail", "NoHandlerError", "getHandlerByKey", "OperationHandlerProvider", "Tag", "provide"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-J5LGTIGS.mjs";
|
|
4
|
+
|
|
5
|
+
// src/Operation.ts
|
|
6
|
+
var Operation_exports = {};
|
|
7
|
+
__export(Operation_exports, {
|
|
8
|
+
DefinitionTypeId: () => DefinitionTypeId,
|
|
9
|
+
PersistentOperation: () => PersistentOperation,
|
|
10
|
+
Service: () => Service,
|
|
11
|
+
deserialize: () => deserialize,
|
|
12
|
+
invoke: () => invoke,
|
|
13
|
+
isOperationDefinition: () => isOperationDefinition,
|
|
14
|
+
isOperationWithHandler: () => isOperationWithHandler,
|
|
15
|
+
make: () => make,
|
|
16
|
+
opaqueHandler: () => opaqueHandler,
|
|
17
|
+
schedule: () => schedule,
|
|
18
|
+
serialize: () => serialize,
|
|
19
|
+
setFrom: () => setFrom,
|
|
20
|
+
withHandler: () => withHandler,
|
|
21
|
+
withInvocationOptions: () => withInvocationOptions
|
|
22
|
+
});
|
|
23
|
+
import * as Context from "effect/Context";
|
|
24
|
+
import * as Effect from "effect/Effect";
|
|
25
|
+
import * as Layer from "effect/Layer";
|
|
26
|
+
import * as Pipeable from "effect/Pipeable";
|
|
27
|
+
import * as Schema$ from "effect/Schema";
|
|
28
|
+
import { Annotation, JsonSchema, Obj, Ref, Type } from "@dxos/echo";
|
|
29
|
+
var DefinitionTypeId = "~@dxos/operation/OperationDefinition";
|
|
30
|
+
var isOperationDefinition = (value) => {
|
|
31
|
+
return typeof value === "object" && value !== null && DefinitionTypeId in value;
|
|
32
|
+
};
|
|
33
|
+
var isOperationWithHandler = (value) => {
|
|
34
|
+
return isOperationDefinition(value) && "handler" in value;
|
|
35
|
+
};
|
|
36
|
+
var make = (props) => {
|
|
37
|
+
return {
|
|
38
|
+
[DefinitionTypeId]: {},
|
|
39
|
+
...props,
|
|
40
|
+
executionMode: props.executionMode ?? "async",
|
|
41
|
+
types: props.types ?? [],
|
|
42
|
+
services: props.services ?? [],
|
|
43
|
+
pipe() {
|
|
44
|
+
return Pipeable.pipeArguments(this, arguments);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var withHandler = (opOrHandler, handler) => {
|
|
49
|
+
if (handler === void 0) {
|
|
50
|
+
const handlerFn = opOrHandler;
|
|
51
|
+
return (op2) => ({
|
|
52
|
+
...op2,
|
|
53
|
+
handler: handlerFn
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const op = opOrHandler;
|
|
57
|
+
return {
|
|
58
|
+
...op,
|
|
59
|
+
handler
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
var opaqueHandler = (handler) => handler;
|
|
63
|
+
var PersistentOperation = Schema$.Struct({
|
|
64
|
+
/**
|
|
65
|
+
* Global registry ID.
|
|
66
|
+
* NOTE: The `key` property refers to the original registry entry.
|
|
67
|
+
*/
|
|
68
|
+
// TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.
|
|
69
|
+
// TODO(dmaretskyi): Consider making it part of ECHO meta.
|
|
70
|
+
// TODO(dmaretskyi): Make required.
|
|
71
|
+
key: Schema$.optional(Schema$.String).annotations({
|
|
72
|
+
description: "Unique registration key for the blueprint"
|
|
73
|
+
}),
|
|
74
|
+
name: Schema$.NonEmptyString,
|
|
75
|
+
version: Schema$.String,
|
|
76
|
+
description: Schema$.optional(Schema$.String),
|
|
77
|
+
/**
|
|
78
|
+
* ISO date string of the last deployment.
|
|
79
|
+
*/
|
|
80
|
+
updated: Schema$.optional(Schema$.String),
|
|
81
|
+
// Reference to a source script if it exists within ECHO.
|
|
82
|
+
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
83
|
+
source: Schema$.optional(Ref.Ref(Obj.Unknown)),
|
|
84
|
+
inputSchema: Schema$.optional(JsonSchema.JsonSchema),
|
|
85
|
+
outputSchema: Schema$.optional(JsonSchema.JsonSchema),
|
|
86
|
+
/**
|
|
87
|
+
* List of required services.
|
|
88
|
+
* Match the Context.Tag keys of the FunctionServices variants.
|
|
89
|
+
*/
|
|
90
|
+
services: Schema$.optional(Schema$.Array(Schema$.String)),
|
|
91
|
+
// Local binding to a function name.
|
|
92
|
+
// TODO(dmaretskyi): Add this field to Operation.Definition.
|
|
93
|
+
binding: Schema$.optional(Schema$.String)
|
|
94
|
+
}).pipe(
|
|
95
|
+
// TODO(dmaretskyi): Keep typename as 'org.dxos.type.function' (not 'operation') to maintain
|
|
96
|
+
// backward compatibility with existing data and avoid requiring data migration.
|
|
97
|
+
Type.object({
|
|
98
|
+
typename: "org.dxos.type.function",
|
|
99
|
+
version: "0.1.0"
|
|
100
|
+
}),
|
|
101
|
+
Annotation.LabelAnnotation.set([
|
|
102
|
+
"name"
|
|
103
|
+
]),
|
|
104
|
+
Annotation.IconAnnotation.set({
|
|
105
|
+
icon: "ph--function--regular",
|
|
106
|
+
hue: "blue"
|
|
107
|
+
}),
|
|
108
|
+
Annotation.SystemTypeAnnotation.set(true)
|
|
109
|
+
);
|
|
110
|
+
var serialize = (operation) => {
|
|
111
|
+
return Obj.make(PersistentOperation, {
|
|
112
|
+
key: operation.meta.key,
|
|
113
|
+
name: operation.meta.name ?? "",
|
|
114
|
+
version: operation.meta.version ?? "0.0.0",
|
|
115
|
+
description: operation.meta.description,
|
|
116
|
+
updated: void 0,
|
|
117
|
+
source: void 0,
|
|
118
|
+
inputSchema: JsonSchema.toJsonSchema(operation.input),
|
|
119
|
+
outputSchema: JsonSchema.toJsonSchema(operation.output),
|
|
120
|
+
services: operation.services.map((service) => service.key)
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
var deserialize = (record) => {
|
|
124
|
+
const deployedId = Obj.getMeta(record).keys.find((key) => key.source === "org.dxos.service.function")?.id;
|
|
125
|
+
return make({
|
|
126
|
+
input: record.inputSchema ? JsonSchema.toEffectSchema(record.inputSchema) : Schema$.Unknown,
|
|
127
|
+
output: record.outputSchema ? JsonSchema.toEffectSchema(record.outputSchema) : Schema$.Unknown,
|
|
128
|
+
services: record.services?.map((service) => Context.GenericTag(service)) ?? [],
|
|
129
|
+
executionMode: "async",
|
|
130
|
+
types: [],
|
|
131
|
+
meta: {
|
|
132
|
+
key: record.key ?? record.name,
|
|
133
|
+
name: record.name,
|
|
134
|
+
version: record.version,
|
|
135
|
+
description: record.description,
|
|
136
|
+
deployedId
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
var setFrom = (target, source) => {
|
|
141
|
+
Obj.update(target, (target2) => {
|
|
142
|
+
target2.key = source.key ?? target2.key;
|
|
143
|
+
target2.name = source.name ?? target2.name;
|
|
144
|
+
target2.version = source.version;
|
|
145
|
+
target2.description = source.description;
|
|
146
|
+
target2.updated = source.updated;
|
|
147
|
+
target2.inputSchema = source.inputSchema ? JSON.parse(JSON.stringify(source.inputSchema)) : void 0;
|
|
148
|
+
target2.outputSchema = source.outputSchema ? JSON.parse(JSON.stringify(source.outputSchema)) : void 0;
|
|
149
|
+
Obj.getMeta(target2).keys = JSON.parse(JSON.stringify(Obj.getMeta(source).keys));
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
var Service = class extends Context.Tag("@dxos/operation/Service")() {
|
|
153
|
+
};
|
|
154
|
+
var invoke = (op, ...args) => Effect.flatMap(Service, (ops) => ops.invoke(op, ...args)).pipe(Effect.withSpan("Operation.invoke"));
|
|
155
|
+
var schedule = (op, ...args) => Effect.flatMap(Service, (ops) => ops.schedule(op, args[0])).pipe(Effect.withSpan("Operation.schedule"));
|
|
156
|
+
var withInvocationOptions = (options) => Layer.effect(Service, Effect.gen(function* () {
|
|
157
|
+
const service = yield* Service;
|
|
158
|
+
return Service.of({
|
|
159
|
+
invoke: (op, input, invocationOptions) => service.invoke(op, input, {
|
|
160
|
+
...options,
|
|
161
|
+
...invocationOptions
|
|
162
|
+
}),
|
|
163
|
+
invokePromise: (op, input, invocationOptions) => service.invokePromise(op, input, {
|
|
164
|
+
...options,
|
|
165
|
+
...invocationOptions
|
|
166
|
+
}),
|
|
167
|
+
schedule: service.schedule
|
|
168
|
+
});
|
|
169
|
+
}));
|
|
170
|
+
|
|
171
|
+
export {
|
|
172
|
+
make,
|
|
173
|
+
withHandler,
|
|
174
|
+
PersistentOperation,
|
|
175
|
+
deserialize,
|
|
176
|
+
invoke,
|
|
177
|
+
Operation_exports
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=chunk-QPCDM7MF.mjs.map
|
|
@@ -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;AAC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AQkB,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
|
+
}
|