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