@dxos/compute 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc
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/LICENSE +102 -5
- package/README.md +36 -1
- package/dist/lib/neutral/StorageService.mjs +22 -0
- package/dist/lib/neutral/chunk-AKVCVI6N.mjs +25 -0
- package/dist/lib/neutral/chunk-AKVCVI6N.mjs.map +7 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-JTZYM2QW.mjs +144 -0
- package/dist/lib/neutral/chunk-JTZYM2QW.mjs.map +7 -0
- package/dist/lib/neutral/chunk-LRCABAWU.mjs +17 -0
- package/dist/lib/neutral/chunk-LRCABAWU.mjs.map +7 -0
- package/dist/lib/neutral/chunk-RCLYF66G.mjs +21 -0
- package/dist/lib/neutral/chunk-RCLYF66G.mjs.map +7 -0
- package/dist/lib/neutral/chunk-SEBWOTOU.mjs +235 -0
- package/dist/lib/neutral/chunk-SEBWOTOU.mjs.map +7 -0
- package/dist/lib/neutral/chunk-VSICPGGY.mjs +53 -0
- package/dist/lib/neutral/chunk-VSICPGGY.mjs.map +7 -0
- package/dist/lib/neutral/chunk-XEVFBI6S.mjs +62 -0
- package/dist/lib/neutral/chunk-XEVFBI6S.mjs.map +7 -0
- package/dist/lib/neutral/fib-ZSJYREBW.mjs +10 -0
- package/dist/lib/neutral/fib-ZSJYREBW.mjs.map +7 -0
- package/dist/lib/neutral/index.mjs +1146 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/reply-YH3BVOUT.mjs +10 -0
- package/dist/lib/neutral/reply-YH3BVOUT.mjs.map +7 -0
- package/dist/lib/neutral/sleep-TSPIQ5EY.mjs +10 -0
- package/dist/lib/neutral/sleep-TSPIQ5EY.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 +192 -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/McpServer.d.ts +27 -0
- package/dist/types/src/McpServer.d.ts.map +1 -0
- package/dist/types/src/Operation.d.ts +340 -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 +63 -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 +62 -0
- package/dist/types/src/Template.d.ts.map +1 -0
- package/dist/types/src/Template.test.d.ts +2 -0
- package/dist/types/src/Template.test.d.ts.map +1 -0
- package/dist/types/src/Trace.d.ts +216 -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 +308 -0
- package/dist/types/src/errors.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +16 -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 +28 -40
- package/src/Blueprint.ts +303 -0
- package/src/Credential.ts +53 -0
- package/src/McpServer.ts +44 -0
- package/src/Operation.ts +593 -0
- package/src/OperationHandlerSet.ts +134 -0
- package/src/OperationRegistry.ts +50 -0
- package/src/Process.ts +490 -0
- package/src/Routine.ts +75 -0
- package/src/Script.ts +40 -0
- package/src/ServiceResolver.ts +174 -0
- package/src/StorageService.ts +101 -0
- package/src/Template.test.ts +151 -0
- package/src/Template.ts +122 -0
- package/src/Trace.ts +283 -0
- package/src/Trigger.ts +209 -0
- package/src/TriggerEvent.ts +64 -0
- package/src/errors.ts +71 -0
- package/src/index.ts +18 -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/browser/chunk-CY35BVJC.mjs +0 -3113
- package/dist/lib/browser/chunk-CY35BVJC.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 -196
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BECNONV7.mjs +0 -3115
- package/dist/lib/node-esm/chunk-BECNONV7.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 -197
- package/dist/lib/node-esm/testing/index.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 -138
- package/src/compute-graph-registry.ts +0 -97
- package/src/compute-graph.test.ts +0 -87
- package/src/compute-graph.ts +0 -266
- package/src/compute-node.ts +0 -59
- package/src/functions/async-function.ts +0 -184
- package/src/functions/edge-function.ts +0 -114
- 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 -38
- 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
|
@@ -0,0 +1,235 @@
|
|
|
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
|
+
PersistentOperation_v0_1_0: () => PersistentOperation_v0_1_0,
|
|
11
|
+
Service: () => Service,
|
|
12
|
+
deserialize: () => deserialize,
|
|
13
|
+
getKey: () => getKey,
|
|
14
|
+
getVersion: () => getVersion,
|
|
15
|
+
intrinsic: () => intrinsic,
|
|
16
|
+
invoke: () => invoke,
|
|
17
|
+
isOperationDefinition: () => isOperationDefinition,
|
|
18
|
+
isOperationWithHandler: () => isOperationWithHandler,
|
|
19
|
+
make: () => make,
|
|
20
|
+
migrations: () => migrations,
|
|
21
|
+
opaqueHandler: () => opaqueHandler,
|
|
22
|
+
schedule: () => schedule,
|
|
23
|
+
serialize: () => serialize,
|
|
24
|
+
setFrom: () => setFrom,
|
|
25
|
+
withHandler: () => withHandler,
|
|
26
|
+
withInvocationOptions: () => withInvocationOptions
|
|
27
|
+
});
|
|
28
|
+
import * as Context from "effect/Context";
|
|
29
|
+
import * as Effect from "effect/Effect";
|
|
30
|
+
import * as Layer from "effect/Layer";
|
|
31
|
+
import * as Pipeable from "effect/Pipeable";
|
|
32
|
+
import * as Schema$ from "effect/Schema";
|
|
33
|
+
import { Annotation, JsonSchema, Migration, Obj, Ref, Type } from "@dxos/echo";
|
|
34
|
+
var DefinitionTypeId = "~@dxos/operation/OperationDefinition";
|
|
35
|
+
var isOperationDefinition = (value) => {
|
|
36
|
+
return typeof value === "object" && value !== null && DefinitionTypeId in value;
|
|
37
|
+
};
|
|
38
|
+
var isOperationWithHandler = (value) => {
|
|
39
|
+
return isOperationDefinition(value) && "handler" in value;
|
|
40
|
+
};
|
|
41
|
+
var make = (props) => {
|
|
42
|
+
return {
|
|
43
|
+
[DefinitionTypeId]: {},
|
|
44
|
+
...props,
|
|
45
|
+
executionMode: props.executionMode ?? "async",
|
|
46
|
+
types: props.types ?? [],
|
|
47
|
+
services: props.services ?? [],
|
|
48
|
+
pipe() {
|
|
49
|
+
return Pipeable.pipeArguments(this, arguments);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
var intrinsic = (op) => {
|
|
54
|
+
return {
|
|
55
|
+
...op,
|
|
56
|
+
meta: {
|
|
57
|
+
...op.meta,
|
|
58
|
+
deployedId: `intrinsic:${op.meta.key}`
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
var withHandler = (opOrHandler, handler) => {
|
|
63
|
+
if (handler === void 0) {
|
|
64
|
+
const handlerFn = opOrHandler;
|
|
65
|
+
return (op2) => ({
|
|
66
|
+
...op2,
|
|
67
|
+
handler: handlerFn
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const op = opOrHandler;
|
|
71
|
+
return {
|
|
72
|
+
...op,
|
|
73
|
+
handler
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var opaqueHandler = (handler) => handler;
|
|
77
|
+
var PersistentOperation = Schema$.Struct({
|
|
78
|
+
name: Schema$.NonEmptyString,
|
|
79
|
+
description: Schema$.optional(Schema$.String),
|
|
80
|
+
/**
|
|
81
|
+
* ISO date string of the last deployment.
|
|
82
|
+
*/
|
|
83
|
+
updated: Schema$.optional(Schema$.String),
|
|
84
|
+
// Reference to a source script if it exists within ECHO.
|
|
85
|
+
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
86
|
+
source: Schema$.optional(Ref.Ref(Obj.Unknown)),
|
|
87
|
+
inputSchema: Schema$.optional(JsonSchema.JsonSchema),
|
|
88
|
+
outputSchema: Schema$.optional(JsonSchema.JsonSchema),
|
|
89
|
+
/**
|
|
90
|
+
* List of required services.
|
|
91
|
+
* Match the Context.Tag keys of the FunctionServices variants.
|
|
92
|
+
*/
|
|
93
|
+
services: Schema$.optional(Schema$.Array(Schema$.String)),
|
|
94
|
+
// Local binding to a function name.
|
|
95
|
+
// TODO(dmaretskyi): Add this field to Operation.Definition.
|
|
96
|
+
binding: Schema$.optional(Schema$.String)
|
|
97
|
+
}).pipe(
|
|
98
|
+
// TODO(dmaretskyi): Keep typename as 'org.dxos.type.function' (not 'operation') to maintain
|
|
99
|
+
// backward compatibility with existing data and avoid requiring data migration.
|
|
100
|
+
Type.object({
|
|
101
|
+
typename: "org.dxos.type.function",
|
|
102
|
+
version: "0.2.0"
|
|
103
|
+
}),
|
|
104
|
+
Annotation.LabelAnnotation.set([
|
|
105
|
+
"name"
|
|
106
|
+
]),
|
|
107
|
+
Annotation.IconAnnotation.set({
|
|
108
|
+
icon: "ph--function--regular",
|
|
109
|
+
hue: "blue"
|
|
110
|
+
}),
|
|
111
|
+
Annotation.SystemTypeAnnotation.set(true)
|
|
112
|
+
);
|
|
113
|
+
var FUNCTION_META_KEY = "org.dxos.service.function";
|
|
114
|
+
var getKey = (record) => Obj.getMeta(record).key;
|
|
115
|
+
var getVersion = (record) => Obj.getMeta(record).version;
|
|
116
|
+
var serialize = (operation) => {
|
|
117
|
+
return Obj.make(PersistentOperation, {
|
|
118
|
+
[Obj.Meta]: {
|
|
119
|
+
key: operation.meta.key,
|
|
120
|
+
version: operation.meta.version ?? "0.0.0",
|
|
121
|
+
keys: operation.meta.deployedId ? [
|
|
122
|
+
{
|
|
123
|
+
source: FUNCTION_META_KEY,
|
|
124
|
+
id: operation.meta.deployedId
|
|
125
|
+
}
|
|
126
|
+
] : []
|
|
127
|
+
},
|
|
128
|
+
name: operation.meta.name ?? "",
|
|
129
|
+
description: operation.meta.description,
|
|
130
|
+
updated: void 0,
|
|
131
|
+
source: void 0,
|
|
132
|
+
inputSchema: JsonSchema.toJsonSchema(operation.input),
|
|
133
|
+
outputSchema: JsonSchema.toJsonSchema(operation.output),
|
|
134
|
+
services: operation.services.map((service) => service.key)
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
var deserialize = (record) => {
|
|
138
|
+
const meta = Obj.getMeta(record);
|
|
139
|
+
const deployedId = meta.keys.find((key) => key.source === FUNCTION_META_KEY)?.id;
|
|
140
|
+
return make({
|
|
141
|
+
input: record.inputSchema ? JsonSchema.toEffectSchema(record.inputSchema) : Schema$.Unknown,
|
|
142
|
+
output: record.outputSchema ? JsonSchema.toEffectSchema(record.outputSchema) : Schema$.Unknown,
|
|
143
|
+
services: record.services?.map((service) => Context.GenericTag(service)) ?? [],
|
|
144
|
+
executionMode: "async",
|
|
145
|
+
types: [],
|
|
146
|
+
meta: {
|
|
147
|
+
key: meta.key ?? record.name,
|
|
148
|
+
name: record.name,
|
|
149
|
+
version: meta.version ?? "0.0.0",
|
|
150
|
+
description: record.description,
|
|
151
|
+
deployedId
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
var setFrom = (target, source) => {
|
|
156
|
+
Obj.update(target, (target2) => {
|
|
157
|
+
target2.name = source.name ?? target2.name;
|
|
158
|
+
target2.description = source.description;
|
|
159
|
+
target2.updated = source.updated;
|
|
160
|
+
target2.inputSchema = source.inputSchema ? JSON.parse(JSON.stringify(source.inputSchema)) : void 0;
|
|
161
|
+
target2.outputSchema = source.outputSchema ? JSON.parse(JSON.stringify(source.outputSchema)) : void 0;
|
|
162
|
+
const sourceMeta = Obj.getMeta(source);
|
|
163
|
+
const targetMeta = Obj.getMeta(target2);
|
|
164
|
+
targetMeta.key = sourceMeta.key ?? targetMeta.key;
|
|
165
|
+
targetMeta.version = sourceMeta.version;
|
|
166
|
+
if (sourceMeta.keys.length > 0) {
|
|
167
|
+
targetMeta.keys = JSON.parse(JSON.stringify(sourceMeta.keys));
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
var Service = class extends Context.Tag("@dxos/operation/Service")() {
|
|
172
|
+
};
|
|
173
|
+
var invoke = (op, ...args) => Effect.flatMap(Service, (ops) => ops.invoke(op, ...args)).pipe(Effect.withSpan("Operation.invoke"));
|
|
174
|
+
var schedule = (op, ...args) => Effect.flatMap(Service, (ops) => ops.schedule(op, args[0])).pipe(Effect.withSpan("Operation.schedule"));
|
|
175
|
+
var withInvocationOptions = (options) => Layer.effect(Service, Effect.gen(function* () {
|
|
176
|
+
const service = yield* Service;
|
|
177
|
+
return Service.of({
|
|
178
|
+
invoke: (op, input, invocationOptions) => service.invoke(op, input, {
|
|
179
|
+
...options,
|
|
180
|
+
...invocationOptions
|
|
181
|
+
}),
|
|
182
|
+
invokePromise: (op, input, invocationOptions) => service.invokePromise(op, input, {
|
|
183
|
+
...options,
|
|
184
|
+
...invocationOptions
|
|
185
|
+
}),
|
|
186
|
+
schedule: service.schedule
|
|
187
|
+
});
|
|
188
|
+
}));
|
|
189
|
+
var PersistentOperation_v0_1_0 = Schema$.Struct({
|
|
190
|
+
key: Schema$.optional(Schema$.String),
|
|
191
|
+
name: Schema$.NonEmptyString,
|
|
192
|
+
version: Schema$.String,
|
|
193
|
+
description: Schema$.optional(Schema$.String),
|
|
194
|
+
updated: Schema$.optional(Schema$.String),
|
|
195
|
+
source: Schema$.optional(Ref.Ref(Obj.Unknown)),
|
|
196
|
+
inputSchema: Schema$.optional(JsonSchema.JsonSchema),
|
|
197
|
+
outputSchema: Schema$.optional(JsonSchema.JsonSchema),
|
|
198
|
+
services: Schema$.optional(Schema$.Array(Schema$.String)),
|
|
199
|
+
binding: Schema$.optional(Schema$.String)
|
|
200
|
+
}).pipe(Type.object({
|
|
201
|
+
typename: "org.dxos.type.function",
|
|
202
|
+
version: "0.1.0"
|
|
203
|
+
}));
|
|
204
|
+
var _migration = Migration.define({
|
|
205
|
+
from: PersistentOperation_v0_1_0,
|
|
206
|
+
to: PersistentOperation,
|
|
207
|
+
transform: async (from) => ({
|
|
208
|
+
[Obj.Meta]: {
|
|
209
|
+
key: from.key,
|
|
210
|
+
version: from.version
|
|
211
|
+
},
|
|
212
|
+
name: from.name,
|
|
213
|
+
description: from.description,
|
|
214
|
+
updated: from.updated,
|
|
215
|
+
source: from.source,
|
|
216
|
+
inputSchema: from.inputSchema,
|
|
217
|
+
outputSchema: from.outputSchema,
|
|
218
|
+
services: from.services,
|
|
219
|
+
binding: from.binding
|
|
220
|
+
})
|
|
221
|
+
});
|
|
222
|
+
var migrations = [
|
|
223
|
+
_migration
|
|
224
|
+
];
|
|
225
|
+
|
|
226
|
+
export {
|
|
227
|
+
make,
|
|
228
|
+
intrinsic,
|
|
229
|
+
withHandler,
|
|
230
|
+
PersistentOperation,
|
|
231
|
+
deserialize,
|
|
232
|
+
invoke,
|
|
233
|
+
Operation_exports
|
|
234
|
+
};
|
|
235
|
+
//# sourceMappingURL=chunk-SEBWOTOU.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Operation.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @import-as-namespace\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, Migration, Obj, Ref, Type, type DXN, type Key } from '@dxos/echo';\n\nimport type { NoHandlerError } from './errors';\nimport type { Operation } from './index';\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 * Marks an operation as intrinsic — provided directly by the DXOS platform runtime rather than\n * deployed as a user function. The `intrinsic:<key>` deployedId routes invocations to the\n * built-in implementation registered with the runtime.\n */\nexport const intrinsic = <const O extends Operation.Definition.Any>(op: O): O => {\n return {\n ...op,\n meta: {\n ...op.meta,\n deployedId: `intrinsic:${op.meta.key}`,\n },\n };\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 * The registry `key` and `version` live in the object meta — access via\n * `Obj.getMeta(record).key` and `Obj.getMeta(record).version`.\n */\nexport const PersistentOperation = Schema$.Struct({\n name: Schema$.NonEmptyString,\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.2.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\nconst FUNCTION_META_KEY = 'org.dxos.service.function';\n\n/**\n * Get the registry key for a persistent operation record (from the object meta).\n */\nexport const getKey = (record: PersistentOperation): string | undefined => Obj.getMeta(record).key;\n\n/**\n * Get the registry version for a persistent operation record (from the object meta).\n */\nexport const getVersion = (record: PersistentOperation): string | undefined => Obj.getMeta(record).version;\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 [Obj.Meta]: {\n key: operation.meta.key,\n version: operation.meta.version ?? '0.0.0',\n keys: operation.meta.deployedId ? [{ source: FUNCTION_META_KEY, id: operation.meta.deployedId }] : [],\n },\n name: operation.meta.name ?? '',\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 const meta = Obj.getMeta(record);\n // Extract deployed function ID from ECHO meta keys (matches FUNCTIONS_META_KEY in @dxos/functions).\n const deployedId = meta.keys.find((key) => key.source === FUNCTION_META_KEY)?.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: meta.key ?? record.name,\n name: record.name,\n version: meta.version ?? '0.0.0',\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.name = source.name ?? target.name;\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 const sourceMeta = Obj.getMeta(source);\n const targetMeta = Obj.getMeta(target);\n targetMeta.key = sourceMeta.key ?? targetMeta.key;\n targetMeta.version = sourceMeta.version;\n // Only overwrite foreign keys when the source actually carries them; otherwise we'd wipe\n // bindings (e.g. the deployedId set by `deserialize`) on records produced by `serialize`.\n if (sourceMeta.keys.length > 0) {\n targetMeta.keys = JSON.parse(JSON.stringify(sourceMeta.keys));\n }\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 AiContext.Service 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\n//\n// Legacy schemas and migrations.\n//\n\n/**\n * Persistent operation schema v0.1.0 — `key` and `version` are stored as data properties.\n * @deprecated Use {@link PersistentOperation} (v0.2.0) instead; the `key` and `version` now live in the object meta.\n */\nexport const PersistentOperation_v0_1_0 = Schema$.Struct({\n key: Schema$.optional(Schema$.String),\n name: Schema$.NonEmptyString,\n version: Schema$.String,\n description: Schema$.optional(Schema$.String),\n updated: Schema$.optional(Schema$.String),\n source: Schema$.optional(Ref.Ref(Obj.Unknown)),\n inputSchema: Schema$.optional(JsonSchema.JsonSchema),\n outputSchema: Schema$.optional(JsonSchema.JsonSchema),\n services: Schema$.optional(Schema$.Array(Schema$.String)),\n binding: Schema$.optional(Schema$.String),\n}).pipe(\n Type.object({\n typename: 'org.dxos.type.function',\n version: '0.1.0',\n }),\n);\nexport interface PersistentOperation_v0_1_0 extends Schema$.Schema.Type<typeof PersistentOperation_v0_1_0> {}\n\n/**\n * Migration from {@link PersistentOperation_v0_1_0} (v0.1.0) to {@link PersistentOperation} (v0.2.0).\n * Moves `key` and `version` from the data section into the object meta.\n */\nconst _migration = Migration.define({\n from: PersistentOperation_v0_1_0,\n to: PersistentOperation,\n transform: async (from) => ({\n [Obj.Meta]: { key: from.key, version: from.version },\n name: from.name,\n description: from.description,\n updated: from.updated,\n source: from.source as any,\n inputSchema: from.inputSchema,\n outputSchema: from.outputSchema,\n services: from.services,\n binding: from.binding,\n }),\n});\n\n/**\n * Schema migrations exported by this module.\n * Exported as an array for extensibility — append future versions here.\n */\nexport const migrations = [_migration];\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA;;;;;;;;;;;;;;;;;;;;;;AAMA,YAAYA,aAAa;AACzB,YAAYC,YAAY;AACxB,YAAYC,WAAW;AACvB,YAAYC,cAAc;AAC1B,YAAYC,aAAa;AAGzB,SAASC,YAAYC,YAAYC,WAAWC,KAAKC,KAAKC,YAAgC;AAW/E,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;AAOO,IAAMC,YAAY,CAA2CC,OAAAA;AAClE,SAAO;IACL,GAAGA;IACHC,MAAM;MACJ,GAAGD,GAAGC;MACNC,YAAY,aAAaF,GAAGC,KAAKE,GAAG;IACtC;EACF;AACF;AA4BO,IAAMC,cAQT,CACFC,aACAC,YAAAA;AAGA,MAAIA,YAAYC,QAAW;AACzB,UAAMC,YAAYH;AAMlB,WAAQ,CAACL,SAAa;MACpB,GAAGA;MACHM,SAASE;IACX;EAC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AgBH,iBAAS9B,IAAIA,IAAID,IAAImC,OAAO,CAAA;EAC5CC,aAAqBL,iBAASjC,WAAWA,UAAU;EACnDuC,cAAsBN,iBAASjC,WAAWA,UAAU;EACpDa,UAAkBoB,iBAAiBO,cAAcN,cAAM,CAAA;EACvDO,SAAiBR,iBAAiBC,cAAM;AAC1C,CAAA,EAAGpB,KACDV,KAAKsC,OAAO;EACVC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;AAQF,IAAMmD,aAAa9F,UAAU+F,OAAO;EAClCC,MAAMH;EACNI,IAAItE;EACJuE,WAAW,OAAOF,UAAU;IAC1B,CAAC/F,IAAIwD,IAAI,GAAG;MAAErC,KAAK4E,KAAK5E;MAAKuB,SAASqD,KAAKrD;IAAQ;IACnDd,MAAMmE,KAAKnE;IACXE,aAAaiE,KAAKjE;IAClBG,SAAS8D,KAAK9D;IACdC,QAAQ6D,KAAK7D;IACbE,aAAa2D,KAAK3D;IAClBC,cAAc0D,KAAK1D;IACnB1B,UAAUoF,KAAKpF;IACf4B,SAASwD,KAAKxD;EAChB;AACF,CAAA;AAMO,IAAM2D,aAAa;EAACL;;",
|
|
6
|
+
"names": ["Context", "Effect", "Layer", "Pipeable", "Schema$", "Annotation", "JsonSchema", "Migration", "Obj", "Ref", "Type", "DefinitionTypeId", "isOperationDefinition", "value", "isOperationWithHandler", "make", "props", "executionMode", "types", "services", "pipe", "pipeArguments", "arguments", "intrinsic", "op", "meta", "deployedId", "key", "withHandler", "opOrHandler", "handler", "undefined", "handlerFn", "opaqueHandler", "PersistentOperation", "Struct", "name", "NonEmptyString", "description", "optional", "String", "updated", "source", "Unknown", "inputSchema", "outputSchema", "Array", "binding", "object", "typename", "version", "LabelAnnotation", "set", "IconAnnotation", "icon", "hue", "SystemTypeAnnotation", "FUNCTION_META_KEY", "getKey", "record", "getMeta", "getVersion", "serialize", "operation", "Meta", "keys", "id", "toJsonSchema", "input", "output", "map", "service", "deserialize", "find", "toEffectSchema", "GenericTag", "setFrom", "target", "update", "JSON", "parse", "stringify", "sourceMeta", "targetMeta", "length", "Service", "Tag", "invoke", "args", "flatMap", "ops", "withSpan", "schedule", "withInvocationOptions", "options", "effect", "gen", "of", "invocationOptions", "invokePromise", "PersistentOperation_v0_1_0", "_migration", "define", "from", "to", "transform", "migrations"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
intrinsic,
|
|
3
|
+
make
|
|
4
|
+
} from "./chunk-SEBWOTOU.mjs";
|
|
5
|
+
|
|
6
|
+
// src/testing/definitions.ts
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
var Fibonacci = make({
|
|
9
|
+
meta: {
|
|
10
|
+
key: "org.example.function.fib",
|
|
11
|
+
name: "Fibonacci",
|
|
12
|
+
description: "Function that calculates a Fibonacci number"
|
|
13
|
+
},
|
|
14
|
+
input: Schema.Struct({
|
|
15
|
+
iterations: Schema.optional(Schema.Number).annotations({
|
|
16
|
+
description: "Number of iterations",
|
|
17
|
+
default: 1e5
|
|
18
|
+
})
|
|
19
|
+
}),
|
|
20
|
+
output: Schema.Struct({
|
|
21
|
+
result: Schema.String
|
|
22
|
+
})
|
|
23
|
+
}).pipe(intrinsic);
|
|
24
|
+
var Reply = make({
|
|
25
|
+
meta: {
|
|
26
|
+
key: "org.example.function.reply",
|
|
27
|
+
name: "Reply",
|
|
28
|
+
description: "Function that echoes the input"
|
|
29
|
+
},
|
|
30
|
+
input: Schema.Any,
|
|
31
|
+
output: Schema.Any
|
|
32
|
+
}).pipe(intrinsic);
|
|
33
|
+
var Sleep = make({
|
|
34
|
+
meta: {
|
|
35
|
+
key: "org.example.function.sleep",
|
|
36
|
+
name: "Sleep",
|
|
37
|
+
description: "Function that sleeps for a given amount of time"
|
|
38
|
+
},
|
|
39
|
+
input: Schema.Struct({
|
|
40
|
+
duration: Schema.optional(Schema.Number).annotations({
|
|
41
|
+
description: "Milliseconds to sleep",
|
|
42
|
+
default: 1e5
|
|
43
|
+
})
|
|
44
|
+
}),
|
|
45
|
+
output: Schema.Void
|
|
46
|
+
}).pipe(intrinsic);
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
Fibonacci,
|
|
50
|
+
Reply,
|
|
51
|
+
Sleep
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=chunk-VSICPGGY.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}).pipe(Operation.intrinsic);\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}).pipe(Operation.intrinsic);\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}).pipe(Operation.intrinsic);\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,EAAGC,KAAeC,SAAS;AAEpB,IAAMC,QAAkBjB,KAAK;EAClCC,MAAM;IACJC,KAAK;IACLC,MAAM;IACNC,aAAa;EACf;EACAC,OAAca;EACdN,QAAeM;AACjB,CAAA,EAAGH,KAAeC,SAAS;AAEpB,IAAMG,QAAkBnB,KAAK;EAClCC,MAAM;IACJC,KAAK;IACLC,MAAM;IACNC,aAAa;EACf;EACAC,OAAcC,cAAO;IACnBc,UAAiBZ,gBAAgBC,aAAM,EAAEC,YAAY;MACnDN,aAAa;MACbO,SAAS;IACX,CAAA;EACF,CAAA;EACAC,QAAeS;AACjB,CAAA,EAAGN,KAAeC,SAAS;",
|
|
6
|
+
"names": ["Schema", "Fibonacci", "make", "meta", "key", "name", "description", "input", "Struct", "iterations", "optional", "Number", "annotations", "default", "output", "result", "String", "pipe", "intrinsic", "Reply", "Any", "Sleep", "duration", "Void"]
|
|
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-XEVFBI6S.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/StorageService.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\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;;;;;;;;;;;AAMA,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
|
+
}
|