@dxos/functions 0.8.1-main.ba2dec9 → 0.8.1-staging.31c3ee1
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/dist/lib/browser/{chunk-M7ZGVWUZ.mjs → chunk-HI7YZO2K.mjs} +2 -2
- package/dist/lib/browser/{chunk-UMJKVIP4.mjs → chunk-LT4LR4VU.mjs} +11 -33
- package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +7 -0
- package/dist/lib/browser/{chunk-RTBBW6RI.mjs → chunk-RVSG6WTL.mjs} +119 -18
- package/dist/lib/browser/chunk-RVSG6WTL.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +1 -1
- package/dist/lib/browser/index.mjs +11 -5
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/browser/types/index.mjs +9 -3
- package/dist/lib/node/{chunk-GX3ZLNHY.cjs → chunk-DSUGRAAL.cjs} +124 -20
- package/dist/lib/node/chunk-DSUGRAAL.cjs.map +7 -0
- package/dist/lib/node/{chunk-UHTKCFWT.cjs → chunk-NXZNXVT3.cjs} +15 -37
- package/dist/lib/node/chunk-NXZNXVT3.cjs.map +7 -0
- package/dist/lib/node/{chunk-AOKUMNKK.cjs → chunk-RXMCVAMJ.cjs} +15 -15
- package/dist/lib/node/edge/index.cjs +4 -4
- package/dist/lib/node/edge/index.cjs.map +1 -1
- package/dist/lib/node/index.cjs +35 -29
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +7 -7
- package/dist/lib/node/types/index.cjs +26 -20
- package/dist/lib/node/types/index.cjs.map +2 -2
- package/dist/lib/node-esm/{chunk-NALEEAQL.mjs → chunk-HBD2FZXO.mjs} +119 -18
- package/dist/lib/node-esm/chunk-HBD2FZXO.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-JDOIALGL.mjs → chunk-O2SXVYU5.mjs} +11 -33
- package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-BYS52HOC.mjs → chunk-SQSJO5HI.mjs} +2 -2
- package/dist/lib/node-esm/edge/index.mjs +1 -1
- package/dist/lib/node-esm/index.mjs +11 -5
- package/dist/lib/node-esm/index.mjs.map +2 -2
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +2 -2
- package/dist/lib/node-esm/types/index.mjs +9 -3
- package/dist/types/src/edge/functions.d.ts +3 -3
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/handler.d.ts +1 -1
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +20 -26
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/trace.d.ts +102 -96
- package/dist/types/src/types/trace.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/edge/functions.ts +12 -29
- package/src/handler.ts +2 -2
- package/src/runtime/scheduler.test.ts +2 -1
- package/src/types/schema.ts +7 -7
- package/src/types/trace.ts +120 -8
- package/src/types/types.ts +2 -1
- package/dist/lib/browser/chunk-RTBBW6RI.mjs.map +0 -7
- package/dist/lib/browser/chunk-UMJKVIP4.mjs.map +0 -7
- package/dist/lib/node/chunk-GX3ZLNHY.cjs.map +0 -7
- package/dist/lib/node/chunk-UHTKCFWT.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-JDOIALGL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NALEEAQL.mjs.map +0 -7
- /package/dist/lib/browser/{chunk-M7ZGVWUZ.mjs.map → chunk-HI7YZO2K.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-AOKUMNKK.cjs.map → chunk-RXMCVAMJ.cjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-BYS52HOC.mjs.map → chunk-SQSJO5HI.mjs.map} +0 -0
|
@@ -2,7 +2,7 @@ import "@dxos/node-std/globals";
|
|
|
2
2
|
import {
|
|
3
3
|
FunctionDef,
|
|
4
4
|
FunctionTrigger
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-RVSG6WTL.mjs";
|
|
6
6
|
|
|
7
7
|
// packages/core/functions/src/function/function-registry.ts
|
|
8
8
|
import { Event } from "@dxos/async";
|
|
@@ -479,4 +479,4 @@ export {
|
|
|
479
479
|
createTimerTrigger,
|
|
480
480
|
TriggerRegistry
|
|
481
481
|
};
|
|
482
|
-
//# sourceMappingURL=chunk-
|
|
482
|
+
//# sourceMappingURL=chunk-HI7YZO2K.mjs.map
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
3
|
// packages/core/functions/src/edge/functions.ts
|
|
4
|
+
import { createEdgeIdentity } from "@dxos/client/edge";
|
|
4
5
|
import { EdgeHttpClient } from "@dxos/edge-client";
|
|
5
6
|
import { invariant } from "@dxos/invariant";
|
|
6
7
|
import { log } from "@dxos/log";
|
|
7
8
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/edge/functions.ts";
|
|
8
|
-
var uploadWorkerFunction = async ({ client,
|
|
9
|
+
var uploadWorkerFunction = async ({ client, spaceId, version, source, name, functionId }) => {
|
|
9
10
|
const edgeUrl = client.config.values.runtime?.services?.edge?.url;
|
|
10
11
|
invariant(edgeUrl, "Edge is not configured.", {
|
|
11
12
|
F: __dxlog_file,
|
|
12
|
-
L:
|
|
13
|
+
L: 33,
|
|
13
14
|
S: void 0,
|
|
14
15
|
A: [
|
|
15
16
|
"edgeUrl",
|
|
@@ -27,53 +28,30 @@ var uploadWorkerFunction = async ({ client, name, version, source, spaceId, func
|
|
|
27
28
|
version,
|
|
28
29
|
script: source
|
|
29
30
|
});
|
|
30
|
-
log("Uploaded", {
|
|
31
|
+
log.info("Uploaded", {
|
|
32
|
+
identityKey: edgeIdentity.identityKey,
|
|
31
33
|
functionId,
|
|
32
|
-
source,
|
|
33
34
|
name,
|
|
34
|
-
|
|
35
|
+
source: source.length,
|
|
35
36
|
response
|
|
36
37
|
}, {
|
|
37
38
|
F: __dxlog_file,
|
|
38
|
-
L:
|
|
39
|
+
L: 40,
|
|
39
40
|
S: void 0,
|
|
40
41
|
C: (f, a) => f(...a)
|
|
41
42
|
});
|
|
42
43
|
return response;
|
|
43
44
|
};
|
|
44
|
-
var createEdgeIdentity = (client) => {
|
|
45
|
-
const identity = client.halo.identity.get();
|
|
46
|
-
const device = client.halo.device;
|
|
47
|
-
if (!identity || !device) {
|
|
48
|
-
throw new Error("Identity not available");
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
identityKey: identity.identityKey.toHex(),
|
|
52
|
-
peerKey: device.deviceKey.toHex(),
|
|
53
|
-
presentCredentials: async ({ challenge }) => {
|
|
54
|
-
const identityService = client.services.services.IdentityService;
|
|
55
|
-
const authCredential = await identityService.createAuthCredential();
|
|
56
|
-
return identityService.signPresentation({
|
|
57
|
-
presentation: {
|
|
58
|
-
credentials: [
|
|
59
|
-
authCredential
|
|
60
|
-
]
|
|
61
|
-
},
|
|
62
|
-
nonce: challenge
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
45
|
var incrementSemverPatch = (version) => {
|
|
68
46
|
const [major, minor, patch] = version.split(".");
|
|
69
47
|
const patchNum = Number(patch);
|
|
70
|
-
invariant(!Number.isNaN(patchNum),
|
|
48
|
+
invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`, {
|
|
71
49
|
F: __dxlog_file,
|
|
72
|
-
L:
|
|
50
|
+
L: 54,
|
|
73
51
|
S: void 0,
|
|
74
52
|
A: [
|
|
75
53
|
"!Number.isNaN(patchNum)",
|
|
76
|
-
"
|
|
54
|
+
"`Unexpected function version format: ${version}`"
|
|
77
55
|
]
|
|
78
56
|
});
|
|
79
57
|
return [
|
|
@@ -91,4 +69,4 @@ export {
|
|
|
91
69
|
incrementSemverPatch,
|
|
92
70
|
publicKeyToDid
|
|
93
71
|
};
|
|
94
|
-
//# sourceMappingURL=chunk-
|
|
72
|
+
//# sourceMappingURL=chunk-LT4LR4VU.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/edge/functions.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Client } from '@dxos/client';\nimport { createEdgeIdentity } from '@dxos/client/edge';\nimport { EdgeHttpClient } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport type { PublicKey, SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type UploadFunctionResponseBody } from '@dxos/protocols';\n\nexport type UploadWorkerArgs = {\n client: Client;\n spaceId: SpaceId;\n source: string;\n version: string;\n name?: string;\n functionId?: string;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n spaceId,\n version,\n source,\n name,\n functionId,\n}: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {\n const edgeUrl = client.config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'Edge is not configured.');\n const edgeClient = new EdgeHttpClient(edgeUrl);\n const edgeIdentity = createEdgeIdentity(client);\n edgeClient.setIdentity(edgeIdentity);\n const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });\n\n // TODO(burdon): Edge service log.\n log.info('Uploaded', {\n identityKey: edgeIdentity.identityKey,\n functionId,\n name,\n source: source.length,\n response,\n });\n\n return response;\n};\n\nexport const incrementSemverPatch = (version: string): string => {\n const [major, minor, patch] = version.split('.');\n const patchNum = Number(patch);\n invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`);\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\n// TODO(burdon): Factor out.\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
|
|
5
|
+
"mappings": ";;;AAOA,SAASA,0BAA0B;AACnC,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;AAE1B,SAASC,WAAW;;AAYb,IAAMC,uBAAuB,OAAO,EACzCC,QACAC,SACAC,SACAC,QACAC,MACAC,WAAU,MACO;AACjB,QAAMC,UAAUN,OAAOO,OAAOC,OAAOC,SAASC,UAAUC,MAAMC;AAC9Df,YAAUS,SAAS,2BAAA;;;;;;;;;AACnB,QAAMO,aAAa,IAAIjB,eAAeU,OAAAA;AACtC,QAAMQ,eAAenB,mBAAmBK,MAAAA;AACxCa,aAAWE,YAAYD,YAAAA;AACvB,QAAME,WAAW,MAAMH,WAAWI,eAAe;IAAEhB;IAASI;EAAW,GAAG;IAAED;IAAMF;IAASgB,QAAQf;EAAO,CAAA;AAG1GL,MAAIqB,KAAK,YAAY;IACnBC,aAAaN,aAAaM;IAC1Bf;IACAD;IACAD,QAAQA,OAAOkB;IACfL;EACF,GAAA;;;;;;AAEA,SAAOA;AACT;AAEO,IAAMM,uBAAuB,CAACpB,YAAAA;AACnC,QAAM,CAACqB,OAAOC,OAAOC,KAAAA,IAASvB,QAAQwB,MAAM,GAAA;AAC5C,QAAMC,WAAWC,OAAOH,KAAAA;AACxB5B,YAAU,CAAC+B,OAAOC,MAAMF,QAAAA,GAAW,uCAAuCzB,OAAAA,IAAS;;;;;;;;;AACnF,SAAO;IAACqB;IAAOC;IAAOM,OAAOH,WAAW,CAAA;IAAII,KAAK,GAAA;AACnD;AAGO,IAAMC,iBAAiB,CAACC,QAAAA;AAC7B,SAAO,WAAWA,IAAIC,MAAK,CAAA;AAC7B;",
|
|
6
|
+
"names": ["createEdgeIdentity", "EdgeHttpClient", "invariant", "log", "uploadWorkerFunction", "client", "spaceId", "version", "source", "name", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "edgeClient", "edgeIdentity", "setIdentity", "response", "uploadFunction", "script", "info", "identityKey", "length", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid", "key", "toHex"]
|
|
7
|
+
}
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import "@dxos/node-std/globals";
|
|
2
2
|
|
|
3
3
|
// packages/core/functions/src/types/schema.ts
|
|
4
|
-
import { JsonSchemaType, Ref, S, TypedObject } from "@dxos/echo-schema";
|
|
4
|
+
import { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, S, TypedObject } from "@dxos/echo-schema";
|
|
5
5
|
import { TextType } from "@dxos/schema";
|
|
6
|
-
var ScriptType =
|
|
7
|
-
typename: "dxos.org/type/Script",
|
|
8
|
-
version: "0.1.0"
|
|
9
|
-
})({
|
|
6
|
+
var ScriptType = S.Struct({
|
|
10
7
|
name: S.optional(S.String),
|
|
11
8
|
description: S.optional(S.String),
|
|
12
9
|
// TODO(burdon): Change to hash of deployed content.
|
|
13
10
|
// Whether source has changed since last deploy.
|
|
14
11
|
changed: S.optional(S.Boolean),
|
|
15
12
|
source: Ref(TextType)
|
|
16
|
-
})
|
|
17
|
-
|
|
13
|
+
}).annotations({
|
|
14
|
+
[LabelAnnotationId]: "name"
|
|
15
|
+
}).pipe(EchoObject({
|
|
16
|
+
typename: "dxos.org/type/Script",
|
|
17
|
+
version: "0.1.0"
|
|
18
|
+
}));
|
|
18
19
|
var FunctionType = class extends TypedObject({
|
|
19
20
|
typename: "dxos.org/type/Function",
|
|
20
21
|
version: "0.1.0"
|
|
@@ -117,7 +118,8 @@ var FunctionTriggerSchema = S2.Struct({
|
|
|
117
118
|
})),
|
|
118
119
|
// TODO(burdon): Flatten entire schema.
|
|
119
120
|
spec: S2.optional(TriggerSchema),
|
|
120
|
-
// TODO(burdon): Get
|
|
121
|
+
// TODO(burdon): Get schema as partial from function.
|
|
122
|
+
// TODO(wittjosiah): Rename to payload.
|
|
121
123
|
// The `meta` property is merged into the event data passed to the function.
|
|
122
124
|
meta: S2.optional(S2.mutable(S2.Record({
|
|
123
125
|
key: S2.String,
|
|
@@ -149,27 +151,49 @@ var FUNCTION_TYPES = [
|
|
|
149
151
|
];
|
|
150
152
|
|
|
151
153
|
// packages/core/functions/src/types/trace.ts
|
|
152
|
-
import { EchoObject, Expando, ObjectId, Ref as Ref2, S as S3 } from "@dxos/echo-schema";
|
|
154
|
+
import { EchoObject as EchoObject2, Expando, ObjectId, Ref as Ref2, S as S3 } from "@dxos/echo-schema";
|
|
155
|
+
import { log } from "@dxos/log";
|
|
156
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/types/trace.ts";
|
|
153
157
|
var InvocationOutcome;
|
|
154
158
|
(function(InvocationOutcome2) {
|
|
155
159
|
InvocationOutcome2["SUCCESS"] = "success";
|
|
156
160
|
InvocationOutcome2["FAILURE"] = "failure";
|
|
161
|
+
InvocationOutcome2["PENDING"] = "pending";
|
|
157
162
|
})(InvocationOutcome || (InvocationOutcome = {}));
|
|
163
|
+
var InvocationTraceEventType;
|
|
164
|
+
(function(InvocationTraceEventType2) {
|
|
165
|
+
InvocationTraceEventType2["START"] = "start";
|
|
166
|
+
InvocationTraceEventType2["END"] = "end";
|
|
167
|
+
})(InvocationTraceEventType || (InvocationTraceEventType = {}));
|
|
158
168
|
var TraceEventException = S3.Struct({
|
|
159
169
|
timestampMs: S3.Number,
|
|
160
170
|
message: S3.String,
|
|
161
171
|
name: S3.String,
|
|
162
172
|
stack: S3.optional(S3.String)
|
|
163
173
|
});
|
|
164
|
-
var
|
|
174
|
+
var InvocationTraceStartEvent = S3.Struct({
|
|
175
|
+
/**
|
|
176
|
+
* Queue message id.
|
|
177
|
+
*/
|
|
165
178
|
id: ObjectId,
|
|
179
|
+
type: S3.Literal("start"),
|
|
180
|
+
/**
|
|
181
|
+
* Invocation id, the same for invocation start and end events.
|
|
182
|
+
*/
|
|
183
|
+
invocationId: ObjectId,
|
|
184
|
+
/**
|
|
185
|
+
* Event generation time.
|
|
186
|
+
*/
|
|
166
187
|
timestampMs: S3.Number,
|
|
167
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Data passed to function / workflow as an argument.
|
|
190
|
+
*/
|
|
191
|
+
// TODO(burdon): Input schema?
|
|
168
192
|
input: S3.Object,
|
|
169
|
-
durationMs: S3.Number,
|
|
170
193
|
/**
|
|
171
194
|
* Queue DXN for function/workflow invocation events.
|
|
172
195
|
*/
|
|
196
|
+
// TODO(burdon): Need reference type for queue. vs. string?
|
|
173
197
|
invocationTraceQueue: Ref2(Expando),
|
|
174
198
|
/**
|
|
175
199
|
* DXN of the invoked function/workflow.
|
|
@@ -178,12 +202,32 @@ var InvocationTraceEvent = S3.Struct({
|
|
|
178
202
|
/**
|
|
179
203
|
* Present for automatic invocations.
|
|
180
204
|
*/
|
|
181
|
-
trigger: S3.optional(Ref2(FunctionTrigger))
|
|
205
|
+
trigger: S3.optional(Ref2(FunctionTrigger))
|
|
206
|
+
}).pipe(EchoObject2({
|
|
207
|
+
typename: "dxos.org/type/InvocationTraceStart",
|
|
208
|
+
version: "0.1.0"
|
|
209
|
+
}));
|
|
210
|
+
var InvocationTraceEndEvent = S3.Struct({
|
|
182
211
|
/**
|
|
183
|
-
*
|
|
212
|
+
* Trace event id.
|
|
184
213
|
*/
|
|
214
|
+
id: ObjectId,
|
|
215
|
+
type: S3.Literal("end"),
|
|
216
|
+
/**
|
|
217
|
+
* Invocation id, will be the same for invocation start and end.
|
|
218
|
+
*/
|
|
219
|
+
invocationId: ObjectId,
|
|
220
|
+
/**
|
|
221
|
+
* Event generation time.
|
|
222
|
+
*/
|
|
223
|
+
// TODO(burdon): Remove ms suffix.
|
|
224
|
+
timestampMs: S3.Number,
|
|
225
|
+
outcome: S3.Enums(InvocationOutcome),
|
|
185
226
|
exception: S3.optional(TraceEventException)
|
|
186
|
-
}).pipe(
|
|
227
|
+
}).pipe(EchoObject2({
|
|
228
|
+
typename: "dxos.org/type/InvocationTraceEnd",
|
|
229
|
+
version: "0.1.0"
|
|
230
|
+
}));
|
|
187
231
|
var TraceEventLog = S3.Struct({
|
|
188
232
|
timestampMs: S3.Number,
|
|
189
233
|
level: S3.String,
|
|
@@ -192,6 +236,7 @@ var TraceEventLog = S3.Struct({
|
|
|
192
236
|
});
|
|
193
237
|
var TraceEvent = S3.Struct({
|
|
194
238
|
id: ObjectId,
|
|
239
|
+
// TODO(burdon): Need enum/numeric result (not string).
|
|
195
240
|
outcome: S3.String,
|
|
196
241
|
truncated: S3.Boolean,
|
|
197
242
|
/**
|
|
@@ -200,7 +245,60 @@ var TraceEvent = S3.Struct({
|
|
|
200
245
|
ingestionTimestampMs: S3.Number,
|
|
201
246
|
logs: S3.Array(TraceEventLog),
|
|
202
247
|
exceptions: S3.Array(TraceEventException)
|
|
203
|
-
}).pipe(
|
|
248
|
+
}).pipe(EchoObject2({
|
|
249
|
+
typename: "dxos.org/type/TraceEvent",
|
|
250
|
+
version: "0.1.0"
|
|
251
|
+
}));
|
|
252
|
+
var createInvocationSpans = (items) => {
|
|
253
|
+
if (!items) {
|
|
254
|
+
return [];
|
|
255
|
+
}
|
|
256
|
+
const eventsByInvocationId = /* @__PURE__ */ new Map();
|
|
257
|
+
for (const event of items) {
|
|
258
|
+
if (!("invocationId" in event)) {
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
const invocationId = event.invocationId;
|
|
262
|
+
const entry = eventsByInvocationId.get(invocationId) || {
|
|
263
|
+
start: void 0,
|
|
264
|
+
end: void 0
|
|
265
|
+
};
|
|
266
|
+
if (event.type === "start") {
|
|
267
|
+
entry.start = event;
|
|
268
|
+
} else if (event.type === "end") {
|
|
269
|
+
entry.end = event;
|
|
270
|
+
}
|
|
271
|
+
eventsByInvocationId.set(invocationId, entry);
|
|
272
|
+
}
|
|
273
|
+
const now = Date.now();
|
|
274
|
+
const result = [];
|
|
275
|
+
for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
|
|
276
|
+
if (!start) {
|
|
277
|
+
log.warn("found end event without matching start", {
|
|
278
|
+
invocationId
|
|
279
|
+
}, {
|
|
280
|
+
F: __dxlog_file,
|
|
281
|
+
L: 158,
|
|
282
|
+
S: void 0,
|
|
283
|
+
C: (f, a) => f(...a)
|
|
284
|
+
});
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const isInProgress = end === void 0;
|
|
288
|
+
result.push({
|
|
289
|
+
id: invocationId,
|
|
290
|
+
timestampMs: start.timestampMs,
|
|
291
|
+
durationMs: isInProgress ? now - start.timestampMs : end.timestampMs - start.timestampMs,
|
|
292
|
+
outcome: end?.outcome ?? "pending",
|
|
293
|
+
exception: end?.exception,
|
|
294
|
+
input: start.input,
|
|
295
|
+
invocationTraceQueue: start.invocationTraceQueue,
|
|
296
|
+
invocationTarget: start.invocationTarget,
|
|
297
|
+
trigger: start.trigger
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
return result;
|
|
301
|
+
};
|
|
204
302
|
|
|
205
303
|
// packages/core/functions/src/types/url.ts
|
|
206
304
|
var FUNCTIONS_META_KEY = "dxos.org/service/function";
|
|
@@ -245,13 +343,16 @@ export {
|
|
|
245
343
|
FunctionManifestSchema,
|
|
246
344
|
FUNCTION_TYPES,
|
|
247
345
|
InvocationOutcome,
|
|
346
|
+
InvocationTraceEventType,
|
|
248
347
|
TraceEventException,
|
|
249
|
-
|
|
348
|
+
InvocationTraceStartEvent,
|
|
349
|
+
InvocationTraceEndEvent,
|
|
250
350
|
TraceEventLog,
|
|
251
351
|
TraceEvent,
|
|
352
|
+
createInvocationSpans,
|
|
252
353
|
FUNCTIONS_PRESET_META_KEY,
|
|
253
354
|
getUserFunctionUrlInMetadata,
|
|
254
355
|
setUserFunctionUrlInMetadata,
|
|
255
356
|
getInvocationUrl
|
|
256
357
|
};
|
|
257
|
-
//# sourceMappingURL=chunk-
|
|
358
|
+
//# sourceMappingURL=chunk-RVSG6WTL.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts", "../../../src/types/trace.ts", "../../../src/types/url.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport const ScriptType = S.Struct({\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: Ref(TextType),\n})\n .annotations({ [LabelAnnotationId]: 'name' })\n .pipe(EchoObject({ typename: 'dxos.org/type/Script', version: '0.1.0' }));\n\nexport type ScriptType = S.Schema.Type<typeof ScriptType>;\n\n/**\n * Function deployment.\n */\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: S.NonEmptyString,\n version: S.String,\n\n description: S.optional(S.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(Ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n outputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject, DXN } from '@dxos/echo-schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n Email = 'email',\n Queue = 'queue',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [AST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [AST.TitleAnnotationId]: 'Cron',\n [AST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),\n}).pipe(S.mutable);\n\nexport type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;\n\nconst QueueTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Queue).annotations(typeLiteralAnnotations),\n queue: DXN,\n}).pipe(S.mutable);\n\nexport type QueueTrigger = S.Schema.Type<typeof QueueTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n QueueTriggerSchema,\n).annotations({\n [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n // TODO(wittjosiah): This should probably be a Ref?\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get schema as partial from function.\n // TODO(wittjosiah): Rename to payload.\n // The `meta` property is merged into the event data passed to the function.\n meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { EchoObject, Expando, ObjectId, Ref, S } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\n\nimport { FunctionTrigger, type FunctionTriggerType } from './types';\n\nexport enum InvocationOutcome {\n SUCCESS = 'success',\n FAILURE = 'failure',\n PENDING = 'pending',\n}\n\n// TODO(burdon): Convert to extensible discriminated union of EDGE events.\nexport enum InvocationTraceEventType {\n START = 'start',\n END = 'end',\n}\n\nexport const TraceEventException = S.Struct({\n timestampMs: S.Number,\n message: S.String,\n name: S.String,\n stack: S.optional(S.String),\n});\nexport type TraceEventException = S.Schema.Type<typeof TraceEventException>;\n\nexport const InvocationTraceStartEvent = S.Struct({\n /**\n * Queue message id.\n */\n id: ObjectId,\n type: S.Literal(InvocationTraceEventType.START),\n /**\n * Invocation id, the same for invocation start and end events.\n */\n invocationId: ObjectId,\n /**\n * Event generation time.\n */\n timestampMs: S.Number,\n /**\n * Data passed to function / workflow as an argument.\n */\n // TODO(burdon): Input schema?\n input: S.Object,\n /**\n * Queue DXN for function/workflow invocation events.\n */\n // TODO(burdon): Need reference type for queue. vs. string?\n invocationTraceQueue: Ref(Expando),\n /**\n * DXN of the invoked function/workflow.\n */\n invocationTarget: Ref(Expando),\n /**\n * Present for automatic invocations.\n */\n trigger: S.optional(Ref(FunctionTrigger)),\n}).pipe(EchoObject({ typename: 'dxos.org/type/InvocationTraceStart', version: '0.1.0' }));\n\nexport type InvocationTraceStartEvent = S.Schema.Type<typeof InvocationTraceStartEvent>;\n\nexport const InvocationTraceEndEvent = S.Struct({\n /**\n * Trace event id.\n */\n id: ObjectId,\n type: S.Literal(InvocationTraceEventType.END),\n /**\n * Invocation id, will be the same for invocation start and end.\n */\n invocationId: ObjectId,\n /**\n * Event generation time.\n */\n // TODO(burdon): Remove ms suffix.\n timestampMs: S.Number,\n outcome: S.Enums(InvocationOutcome),\n exception: S.optional(TraceEventException),\n}).pipe(EchoObject({ typename: 'dxos.org/type/InvocationTraceEnd', version: '0.1.0' }));\n\nexport type InvocationTraceEndEvent = S.Schema.Type<typeof InvocationTraceEndEvent>;\n\nexport type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;\n\nexport const TraceEventLog = S.Struct({\n timestampMs: S.Number,\n level: S.String,\n message: S.String,\n context: S.optional(S.Object),\n});\n\nexport const TraceEvent = S.Struct({\n id: ObjectId,\n // TODO(burdon): Need enum/numeric result (not string).\n outcome: S.String,\n truncated: S.Boolean,\n /**\n * Time when the event was persisted.\n */\n ingestionTimestampMs: S.Number,\n logs: S.Array(TraceEventLog),\n exceptions: S.Array(TraceEventException),\n}).pipe(EchoObject({ typename: 'dxos.org/type/TraceEvent', version: '0.1.0' }));\n\nexport type TraceEvent = S.Schema.Type<typeof TraceEvent>;\n\n/**\n * Deprecated InvocationTrace event format.\n * @deprecated\n */\n// TODO(burdon): Remove.\nexport type InvocationSpan = {\n id: string;\n timestampMs: number;\n outcome: InvocationOutcome;\n input: object;\n durationMs: number;\n invocationTraceQueue: Ref<Expando>;\n invocationTarget: Ref<Expando>;\n trigger?: Ref<FunctionTriggerType>;\n exception?: TraceEventException;\n};\n\nexport const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {\n if (!items) {\n return [];\n }\n\n const eventsByInvocationId = new Map<string, { start?: InvocationTraceStartEvent; end?: InvocationTraceEndEvent }>();\n for (const event of items) {\n if (!('invocationId' in event)) {\n // Skip legacy format entries.\n continue;\n }\n\n const invocationId = event.invocationId;\n const entry = eventsByInvocationId.get(invocationId) || { start: undefined, end: undefined };\n if (event.type === InvocationTraceEventType.START) {\n entry.start = event as InvocationTraceStartEvent;\n } else if (event.type === InvocationTraceEventType.END) {\n entry.end = event as InvocationTraceEndEvent;\n }\n\n eventsByInvocationId.set(invocationId, entry);\n }\n\n const now = Date.now();\n const result: InvocationSpan[] = [];\n\n // Create spans for each invocation\n for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {\n if (!start) {\n // No start event, can't create a meaningful span\n log.warn('found end event without matching start', { invocationId });\n continue;\n }\n\n const isInProgress = end === undefined;\n\n result.push({\n id: invocationId,\n timestampMs: start.timestampMs,\n durationMs: isInProgress ? now - start.timestampMs : end!.timestampMs - start.timestampMs,\n outcome: end?.outcome ?? InvocationOutcome.PENDING,\n exception: end?.exception,\n input: start.input,\n invocationTraceQueue: start.invocationTraceQueue,\n invocationTarget: start.invocationTarget,\n trigger: start.trigger,\n });\n }\n\n return result;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { type SpaceId } from '@dxos/keys';\n\n// TODO: use URL scheme for source?\nconst FUNCTIONS_META_KEY = 'dxos.org/service/function';\n\nexport const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';\n\nconst isSecure = (protocol: string) => {\n return protocol === 'https:' || protocol === 'wss:';\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = isSecure(url.protocol) ? 'https' : 'http';\n return url.toString();\n};\n\nexport type InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,YAAYC,gBAAgBC,mBAAmBC,KAAKC,GAAGC,mBAAmB;AACnF,SAASC,gBAAgB;AAKlB,IAAMC,aAAaC,EAAEC,OAAO;EACjCC,MAAMF,EAAEG,SAASH,EAAEI,MAAM;EACzBC,aAAaL,EAAEG,SAASH,EAAEI,MAAM;;;EAGhCE,SAASN,EAAEG,SAASH,EAAEO,OAAO;EAC7BC,QAAQC,IAAIC,QAAAA;AACd,CAAA,EACGC,YAAY;EAAE,CAACC,iBAAAA,GAAoB;AAAO,CAAA,EAC1CC,KAAKC,WAAW;EAAEC,UAAU;EAAwBC,SAAS;AAAQ,CAAA,CAAA;AAOjE,IAAMC,eAAN,cAA2BC,YAAY;EAC5CH,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDd,MAAMF,EAAEmB;EACRH,SAAShB,EAAEI;EAEXC,aAAaL,EAAEG,SAASH,EAAEI,MAAM;;;EAIhCI,QAAQR,EAAEG,SAASM,IAAIV,UAAAA,CAAAA;EAEvBqB,aAAapB,EAAEG,SAASkB,cAAAA;EACxBC,cAActB,EAAEG,SAASkB,cAAAA;;EAGzBE,SAASvB,EAAEG,SAASH,EAAEI,MAAM;AAC9B,CAAA,EAAA;AAAI;;;ACzCJ,SAASoB,KAAKC,qBAAqBC,WAAWC,KAAAA,IAAGC,eAAAA,cAAaC,WAAW;;UAO7DC,cAAAA;;;;;;GAAAA,gBAAAA,cAAAA,CAAAA,EAAAA;AASZ,IAAMC,yBAAyB;EAAE,CAACC,IAAIC,iBAAiB,GAAG;AAAO;AAKjE,IAAMC,qBAAqBC,GAAEC,OAAO;EAClCC,MAAMF,GAAEG,QAAO,OAAA,EAAoBC,YAAYR,sBAAAA;EAC/CS,MAAML,GAAEM,OAAOF,YAAY;IACzB,CAACP,IAAIC,iBA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,QAAQO,OAAO;AAClEP,UAAQU,aAAaL,IAAIG,aAAaC,IAAI,aAAaT,QAAQU,SAAS;AACxEL,MAAInB,WAAWD,SAASoB,IAAInB,QAAQ,IAAI,UAAU;AAClD,SAAOmB,IAAIC,SAAQ;AACrB;",
|
|
6
|
+
"names": ["EchoObject", "JsonSchemaType", "LabelAnnotationId", "Ref", "S", "TypedObject", "TextType", "ScriptType", "S", "Struct", "name", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "annotations", "LabelAnnotationId", "pipe", "EchoObject", "typename", "version", "FunctionType", "TypedObject", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "AST", "OptionsAnnotationId", "RawObject", "S", "TypedObject", "DXN", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "S", "Struct", "type", "Literal", "annotations", "cron", "String", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "optional", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionDef", "uri", "description", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES", "EchoObject", "Expando", "ObjectId", "Ref", "S", "log", "InvocationOutcome", "InvocationTraceEventType", "TraceEventException", "S", "Struct", "timestampMs", "Number", "message", "String", "name", "stack", "optional", "InvocationTraceStartEvent", "id", "ObjectId", "type", "Literal", "invocationId", "input", "Object", "invocationTraceQueue", "Ref", "Expando", "invocationTarget", "trigger", "FunctionTrigger", "pipe", "EchoObject", "typename", "version", "InvocationTraceEndEvent", "outcome", "Enums", "exception", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "Boolean", "ingestionTimestampMs", "logs", "Array", "exceptions", "createInvocationSpans", "items", "eventsByInvocationId", "Map", "event", "entry", "get", "start", "undefined", "end", "set", "now", "Date", "result", "entries", "log", "warn", "isInProgress", "push", "durationMs", "FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "isSecure", "protocol", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "key", "source", "id", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "push", "getInvocationUrl", "edgeUrl", "options", "baseUrl", "URL", "relativeUrl", "replace", "url", "toString", "spaceId", "searchParams", "set", "subjectId"]
|
|
7
|
+
}
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
incrementSemverPatch,
|
|
4
4
|
publicKeyToDid,
|
|
5
5
|
uploadWorkerFunction
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LT4LR4VU.mjs";
|
|
7
7
|
import {
|
|
8
8
|
FunctionRegistry,
|
|
9
9
|
TriggerRegistry,
|
|
10
10
|
createSubscriptionTrigger,
|
|
11
11
|
createTimerTrigger
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-HI7YZO2K.mjs";
|
|
13
13
|
import {
|
|
14
14
|
FUNCTIONS_PRESET_META_KEY,
|
|
15
15
|
FUNCTION_TYPES,
|
|
@@ -19,17 +19,20 @@ import {
|
|
|
19
19
|
FunctionTriggerSchema,
|
|
20
20
|
FunctionType,
|
|
21
21
|
InvocationOutcome,
|
|
22
|
-
|
|
22
|
+
InvocationTraceEndEvent,
|
|
23
|
+
InvocationTraceEventType,
|
|
24
|
+
InvocationTraceStartEvent,
|
|
23
25
|
ScriptType,
|
|
24
26
|
TraceEvent,
|
|
25
27
|
TraceEventException,
|
|
26
28
|
TraceEventLog,
|
|
27
29
|
TriggerKind,
|
|
28
30
|
TriggerSchema,
|
|
31
|
+
createInvocationSpans,
|
|
29
32
|
getInvocationUrl,
|
|
30
33
|
getUserFunctionUrlInMetadata,
|
|
31
34
|
setUserFunctionUrlInMetadata
|
|
32
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-RVSG6WTL.mjs";
|
|
33
36
|
import "./chunk-XRCXIG74.mjs";
|
|
34
37
|
|
|
35
38
|
// packages/core/functions/src/handler.ts
|
|
@@ -121,7 +124,9 @@ export {
|
|
|
121
124
|
FunctionTriggerSchema,
|
|
122
125
|
FunctionType,
|
|
123
126
|
InvocationOutcome,
|
|
124
|
-
|
|
127
|
+
InvocationTraceEndEvent,
|
|
128
|
+
InvocationTraceEventType,
|
|
129
|
+
InvocationTraceStartEvent,
|
|
125
130
|
ScriptType,
|
|
126
131
|
TraceEvent,
|
|
127
132
|
TraceEventException,
|
|
@@ -129,6 +134,7 @@ export {
|
|
|
129
134
|
TriggerKind,
|
|
130
135
|
TriggerRegistry,
|
|
131
136
|
TriggerSchema,
|
|
137
|
+
createInvocationSpans,
|
|
132
138
|
createSubscriptionTrigger,
|
|
133
139
|
createTimerTrigger,
|
|
134
140
|
defineFunction,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/handler.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema as S } from 'effect';\nimport { type Effect } from 'effect';\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space, type SpaceId } from '@dxos/client/echo';\nimport type { CoreDatabase, EchoDatabase, ReactiveEchoObject } from '@dxos/echo-db';\nimport { type HasId } from '@dxos/echo-schema';\nimport { type DXN } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type QueryResult } from '@dxos/protocols';\nimport { isNonNullable } from '@dxos/util';\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\n// https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n\n/**\n * Function handler.\n */\nexport type FunctionHandler<TData = {}, TMeta = {}, TOutput = any> = (params: {\n context: FunctionContext;\n event: FunctionEvent<TData, TMeta>;\n /**\n * @deprecated\n */\n response: FunctionResponse;\n}) => TOutput | Promise<TOutput> | Effect.Effect<TOutput, any>;\n\n/**\n * Function context.\n */\nexport interface FunctionContext {\n getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;\n\n /**\n * Space from which the function was invoked.\n */\n space: SpaceAPI | undefined;\n\n ai: FunctionContextAi;\n\n /**\n * @deprecated\n */\n // TODO(burdon): Limit access to individual space.\n client: Client;\n /**\n * @deprecated\n */\n // TODO(burdon): Replace with storage service abstraction.\n dataDir?: string;\n}\n\nexport interface FunctionContextAi {\n // TODO(dmaretskyi): Refer to cloudflare AI docs for more comprehensive typedefs.\n run(model: string, inputs: any, options?: any): Promise<any>;\n}\n\n/**\n * Event payload.\n */\n// TODO(dmaretskyi): Update type definitions to match the actual payload.\nexport type FunctionEvent<TData = {}, TMeta = {}> = {\n data: FunctionEventMeta<TMeta> & TData;\n};\n\n/**\n * Metadata from trigger.\n */\nexport type FunctionEventMeta<TMeta = {}> = {\n meta: TMeta;\n};\n\n/**\n * Function response.\n */\nexport type FunctionResponse = {\n status(code: number): FunctionResponse;\n};\n\n//\n// API.\n//\n\n// TODO(dmaretskyi): Temporary API to get the queues working.\n// TODO(dmaretskyi): To be replaced with integrating queues into echo.\nexport interface QueuesAPI {\n queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;\n}\n\n/**\n * Space interface available to functions.\n */\nexport interface SpaceAPI {\n get id(): SpaceId;\n /**\n * @deprecated\n */\n get crud(): CoreDatabase;\n get db(): EchoDatabase;\n // TODO(dmaretskyi): Align with echo api --- queues.get(id).append(items);\n get queues(): QueuesAPI;\n}\n\n// TODO(wittjosiah): Fix this.\nconst __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {\n // const _: SpaceAPI = {} as Space;\n};\n\nexport type FunctionDefinition = {\n description?: string;\n inputSchema: S.Schema.AnyNoContext;\n outputSchema?: S.Schema.AnyNoContext;\n handler: FunctionHandler<any>;\n};\n\nexport type DefineFunctionParams<T, O = any> = {\n description?: string;\n inputSchema: S.Schema<T, any>;\n outputSchema?: S.Schema<O, any>;\n handler: FunctionHandler<T, any, O>;\n};\n\n// TODO(dmaretskyi): Bind input type to function handler.\nexport const defineFunction = <T, O>(params: DefineFunctionParams<T, O>): FunctionDefinition => {\n if (!S.isSchema(params.inputSchema)) {\n throw new Error('Input schema must be a valid schema');\n }\n if (typeof params.handler !== 'function') {\n throw new Error('Handler must be a function');\n }\n\n return {\n description: params.description,\n inputSchema: params.inputSchema,\n outputSchema: params.outputSchema ?? S.Any,\n handler: params.handler,\n };\n};\n\n//\n// Subscription utils.\n//\n\nexport type RawSubscriptionData = {\n spaceKey?: string;\n objects?: string[];\n};\n\nexport type SubscriptionData = {\n space?: Space;\n objects?: ReactiveEchoObject<any>[];\n};\n\n/**\n * Handler wrapper for subscription events; extracts space and objects.\n *\n * To test:\n * ```\n * curl -s -X POST -H \"Content-Type: application/json\" --data '{\"space\": \"0446...1cbb\"}' http://localhost:7100/dev/email-extractor\n * ```\n *\n * NOTE: Get space key from devtools or `dx space list --json`\n */\n// TODO(burdon): Evolve into plugin definition like Composer.\nexport const subscriptionHandler = <TMeta>(\n handler: FunctionHandler<SubscriptionData, TMeta>,\n types?: S.Schema
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema as S } from 'effect';\nimport { type Effect } from 'effect';\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space, type SpaceId } from '@dxos/client/echo';\nimport type { CoreDatabase, EchoDatabase, ReactiveEchoObject } from '@dxos/echo-db';\nimport { type HasId } from '@dxos/echo-schema';\nimport { type DXN } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type QueryResult } from '@dxos/protocols';\nimport { isNonNullable } from '@dxos/util';\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\n// https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n\n/**\n * Function handler.\n */\nexport type FunctionHandler<TData = {}, TMeta = {}, TOutput = any> = (params: {\n context: FunctionContext;\n event: FunctionEvent<TData, TMeta>;\n /**\n * @deprecated\n */\n response: FunctionResponse;\n}) => TOutput | Promise<TOutput> | Effect.Effect<TOutput, any>;\n\n/**\n * Function context.\n */\nexport interface FunctionContext {\n getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;\n\n /**\n * Space from which the function was invoked.\n */\n space: SpaceAPI | undefined;\n\n ai: FunctionContextAi;\n\n /**\n * @deprecated\n */\n // TODO(burdon): Limit access to individual space.\n client: Client;\n /**\n * @deprecated\n */\n // TODO(burdon): Replace with storage service abstraction.\n dataDir?: string;\n}\n\nexport interface FunctionContextAi {\n // TODO(dmaretskyi): Refer to cloudflare AI docs for more comprehensive typedefs.\n run(model: string, inputs: any, options?: any): Promise<any>;\n}\n\n/**\n * Event payload.\n */\n// TODO(dmaretskyi): Update type definitions to match the actual payload.\nexport type FunctionEvent<TData = {}, TMeta = {}> = {\n data: FunctionEventMeta<TMeta> & TData;\n};\n\n/**\n * Metadata from trigger.\n */\nexport type FunctionEventMeta<TMeta = {}> = {\n meta: TMeta;\n};\n\n/**\n * Function response.\n */\nexport type FunctionResponse = {\n status(code: number): FunctionResponse;\n};\n\n//\n// API.\n//\n\n// TODO(dmaretskyi): Temporary API to get the queues working.\n// TODO(dmaretskyi): To be replaced with integrating queues into echo.\nexport interface QueuesAPI {\n queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;\n}\n\n/**\n * Space interface available to functions.\n */\nexport interface SpaceAPI {\n get id(): SpaceId;\n /**\n * @deprecated\n */\n get crud(): CoreDatabase;\n get db(): EchoDatabase;\n // TODO(dmaretskyi): Align with echo api --- queues.get(id).append(items);\n get queues(): QueuesAPI;\n}\n\n// TODO(wittjosiah): Fix this.\nconst __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {\n // const _: SpaceAPI = {} as Space;\n};\n\nexport type FunctionDefinition = {\n description?: string;\n inputSchema: S.Schema.AnyNoContext;\n outputSchema?: S.Schema.AnyNoContext;\n handler: FunctionHandler<any>;\n};\n\nexport type DefineFunctionParams<T, O = any> = {\n description?: string;\n inputSchema: S.Schema<T, any>;\n outputSchema?: S.Schema<O, any>;\n handler: FunctionHandler<T, any, O>;\n};\n\n// TODO(dmaretskyi): Bind input type to function handler.\nexport const defineFunction = <T, O>(params: DefineFunctionParams<T, O>): FunctionDefinition => {\n if (!S.isSchema(params.inputSchema)) {\n throw new Error('Input schema must be a valid schema');\n }\n if (typeof params.handler !== 'function') {\n throw new Error('Handler must be a function');\n }\n\n return {\n description: params.description,\n inputSchema: params.inputSchema,\n outputSchema: params.outputSchema ?? S.Any,\n handler: params.handler,\n };\n};\n\n//\n// Subscription utils.\n//\n\nexport type RawSubscriptionData = {\n spaceKey?: string;\n objects?: string[];\n};\n\nexport type SubscriptionData = {\n space?: Space;\n objects?: ReactiveEchoObject<any>[];\n};\n\n/**\n * Handler wrapper for subscription events; extracts space and objects.\n *\n * To test:\n * ```\n * curl -s -X POST -H \"Content-Type: application/json\" --data '{\"space\": \"0446...1cbb\"}' http://localhost:7100/dev/email-extractor\n * ```\n *\n * NOTE: Get space key from devtools or `dx space list --json`\n */\n// TODO(burdon): Evolve into plugin definition like Composer.\nexport const subscriptionHandler = <TMeta>(\n handler: FunctionHandler<SubscriptionData, TMeta>,\n types?: S.Schema.AnyNoContext[],\n): FunctionHandler<RawSubscriptionData, TMeta> => {\n return async ({ event: { data }, context, response, ...rest }) => {\n const { client } = context;\n const space = data.spaceKey ? client.spaces.get(PublicKey.from(data.spaceKey)) : undefined;\n if (!space) {\n log.error('Invalid space');\n return response.status(500);\n }\n\n registerTypes(space, types);\n const objects = space\n ? data.objects\n ?.map<ReactiveEchoObject<any> | undefined>((id) => space!.db.getObjectById(id))\n .filter(isNonNullable)\n : [];\n\n if (!!data.spaceKey && !space) {\n log.warn('invalid space', { data });\n } else {\n log.info('handler', { space: space?.key.truncate(), objects: objects?.length });\n }\n\n return handler({ event: { data: { ...data, space, objects } }, context, response, ...rest });\n };\n};\n\n// TODO(burdon): Evolve types as part of function metadata.\nconst registerTypes = (space: Space, types: S.Schema.AnyNoContext[] = []) => {\n const registry = space.db.graph.schemaRegistry;\n for (const type of types) {\n if (!registry.hasSchema(type)) {\n registry.addSchema([type]);\n }\n }\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAASA,UAAUC,SAAS;AAG5B,SAAsBC,iBAAiB;AAKvC,SAASC,WAAW;AAEpB,SAASC,qBAAqB;;AAoHvB,IAAMC,iBAAiB,CAAOC,WAAAA;AACnC,MAAI,CAACC,EAAEC,SAASF,OAAOG,WAAW,GAAG;AACnC,UAAM,IAAIC,MAAM,qCAAA;EAClB;AACA,MAAI,OAAOJ,OAAOK,YAAY,YAAY;AACxC,UAAM,IAAID,MAAM,4BAAA;EAClB;AAEA,SAAO;IACLE,aAAaN,OAAOM;IACpBH,aAAaH,OAAOG;IACpBI,cAAcP,OAAOO,gBAAgBN,EAAEO;IACvCH,SAASL,OAAOK;EAClB;AACF;AA2BO,IAAMI,sBAAsB,CACjCJ,SACAK,UAAAA;AAEA,SAAO,OAAO,EAAEC,OAAO,EAAEC,KAAI,GAAIC,SAASC,UAAU,GAAGC,KAAAA,MAAM;AAC3D,UAAM,EAAEC,OAAM,IAAKH;AACnB,UAAMI,QAAQL,KAAKM,WAAWF,OAAOG,OAAOC,IAAIC,UAAUC,KAAKV,KAAKM,QAAQ,CAAA,IAAKK;AACjF,QAAI,CAACN,OAAO;AACVO,UAAIC,MAAM,iBAAA,QAAA;;;;;;AACV,aAAOX,SAASY,OAAO,GAAA;IACzB;AAEAC,kBAAcV,OAAOP,KAAAA;AACrB,UAAMkB,UAAUX,QACZL,KAAKgB,SACDC,IAAyC,CAACC,OAAOb,MAAOc,GAAGC,cAAcF,EAAAA,CAAAA,EAC1EG,OAAOC,aAAAA,IACV,CAAA;AAEJ,QAAI,CAAC,CAACtB,KAAKM,YAAY,CAACD,OAAO;AAC7BO,UAAIW,KAAK,iBAAiB;QAAEvB;MAAK,GAAA;;;;;;IACnC,OAAO;AACLY,UAAIY,KAAK,WAAW;QAAEnB,OAAOA,OAAOoB,IAAIC,SAAAA;QAAYV,SAASA,SAASW;MAAO,GAAA;;;;;;IAC/E;AAEA,WAAOlC,QAAQ;MAAEM,OAAO;QAAEC,MAAM;UAAE,GAAGA;UAAMK;UAAOW;QAAQ;MAAE;MAAGf;MAASC;MAAU,GAAGC;IAAK,CAAA;EAC5F;AACF;AAGA,IAAMY,gBAAgB,CAACV,OAAcP,QAAiC,CAAA,MAAE;AACtE,QAAM8B,WAAWvB,MAAMc,GAAGU,MAAMC;AAChC,aAAWC,QAAQjC,OAAO;AACxB,QAAI,CAAC8B,SAASI,UAAUD,IAAAA,GAAO;AAC7BH,eAASK,UAAU;QAACF;OAAK;IAC3B;EACF;AACF;",
|
|
6
6
|
"names": ["Schema", "S", "PublicKey", "log", "isNonNullable", "defineFunction", "params", "S", "isSchema", "inputSchema", "Error", "handler", "description", "outputSchema", "Any", "subscriptionHandler", "types", "event", "data", "context", "response", "rest", "client", "space", "spaceKey", "spaces", "get", "PublicKey", "from", "undefined", "log", "error", "status", "registerTypes", "objects", "map", "id", "db", "getObjectById", "filter", "isNonNullable", "warn", "info", "key", "truncate", "length", "registry", "graph", "schemaRegistry", "type", "hasSchema", "addSchema"]
|
|
7
7
|
}
|