@dxos/functions 0.8.2-main.2f9c567 → 0.8.2-main.36232bc
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/bundler/index.mjs +3 -0
- package/dist/lib/browser/bundler/index.mjs.map +1 -1
- package/dist/lib/browser/chunk-2YE6S7XY.mjs +360 -0
- package/dist/lib/browser/chunk-2YE6S7XY.mjs.map +7 -0
- package/dist/lib/browser/chunk-7CHDHCV3.mjs +482 -0
- package/dist/lib/browser/chunk-7CHDHCV3.mjs.map +7 -0
- package/dist/lib/browser/chunk-LT4LR4VU.mjs +72 -0
- package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +7 -0
- package/dist/lib/browser/chunk-XRCXIG74.mjs +12 -0
- package/dist/lib/browser/chunk-XRCXIG74.mjs.map +7 -0
- package/dist/lib/browser/edge/index.mjs +7 -63
- package/dist/lib/browser/edge/index.mjs.map +4 -4
- package/dist/lib/browser/index.mjs +99 -367
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +670 -0
- package/dist/lib/browser/testing/index.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +51 -0
- package/dist/lib/browser/types/index.mjs.map +7 -0
- package/dist/lib/node/bundler/index.cjs +1 -0
- package/dist/lib/node/bundler/index.cjs.map +1 -1
- package/dist/lib/node/chunk-FBIUZ7SD.cjs +496 -0
- package/dist/lib/node/chunk-FBIUZ7SD.cjs.map +7 -0
- package/dist/lib/node/chunk-JEQ2X3Z6.cjs +34 -0
- package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +7 -0
- package/dist/lib/node/chunk-NXZNXVT3.cjs +94 -0
- package/dist/lib/node/chunk-NXZNXVT3.cjs.map +7 -0
- package/dist/lib/node/chunk-SV5NRE5L.cjs +395 -0
- package/dist/lib/node/chunk-SV5NRE5L.cjs.map +7 -0
- package/dist/lib/node/edge/index.cjs +5 -65
- package/dist/lib/node/edge/index.cjs.map +4 -4
- package/dist/lib/node/index.cjs +94 -382
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +687 -0
- package/dist/lib/node/testing/index.cjs.map +7 -0
- package/dist/lib/node/types/index.cjs +72 -0
- package/dist/lib/node/types/index.cjs.map +7 -0
- package/dist/lib/node-esm/bundler/index.mjs +1 -0
- package/dist/lib/node-esm/bundler/index.mjs.map +1 -1
- package/dist/lib/node-esm/chunk-3XMJFSID.mjs +360 -0
- package/dist/lib/node-esm/chunk-3XMJFSID.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-C6YINTWG.mjs +482 -0
- package/dist/lib/node-esm/chunk-C6YINTWG.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +12 -0
- package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +72 -0
- package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +7 -0
- package/dist/lib/node-esm/edge/index.mjs +6 -64
- package/dist/lib/node-esm/edge/index.mjs.map +4 -4
- package/dist/lib/node-esm/index.mjs +97 -367
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +670 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +51 -0
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/browser/index.d.ts +2 -0
- package/dist/types/src/browser/index.d.ts.map +1 -0
- package/dist/types/src/edge/index.d.ts.map +1 -1
- package/dist/types/src/function/function-registry.d.ts +25 -0
- package/dist/types/src/function/function-registry.d.ts.map +1 -0
- package/dist/types/src/function/function-registry.test.d.ts +2 -0
- package/dist/types/src/function/function-registry.test.d.ts.map +1 -0
- package/dist/types/src/function/index.d.ts +2 -0
- package/dist/types/src/function/index.d.ts.map +1 -0
- package/dist/types/src/handler.d.ts +61 -12
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +3 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/runtime/dev-server.d.ts +52 -0
- package/dist/types/src/runtime/dev-server.d.ts.map +1 -0
- package/dist/types/src/runtime/dev-server.test.d.ts +2 -0
- package/dist/types/src/runtime/dev-server.test.d.ts.map +1 -0
- package/dist/types/src/runtime/index.d.ts +3 -0
- package/dist/types/src/runtime/index.d.ts.map +1 -0
- package/dist/types/src/runtime/scheduler.d.ts +34 -0
- package/dist/types/src/runtime/scheduler.d.ts.map +1 -0
- package/dist/types/src/runtime/scheduler.test.d.ts +2 -0
- package/dist/types/src/runtime/scheduler.test.d.ts.map +1 -0
- package/dist/types/src/testing/functions-integration.test.d.ts +2 -0
- package/dist/types/src/testing/functions-integration.test.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +5 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/manifest.d.ts +3 -0
- package/dist/types/src/testing/manifest.d.ts.map +1 -0
- package/dist/types/src/testing/plugin-init.d.ts +6 -0
- package/dist/types/src/testing/plugin-init.d.ts.map +1 -0
- package/dist/types/src/testing/setup.d.ts +15 -0
- package/dist/types/src/testing/setup.d.ts.map +1 -0
- package/dist/types/src/testing/test/handler.d.ts +4 -0
- package/dist/types/src/testing/test/handler.d.ts.map +1 -0
- package/dist/types/src/testing/test/index.d.ts +3 -0
- package/dist/types/src/testing/test/index.d.ts.map +1 -0
- package/dist/types/src/testing/types.d.ts +10 -0
- package/dist/types/src/testing/types.d.ts.map +1 -0
- package/dist/types/src/testing/util.d.ts +5 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/src/trigger/index.d.ts +3 -0
- package/dist/types/src/trigger/index.d.ts.map +1 -0
- package/dist/types/src/trigger/trigger-registry.d.ts +38 -0
- package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -0
- package/dist/types/src/trigger/trigger-registry.test.d.ts +2 -0
- package/dist/types/src/trigger/trigger-registry.test.d.ts.map +1 -0
- package/dist/types/src/trigger/type/index.d.ts +3 -0
- package/dist/types/src/trigger/type/index.d.ts.map +1 -0
- package/dist/types/src/trigger/type/subscription-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -0
- package/dist/types/src/trigger/type/timer-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -0
- package/dist/types/src/trigger/type/webhook-trigger.d.ts +4 -0
- package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +5 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/schema.d.ts +53 -0
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/types/trace.d.ts +146 -0
- package/dist/types/src/types/trace.d.ts.map +1 -0
- package/dist/types/src/{types.d.ts → types/types.d.ts} +49 -191
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tools/schema.d.ts +2 -0
- package/dist/types/tools/schema.d.ts.map +1 -0
- package/package.json +36 -20
- package/schema/functions.json +211 -0
- package/src/browser/index.ts +5 -0
- package/src/edge/index.ts +0 -4
- package/src/function/function-registry.test.ts +118 -0
- package/src/function/function-registry.ts +104 -0
- package/src/function/index.ts +5 -0
- package/src/handler.ts +118 -14
- package/src/index.ts +5 -4
- package/src/runtime/dev-server.test.ts +79 -0
- package/src/runtime/dev-server.ts +240 -0
- package/src/runtime/index.ts +6 -0
- package/src/runtime/scheduler.test.ts +152 -0
- package/src/runtime/scheduler.ts +170 -0
- package/src/testing/functions-integration.test.ts +65 -0
- package/src/testing/index.ts +8 -0
- package/src/testing/manifest.ts +15 -0
- package/src/testing/plugin-init.ts +20 -0
- package/src/testing/setup.ts +109 -0
- package/src/testing/test/handler.ts +15 -0
- package/src/testing/test/index.ts +7 -0
- package/src/testing/types.ts +9 -0
- package/src/testing/util.ts +26 -0
- package/src/translations.ts +1 -1
- package/src/trigger/index.ts +6 -0
- package/src/trigger/trigger-registry.test.ts +278 -0
- package/src/trigger/trigger-registry.ts +218 -0
- package/src/trigger/type/index.ts +7 -0
- package/src/trigger/type/subscription-trigger.ts +84 -0
- package/src/trigger/type/timer-trigger.ts +48 -0
- package/src/trigger/type/webhook-trigger.ts +48 -0
- package/src/types/index.ts +8 -0
- package/src/types/schema.ts +46 -0
- package/src/{trace.ts → types/trace.ts} +31 -33
- package/src/types/types.ts +163 -0
- package/dist/types/src/schema.d.ts +0 -57
- package/dist/types/src/schema.d.ts.map +0 -1
- package/dist/types/src/trace.d.ts +0 -148
- package/dist/types/src/trace.d.ts.map +0 -1
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/schema.ts +0 -53
- package/src/types.ts +0 -214
- /package/dist/types/src/{url.d.ts → types/url.d.ts} +0 -0
- /package/src/{url.ts → types/url.ts} +0 -0
|
@@ -1,66 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const edgeUrl = client.config.values.runtime?.services?.edge?.url;
|
|
9
|
-
invariant(edgeUrl, "Edge is not configured.", {
|
|
10
|
-
F: __dxlog_file,
|
|
11
|
-
L: 33,
|
|
12
|
-
S: void 0,
|
|
13
|
-
A: [
|
|
14
|
-
"edgeUrl",
|
|
15
|
-
"'Edge is not configured.'"
|
|
16
|
-
]
|
|
17
|
-
});
|
|
18
|
-
const edgeClient = new EdgeHttpClient(edgeUrl);
|
|
19
|
-
const edgeIdentity = createEdgeIdentity(client);
|
|
20
|
-
edgeClient.setIdentity(edgeIdentity);
|
|
21
|
-
const response = await edgeClient.uploadFunction({
|
|
22
|
-
spaceId,
|
|
23
|
-
functionId
|
|
24
|
-
}, {
|
|
25
|
-
name,
|
|
26
|
-
version,
|
|
27
|
-
script: source
|
|
28
|
-
});
|
|
29
|
-
log.info("Uploaded", {
|
|
30
|
-
identityKey: edgeIdentity.identityKey,
|
|
31
|
-
functionId,
|
|
32
|
-
name,
|
|
33
|
-
source: source.length,
|
|
34
|
-
response
|
|
35
|
-
}, {
|
|
36
|
-
F: __dxlog_file,
|
|
37
|
-
L: 40,
|
|
38
|
-
S: void 0,
|
|
39
|
-
C: (f, a) => f(...a)
|
|
40
|
-
});
|
|
41
|
-
return response;
|
|
42
|
-
};
|
|
43
|
-
var incrementSemverPatch = (version) => {
|
|
44
|
-
const [major, minor, patch] = version.split(".");
|
|
45
|
-
const patchNum = Number(patch);
|
|
46
|
-
invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`, {
|
|
47
|
-
F: __dxlog_file,
|
|
48
|
-
L: 54,
|
|
49
|
-
S: void 0,
|
|
50
|
-
A: [
|
|
51
|
-
"!Number.isNaN(patchNum)",
|
|
52
|
-
"`Unexpected function version format: ${version}`"
|
|
53
|
-
]
|
|
54
|
-
});
|
|
55
|
-
return [
|
|
56
|
-
major,
|
|
57
|
-
minor,
|
|
58
|
-
String(patchNum + 1)
|
|
59
|
-
].join(".");
|
|
60
|
-
};
|
|
61
|
-
var publicKeyToDid = (key) => {
|
|
62
|
-
return `did:key:${key.toHex()}`;
|
|
63
|
-
};
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
import {
|
|
3
|
+
incrementSemverPatch,
|
|
4
|
+
publicKeyToDid,
|
|
5
|
+
uploadWorkerFunction
|
|
6
|
+
} from "../chunk-LT4LR4VU.mjs";
|
|
7
|
+
import "../chunk-XRCXIG74.mjs";
|
|
64
8
|
export {
|
|
65
9
|
incrementSemverPatch,
|
|
66
10
|
publicKeyToDid,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": [
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
3
|
+
"sources": [],
|
|
4
|
+
"sourcesContent": [],
|
|
5
|
+
"mappings": "",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,47 @@
|
|
|
1
|
+
import "@dxos/node-std/globals";
|
|
2
|
+
import {
|
|
3
|
+
incrementSemverPatch,
|
|
4
|
+
publicKeyToDid,
|
|
5
|
+
uploadWorkerFunction
|
|
6
|
+
} from "./chunk-LT4LR4VU.mjs";
|
|
7
|
+
import {
|
|
8
|
+
FunctionRegistry,
|
|
9
|
+
TriggerRegistry,
|
|
10
|
+
createSubscriptionTrigger,
|
|
11
|
+
createTimerTrigger
|
|
12
|
+
} from "./chunk-7CHDHCV3.mjs";
|
|
13
|
+
import {
|
|
14
|
+
FUNCTIONS_PRESET_META_KEY,
|
|
15
|
+
FUNCTION_TYPES,
|
|
16
|
+
FunctionDef,
|
|
17
|
+
FunctionManifestSchema,
|
|
18
|
+
FunctionTrigger,
|
|
19
|
+
FunctionTriggerSchema,
|
|
20
|
+
FunctionType,
|
|
21
|
+
InvocationOutcome,
|
|
22
|
+
InvocationTraceEndEvent,
|
|
23
|
+
InvocationTraceEventType,
|
|
24
|
+
InvocationTraceStartEvent,
|
|
25
|
+
ScriptType,
|
|
26
|
+
TraceEvent,
|
|
27
|
+
TraceEventException,
|
|
28
|
+
TraceEventLog,
|
|
29
|
+
TriggerKind,
|
|
30
|
+
TriggerSchema,
|
|
31
|
+
createInvocationSpans,
|
|
32
|
+
getInvocationUrl,
|
|
33
|
+
getUserFunctionUrlInMetadata,
|
|
34
|
+
makeFunctionUrl,
|
|
35
|
+
setUserFunctionUrlInMetadata
|
|
36
|
+
} from "./chunk-2YE6S7XY.mjs";
|
|
37
|
+
import "./chunk-XRCXIG74.mjs";
|
|
38
|
+
|
|
1
39
|
// packages/core/functions/src/handler.ts
|
|
2
40
|
import { Schema as S } from "effect";
|
|
41
|
+
import { PublicKey } from "@dxos/client";
|
|
42
|
+
import { log } from "@dxos/log";
|
|
43
|
+
import { isNonNullable } from "@dxos/util";
|
|
44
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/handler.ts";
|
|
3
45
|
var defineFunction = (params) => {
|
|
4
46
|
if (!S.isSchema(params.inputSchema)) {
|
|
5
47
|
throw new Error("Input schema must be a valid schema");
|
|
@@ -14,384 +56,71 @@ var defineFunction = (params) => {
|
|
|
14
56
|
handler: params.handler
|
|
15
57
|
};
|
|
16
58
|
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}).annotations({
|
|
30
|
-
[LabelAnnotationId]: "name"
|
|
31
|
-
}).pipe(EchoObject({
|
|
32
|
-
typename: "dxos.org/type/Script",
|
|
33
|
-
version: "0.1.0"
|
|
34
|
-
}));
|
|
35
|
-
var FunctionType = class extends TypedObject({
|
|
36
|
-
typename: "dxos.org/type/Function",
|
|
37
|
-
version: "0.1.0"
|
|
38
|
-
})({
|
|
39
|
-
// TODO(burdon): Rename to id/uri?
|
|
40
|
-
name: Schema.NonEmptyString,
|
|
41
|
-
version: Schema.String,
|
|
42
|
-
description: Schema.optional(Schema.String),
|
|
43
|
-
// Reference to a source script if it exists within ECHO.
|
|
44
|
-
// TODO(burdon): Don't ref ScriptType directly (core).
|
|
45
|
-
source: Schema.optional(Ref(ScriptType)),
|
|
46
|
-
inputSchema: Schema.optional(JsonSchemaType),
|
|
47
|
-
outputSchema: Schema.optional(JsonSchemaType),
|
|
48
|
-
// Local binding to a function name.
|
|
49
|
-
binding: Schema.optional(Schema.String)
|
|
50
|
-
}) {
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// packages/core/functions/src/trace.ts
|
|
54
|
-
import { Schema as Schema2 } from "effect";
|
|
55
|
-
import { EchoObject as EchoObject2, Expando as Expando2, ObjectId, Ref as Ref3 } from "@dxos/echo-schema";
|
|
56
|
-
import { log } from "@dxos/log";
|
|
57
|
-
|
|
58
|
-
// packages/core/functions/src/types.ts
|
|
59
|
-
import { Schema as S2, SchemaAST } from "effect";
|
|
60
|
-
import { Expando, OptionsAnnotationId, TypedObject as TypedObject2, DXN, Ref as Ref2, RawObject } from "@dxos/echo-schema";
|
|
61
|
-
var TriggerKind;
|
|
62
|
-
(function(TriggerKind2) {
|
|
63
|
-
TriggerKind2["Timer"] = "timer";
|
|
64
|
-
TriggerKind2["Webhook"] = "webhook";
|
|
65
|
-
TriggerKind2["Subscription"] = "subscription";
|
|
66
|
-
TriggerKind2["Email"] = "email";
|
|
67
|
-
TriggerKind2["Queue"] = "queue";
|
|
68
|
-
})(TriggerKind || (TriggerKind = {}));
|
|
69
|
-
var typeLiteralAnnotations = {
|
|
70
|
-
[SchemaAST.TitleAnnotationId]: "Type"
|
|
71
|
-
};
|
|
72
|
-
var TimerTriggerSchema = S2.Struct({
|
|
73
|
-
type: S2.Literal("timer").annotations(typeLiteralAnnotations),
|
|
74
|
-
cron: S2.String.annotations({
|
|
75
|
-
[SchemaAST.TitleAnnotationId]: "Cron",
|
|
76
|
-
[SchemaAST.ExamplesAnnotationId]: [
|
|
77
|
-
"0 0 * * *"
|
|
78
|
-
]
|
|
79
|
-
})
|
|
80
|
-
}).pipe(S2.mutable);
|
|
81
|
-
var EmailTriggerSchema = S2.Struct({
|
|
82
|
-
type: S2.Literal("email").annotations(typeLiteralAnnotations)
|
|
83
|
-
}).pipe(S2.mutable);
|
|
84
|
-
var QueueTriggerSchema = S2.Struct({
|
|
85
|
-
type: S2.Literal("queue").annotations(typeLiteralAnnotations),
|
|
86
|
-
queue: DXN
|
|
87
|
-
}).pipe(S2.mutable);
|
|
88
|
-
var WebhookTriggerSchema = S2.Struct({
|
|
89
|
-
type: S2.Literal("webhook").annotations(typeLiteralAnnotations),
|
|
90
|
-
method: S2.optional(S2.String.annotations({
|
|
91
|
-
[SchemaAST.TitleAnnotationId]: "Method",
|
|
92
|
-
[OptionsAnnotationId]: [
|
|
93
|
-
"GET",
|
|
94
|
-
"POST"
|
|
95
|
-
]
|
|
96
|
-
})),
|
|
97
|
-
port: S2.optional(S2.Number.annotations({
|
|
98
|
-
[SchemaAST.TitleAnnotationId]: "Port"
|
|
99
|
-
}))
|
|
100
|
-
}).pipe(S2.mutable);
|
|
101
|
-
var QuerySchema = S2.Struct({
|
|
102
|
-
type: S2.optional(S2.String.annotations({
|
|
103
|
-
[SchemaAST.TitleAnnotationId]: "Type"
|
|
104
|
-
})),
|
|
105
|
-
props: S2.optional(S2.Record({
|
|
106
|
-
key: S2.String,
|
|
107
|
-
value: S2.Any
|
|
108
|
-
}))
|
|
109
|
-
}).annotations({
|
|
110
|
-
[SchemaAST.TitleAnnotationId]: "Query"
|
|
111
|
-
});
|
|
112
|
-
var SubscriptionTriggerSchema = S2.Struct({
|
|
113
|
-
type: S2.Literal("subscription").annotations(typeLiteralAnnotations),
|
|
114
|
-
// TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
|
|
115
|
-
filter: QuerySchema,
|
|
116
|
-
options: S2.optional(S2.Struct({
|
|
117
|
-
// Watch changes to object (not just creation).
|
|
118
|
-
deep: S2.optional(S2.Boolean.annotations({
|
|
119
|
-
[SchemaAST.TitleAnnotationId]: "Nested"
|
|
120
|
-
})),
|
|
121
|
-
// Debounce changes (delay in ms).
|
|
122
|
-
delay: S2.optional(S2.Number.annotations({
|
|
123
|
-
[SchemaAST.TitleAnnotationId]: "Delay"
|
|
124
|
-
}))
|
|
125
|
-
}).annotations({
|
|
126
|
-
[SchemaAST.TitleAnnotationId]: "Options"
|
|
127
|
-
}))
|
|
128
|
-
}).pipe(S2.mutable);
|
|
129
|
-
var TriggerSchema = S2.Union(TimerTriggerSchema, WebhookTriggerSchema, SubscriptionTriggerSchema, EmailTriggerSchema, QueueTriggerSchema).annotations({
|
|
130
|
-
[SchemaAST.TitleAnnotationId]: "Trigger"
|
|
131
|
-
});
|
|
132
|
-
var EmailTriggerOutput = S2.mutable(S2.Struct({
|
|
133
|
-
from: S2.String,
|
|
134
|
-
to: S2.String,
|
|
135
|
-
subject: S2.String,
|
|
136
|
-
created: S2.String,
|
|
137
|
-
body: S2.String
|
|
138
|
-
}));
|
|
139
|
-
var WebhookTriggerOutput = S2.mutable(S2.Struct({
|
|
140
|
-
url: S2.String,
|
|
141
|
-
method: S2.Literal("GET", "POST"),
|
|
142
|
-
headers: S2.Record({
|
|
143
|
-
key: S2.String,
|
|
144
|
-
value: S2.String
|
|
145
|
-
}),
|
|
146
|
-
bodyText: S2.String
|
|
147
|
-
}));
|
|
148
|
-
var QueueTriggerOutput = S2.mutable(S2.Struct({
|
|
149
|
-
queue: DXN,
|
|
150
|
-
item: S2.Any,
|
|
151
|
-
cursor: S2.String
|
|
152
|
-
}));
|
|
153
|
-
var SubscriptionTriggerOutput = S2.mutable(S2.Struct({
|
|
154
|
-
type: S2.String,
|
|
155
|
-
changedObjectId: S2.String
|
|
156
|
-
}));
|
|
157
|
-
var TimerTriggerOutput = S2.mutable(S2.Struct({
|
|
158
|
-
tick: S2.Number
|
|
159
|
-
}));
|
|
160
|
-
var FunctionTriggerSchema = S2.Struct({
|
|
161
|
-
/**
|
|
162
|
-
* Function or workflow to invoke.
|
|
163
|
-
*/
|
|
164
|
-
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
165
|
-
function: S2.optional(Ref2(Expando).annotations({
|
|
166
|
-
[SchemaAST.TitleAnnotationId]: "Function"
|
|
167
|
-
})),
|
|
168
|
-
/**
|
|
169
|
-
* Only used for workflows.
|
|
170
|
-
* Specifies the input node in the circuit.
|
|
171
|
-
* @deprecated Remove and enforce a single input node in all compute graphs.
|
|
172
|
-
*/
|
|
173
|
-
inputNodeId: S2.optional(S2.String.annotations({
|
|
174
|
-
[SchemaAST.TitleAnnotationId]: "Input Node ID"
|
|
175
|
-
})),
|
|
176
|
-
enabled: S2.optional(S2.Boolean.annotations({
|
|
177
|
-
[SchemaAST.TitleAnnotationId]: "Enabled"
|
|
178
|
-
})),
|
|
179
|
-
spec: S2.optional(TriggerSchema),
|
|
180
|
-
/**
|
|
181
|
-
* Passed as the input data to the function.
|
|
182
|
-
* Must match the function's input schema.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* {
|
|
186
|
-
* item: '{{$.trigger.event}}',
|
|
187
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
188
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
189
|
-
* }
|
|
190
|
-
*/
|
|
191
|
-
input: S2.optional(S2.mutable(S2.Record({
|
|
192
|
-
key: S2.String,
|
|
193
|
-
value: S2.Any
|
|
194
|
-
})))
|
|
195
|
-
});
|
|
196
|
-
var FunctionTrigger = class extends TypedObject2({
|
|
197
|
-
typename: "dxos.org/type/FunctionTrigger",
|
|
198
|
-
version: "0.1.0"
|
|
199
|
-
})(FunctionTriggerSchema.fields) {
|
|
200
|
-
};
|
|
201
|
-
var FunctionManifestSchema = S2.Struct({
|
|
202
|
-
functions: S2.optional(S2.mutable(S2.Array(RawObject(FunctionType)))),
|
|
203
|
-
triggers: S2.optional(S2.mutable(S2.Array(RawObject(FunctionTrigger))))
|
|
204
|
-
});
|
|
205
|
-
var FUNCTION_TYPES = [
|
|
206
|
-
FunctionType,
|
|
207
|
-
FunctionTrigger
|
|
208
|
-
];
|
|
209
|
-
|
|
210
|
-
// packages/core/functions/src/trace.ts
|
|
211
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/trace.ts";
|
|
212
|
-
var InvocationOutcome;
|
|
213
|
-
(function(InvocationOutcome2) {
|
|
214
|
-
InvocationOutcome2["SUCCESS"] = "success";
|
|
215
|
-
InvocationOutcome2["FAILURE"] = "failure";
|
|
216
|
-
InvocationOutcome2["PENDING"] = "pending";
|
|
217
|
-
})(InvocationOutcome || (InvocationOutcome = {}));
|
|
218
|
-
var InvocationTraceEventType;
|
|
219
|
-
(function(InvocationTraceEventType2) {
|
|
220
|
-
InvocationTraceEventType2["START"] = "start";
|
|
221
|
-
InvocationTraceEventType2["END"] = "end";
|
|
222
|
-
})(InvocationTraceEventType || (InvocationTraceEventType = {}));
|
|
223
|
-
var TraceEventException = Schema2.Struct({
|
|
224
|
-
timestampMs: Schema2.Number,
|
|
225
|
-
message: Schema2.String,
|
|
226
|
-
name: Schema2.String,
|
|
227
|
-
stack: Schema2.optional(Schema2.String)
|
|
228
|
-
});
|
|
229
|
-
var InvocationTraceStartEvent = Schema2.Struct({
|
|
230
|
-
/**
|
|
231
|
-
* Queue message id.
|
|
232
|
-
*/
|
|
233
|
-
id: ObjectId,
|
|
234
|
-
type: Schema2.Literal("start"),
|
|
235
|
-
/**
|
|
236
|
-
* Invocation id, the same for invocation start and end events.
|
|
237
|
-
*/
|
|
238
|
-
invocationId: ObjectId,
|
|
239
|
-
/**
|
|
240
|
-
* Event generation time.
|
|
241
|
-
*/
|
|
242
|
-
timestampMs: Schema2.Number,
|
|
243
|
-
/**
|
|
244
|
-
* Data passed to function / workflow as an argument.
|
|
245
|
-
*/
|
|
246
|
-
// TODO(burdon): Input schema?
|
|
247
|
-
input: Schema2.Object,
|
|
248
|
-
/**
|
|
249
|
-
* Queue DXN for function/workflow invocation events.
|
|
250
|
-
*/
|
|
251
|
-
// TODO(burdon): Need reference type for queue. vs. string?
|
|
252
|
-
invocationTraceQueue: Ref3(Expando2),
|
|
253
|
-
/**
|
|
254
|
-
* DXN of the invoked function/workflow.
|
|
255
|
-
*/
|
|
256
|
-
invocationTarget: Ref3(Expando2),
|
|
257
|
-
/**
|
|
258
|
-
* Present for automatic invocations.
|
|
259
|
-
*/
|
|
260
|
-
trigger: Schema2.optional(Ref3(FunctionTrigger))
|
|
261
|
-
}).pipe(EchoObject2({
|
|
262
|
-
typename: "dxos.org/type/InvocationTraceStart",
|
|
263
|
-
version: "0.1.0"
|
|
264
|
-
}));
|
|
265
|
-
var InvocationTraceEndEvent = Schema2.Struct({
|
|
266
|
-
/**
|
|
267
|
-
* Trace event id.
|
|
268
|
-
*/
|
|
269
|
-
id: ObjectId,
|
|
270
|
-
type: Schema2.Literal("end"),
|
|
271
|
-
/**
|
|
272
|
-
* Invocation id, will be the same for invocation start and end.
|
|
273
|
-
*/
|
|
274
|
-
invocationId: ObjectId,
|
|
275
|
-
/**
|
|
276
|
-
* Event generation time.
|
|
277
|
-
*/
|
|
278
|
-
// TODO(burdon): Remove ms suffix.
|
|
279
|
-
timestampMs: Schema2.Number,
|
|
280
|
-
outcome: Schema2.Enums(InvocationOutcome),
|
|
281
|
-
exception: Schema2.optional(TraceEventException)
|
|
282
|
-
}).pipe(EchoObject2({
|
|
283
|
-
typename: "dxos.org/type/InvocationTraceEnd",
|
|
284
|
-
version: "0.1.0"
|
|
285
|
-
}));
|
|
286
|
-
var TraceEventLog = Schema2.Struct({
|
|
287
|
-
timestampMs: Schema2.Number,
|
|
288
|
-
level: Schema2.String,
|
|
289
|
-
message: Schema2.String,
|
|
290
|
-
context: Schema2.optional(Schema2.Object)
|
|
291
|
-
});
|
|
292
|
-
var TraceEvent = Schema2.Struct({
|
|
293
|
-
id: ObjectId,
|
|
294
|
-
// TODO(burdon): Need enum/numeric result (not string).
|
|
295
|
-
outcome: Schema2.String,
|
|
296
|
-
truncated: Schema2.Boolean,
|
|
297
|
-
/**
|
|
298
|
-
* Time when the event was persisted.
|
|
299
|
-
*/
|
|
300
|
-
ingestionTimestampMs: Schema2.Number,
|
|
301
|
-
logs: Schema2.Array(TraceEventLog),
|
|
302
|
-
exceptions: Schema2.Array(TraceEventException)
|
|
303
|
-
}).pipe(EchoObject2({
|
|
304
|
-
typename: "dxos.org/type/TraceEvent",
|
|
305
|
-
version: "0.1.0"
|
|
306
|
-
}));
|
|
307
|
-
var createInvocationSpans = (items) => {
|
|
308
|
-
if (!items) {
|
|
309
|
-
return [];
|
|
310
|
-
}
|
|
311
|
-
const eventsByInvocationId = /* @__PURE__ */ new Map();
|
|
312
|
-
for (const event of items) {
|
|
313
|
-
if (!("invocationId" in event)) {
|
|
314
|
-
continue;
|
|
315
|
-
}
|
|
316
|
-
const invocationId = event.invocationId;
|
|
317
|
-
const entry = eventsByInvocationId.get(invocationId) || {
|
|
318
|
-
start: void 0,
|
|
319
|
-
end: void 0
|
|
320
|
-
};
|
|
321
|
-
if (event.type === "start") {
|
|
322
|
-
entry.start = event;
|
|
323
|
-
} else if (event.type === "end") {
|
|
324
|
-
entry.end = event;
|
|
59
|
+
var subscriptionHandler = (handler, types) => {
|
|
60
|
+
return async ({ event: { data }, context, response, ...rest }) => {
|
|
61
|
+
const { client } = context;
|
|
62
|
+
const space = data.spaceKey ? client.spaces.get(PublicKey.from(data.spaceKey)) : void 0;
|
|
63
|
+
if (!space) {
|
|
64
|
+
log.error("Invalid space", void 0, {
|
|
65
|
+
F: __dxlog_file,
|
|
66
|
+
L: 181,
|
|
67
|
+
S: void 0,
|
|
68
|
+
C: (f, a) => f(...a)
|
|
69
|
+
});
|
|
70
|
+
return response.status(500);
|
|
325
71
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (!start) {
|
|
332
|
-
log.warn("found end event without matching start", {
|
|
333
|
-
invocationId
|
|
72
|
+
registerTypes(space, types);
|
|
73
|
+
const objects = space ? data.objects?.map((id) => space.db.getObjectById(id)).filter(isNonNullable) : [];
|
|
74
|
+
if (!!data.spaceKey && !space) {
|
|
75
|
+
log.warn("invalid space", {
|
|
76
|
+
data
|
|
334
77
|
}, {
|
|
335
78
|
F: __dxlog_file,
|
|
336
|
-
L:
|
|
79
|
+
L: 193,
|
|
80
|
+
S: void 0,
|
|
81
|
+
C: (f, a) => f(...a)
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
log.info("handler", {
|
|
85
|
+
space: space?.key.truncate(),
|
|
86
|
+
objects: objects?.length
|
|
87
|
+
}, {
|
|
88
|
+
F: __dxlog_file,
|
|
89
|
+
L: 195,
|
|
337
90
|
S: void 0,
|
|
338
91
|
C: (f, a) => f(...a)
|
|
339
92
|
});
|
|
340
|
-
continue;
|
|
341
93
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
94
|
+
return handler({
|
|
95
|
+
event: {
|
|
96
|
+
data: {
|
|
97
|
+
...data,
|
|
98
|
+
space,
|
|
99
|
+
objects
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
context,
|
|
103
|
+
response,
|
|
104
|
+
...rest
|
|
353
105
|
});
|
|
354
|
-
}
|
|
355
|
-
return result;
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
// packages/core/functions/src/url.ts
|
|
359
|
-
var FUNCTIONS_META_KEY = "dxos.org/service/function";
|
|
360
|
-
var FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
|
|
361
|
-
var isSecure = (protocol) => {
|
|
362
|
-
return protocol === "https:" || protocol === "wss:";
|
|
363
|
-
};
|
|
364
|
-
var getUserFunctionUrlInMetadata = (meta) => {
|
|
365
|
-
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
106
|
+
};
|
|
366
107
|
};
|
|
367
|
-
var
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
if (
|
|
371
|
-
|
|
108
|
+
var registerTypes = (space, types = []) => {
|
|
109
|
+
const registry = space.db.graph.schemaRegistry;
|
|
110
|
+
for (const type of types) {
|
|
111
|
+
if (!registry.hasSchema(type)) {
|
|
112
|
+
registry.addSchema([
|
|
113
|
+
type
|
|
114
|
+
]);
|
|
372
115
|
}
|
|
373
|
-
} else {
|
|
374
|
-
meta.keys.push({
|
|
375
|
-
source: FUNCTIONS_META_KEY,
|
|
376
|
-
id: functionUrl
|
|
377
|
-
});
|
|
378
116
|
}
|
|
379
117
|
};
|
|
380
|
-
var makeFunctionUrl = (spaceId, fn) => `/${spaceId}/${fn.functionId}`;
|
|
381
|
-
var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
|
|
382
|
-
const baseUrl = new URL("functions/", edgeUrl);
|
|
383
|
-
const relativeUrl = functionUrl.replace(/^\//, "");
|
|
384
|
-
const url = new URL(`./${relativeUrl}`, baseUrl.toString());
|
|
385
|
-
options.spaceId && url.searchParams.set("spaceId", options.spaceId);
|
|
386
|
-
options.subjectId && url.searchParams.set("subjectId", options.subjectId);
|
|
387
|
-
url.protocol = isSecure(url.protocol) ? "https" : "http";
|
|
388
|
-
return url.toString();
|
|
389
|
-
};
|
|
390
118
|
export {
|
|
391
|
-
EmailTriggerOutput,
|
|
392
119
|
FUNCTIONS_PRESET_META_KEY,
|
|
393
120
|
FUNCTION_TYPES,
|
|
121
|
+
FunctionDef,
|
|
394
122
|
FunctionManifestSchema,
|
|
123
|
+
FunctionRegistry,
|
|
395
124
|
FunctionTrigger,
|
|
396
125
|
FunctionTriggerSchema,
|
|
397
126
|
FunctionType,
|
|
@@ -399,21 +128,24 @@ export {
|
|
|
399
128
|
InvocationTraceEndEvent,
|
|
400
129
|
InvocationTraceEventType,
|
|
401
130
|
InvocationTraceStartEvent,
|
|
402
|
-
QueueTriggerOutput,
|
|
403
131
|
ScriptType,
|
|
404
|
-
SubscriptionTriggerOutput,
|
|
405
|
-
TimerTriggerOutput,
|
|
406
132
|
TraceEvent,
|
|
407
133
|
TraceEventException,
|
|
408
134
|
TraceEventLog,
|
|
409
135
|
TriggerKind,
|
|
136
|
+
TriggerRegistry,
|
|
410
137
|
TriggerSchema,
|
|
411
|
-
WebhookTriggerOutput,
|
|
412
138
|
createInvocationSpans,
|
|
139
|
+
createSubscriptionTrigger,
|
|
140
|
+
createTimerTrigger,
|
|
413
141
|
defineFunction,
|
|
414
142
|
getInvocationUrl,
|
|
415
143
|
getUserFunctionUrlInMetadata,
|
|
144
|
+
incrementSemverPatch,
|
|
416
145
|
makeFunctionUrl,
|
|
417
|
-
|
|
146
|
+
publicKeyToDid,
|
|
147
|
+
setUserFunctionUrlInMetadata,
|
|
148
|
+
subscriptionHandler,
|
|
149
|
+
uploadWorkerFunction
|
|
418
150
|
};
|
|
419
151
|
//# sourceMappingURL=index.mjs.map
|