@dxos/functions 0.8.1-main.ba2dec9 → 0.8.1-staging.5be625a
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-UMJKVIP4.mjs → chunk-B747D6L6.mjs} +5 -27
- package/dist/lib/browser/chunk-B747D6L6.mjs.map +7 -0
- package/dist/lib/browser/{chunk-RTBBW6RI.mjs → chunk-LHCAYQLL.mjs} +89 -17
- package/dist/lib/browser/chunk-LHCAYQLL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-M7ZGVWUZ.mjs → chunk-OREUICVD.mjs} +2 -2
- 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-UHTKCFWT.cjs → chunk-D4T2DS7U.cjs} +9 -31
- package/dist/lib/node/chunk-D4T2DS7U.cjs.map +7 -0
- package/dist/lib/node/{chunk-GX3ZLNHY.cjs → chunk-UQZH4J6S.cjs} +93 -18
- package/dist/lib/node/chunk-UQZH4J6S.cjs.map +7 -0
- package/dist/lib/node/{chunk-AOKUMNKK.cjs → chunk-ZSHBAXJA.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-JDOIALGL.mjs → chunk-D43PP2YW.mjs} +5 -27
- package/dist/lib/node-esm/chunk-D43PP2YW.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NALEEAQL.mjs → chunk-YCBKVXQU.mjs} +89 -17
- package/dist/lib/node-esm/chunk-YCBKVXQU.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-BYS52HOC.mjs → chunk-ZX523EY4.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.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 +100 -95
- package/dist/types/src/types/trace.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/edge/functions.ts +2 -21
- package/src/handler.ts +2 -2
- package/src/runtime/scheduler.test.ts +2 -1
- package/src/types/schema.ts +8 -6
- package/src/types/trace.ts +94 -7
- 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-OREUICVD.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-AOKUMNKK.cjs.map → chunk-ZSHBAXJA.cjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-BYS52HOC.mjs.map → chunk-ZX523EY4.mjs.map} +0 -0
|
@@ -1,65 +1,50 @@
|
|
|
1
1
|
import { Expando, Ref, S } from '@dxos/echo-schema';
|
|
2
|
+
import { type FunctionTriggerType } from './types';
|
|
2
3
|
export declare enum InvocationOutcome {
|
|
3
4
|
SUCCESS = "success",
|
|
4
5
|
FAILURE = "failure"
|
|
5
6
|
}
|
|
7
|
+
export declare enum InvocationTraceEventType {
|
|
8
|
+
START = "start",
|
|
9
|
+
END = "end"
|
|
10
|
+
}
|
|
6
11
|
export declare const TraceEventException: S.Struct<{
|
|
7
12
|
timestampMs: typeof S.Number;
|
|
8
13
|
message: typeof S.String;
|
|
9
14
|
name: typeof S.String;
|
|
10
15
|
stack: S.optional<typeof S.String>;
|
|
11
16
|
}>;
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
type: S.Literal<[import("./types").TriggerKind.Queue]>;
|
|
44
|
-
queue: S.refine<string, typeof S.NonEmptyString>;
|
|
45
|
-
}>>]>>;
|
|
46
|
-
readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
47
|
-
}, import("@dxos/echo-schema").TypedObjectOptions>> | undefined;
|
|
48
|
-
exception?: {
|
|
49
|
-
readonly name: string;
|
|
50
|
-
readonly timestampMs: number;
|
|
51
|
-
readonly message: string;
|
|
52
|
-
readonly stack?: string | undefined;
|
|
53
|
-
} | undefined;
|
|
54
|
-
}, {
|
|
55
|
-
readonly id: string;
|
|
56
|
-
timestampMs: number;
|
|
57
|
-
outcome: InvocationOutcome;
|
|
58
|
-
input: object;
|
|
59
|
-
durationMs: number;
|
|
60
|
-
invocationTraceQueue: Ref<Expando>;
|
|
61
|
-
invocationTarget: Ref<Expando>;
|
|
62
|
-
trigger?: Ref<import("@dxos/echo-schema").TypedObjectFields<{
|
|
17
|
+
export type TraceEventException = S.Schema.Type<typeof TraceEventException>;
|
|
18
|
+
export declare const InvocationTraceStartEvent: import("@dxos/echo-schema").EchoObjectSchema<S.Struct<{
|
|
19
|
+
/**
|
|
20
|
+
* Queue message id.
|
|
21
|
+
*/
|
|
22
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
23
|
+
type: S.Literal<[InvocationTraceEventType.START]>;
|
|
24
|
+
/**
|
|
25
|
+
* Invocation id, the same for invocation start and end events.
|
|
26
|
+
*/
|
|
27
|
+
invocationId: import("@dxos/echo-schema").ObjectIdClass;
|
|
28
|
+
/**
|
|
29
|
+
* Event generation time.
|
|
30
|
+
*/
|
|
31
|
+
timestampMs: typeof S.Number;
|
|
32
|
+
/**
|
|
33
|
+
* Data passed to function / workflow as an argument.
|
|
34
|
+
*/
|
|
35
|
+
input: typeof S.Object;
|
|
36
|
+
/**
|
|
37
|
+
* Queue DXN for function/workflow invocation events.
|
|
38
|
+
*/
|
|
39
|
+
invocationTraceQueue: import("@dxos/echo-schema").Ref$<Expando>;
|
|
40
|
+
/**
|
|
41
|
+
* DXN of the invoked function/workflow.
|
|
42
|
+
*/
|
|
43
|
+
invocationTarget: import("@dxos/echo-schema").Ref$<Expando>;
|
|
44
|
+
/**
|
|
45
|
+
* Present for automatic invocations.
|
|
46
|
+
*/
|
|
47
|
+
trigger: S.optional<import("@dxos/echo-schema").Ref$<import("@dxos/echo-schema").TypedObjectFields<{
|
|
63
48
|
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
64
49
|
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
65
50
|
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
@@ -86,55 +71,75 @@ export declare const InvocationTraceEvent: S.Schema<{
|
|
|
86
71
|
queue: S.refine<string, typeof S.NonEmptyString>;
|
|
87
72
|
}>>]>>;
|
|
88
73
|
readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
89
|
-
}, import("@dxos/echo-schema").TypedObjectOptions
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
74
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>>>;
|
|
75
|
+
}>>;
|
|
76
|
+
export type InvocationTraceStartEvent = S.Schema.Type<typeof InvocationTraceStartEvent>;
|
|
77
|
+
export declare const InvocationTraceEndEvent: import("@dxos/echo-schema").EchoObjectSchema<S.Struct<{
|
|
78
|
+
/**
|
|
79
|
+
* Trace event id.
|
|
80
|
+
*/
|
|
81
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
82
|
+
type: S.Literal<[InvocationTraceEventType.END]>;
|
|
83
|
+
/**
|
|
84
|
+
* Invocation id, will be the same for invocation start and end.
|
|
85
|
+
*/
|
|
86
|
+
invocationId: import("@dxos/echo-schema").ObjectIdClass;
|
|
87
|
+
/**
|
|
88
|
+
* Event generation time.
|
|
89
|
+
*/
|
|
90
|
+
timestampMs: typeof S.Number;
|
|
91
|
+
outcome: S.Enums<typeof InvocationOutcome>;
|
|
92
|
+
exception: S.optional<S.Struct<{
|
|
93
|
+
timestampMs: typeof S.Number;
|
|
94
|
+
message: typeof S.String;
|
|
95
|
+
name: typeof S.String;
|
|
96
|
+
stack: S.optional<typeof S.String>;
|
|
97
|
+
}>>;
|
|
98
|
+
}>>;
|
|
99
|
+
export type InvocationTraceEndEvent = S.Schema.Type<typeof InvocationTraceEndEvent>;
|
|
100
|
+
export type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;
|
|
98
101
|
export declare const TraceEventLog: S.Struct<{
|
|
99
102
|
timestampMs: typeof S.Number;
|
|
100
103
|
level: typeof S.String;
|
|
101
104
|
message: typeof S.String;
|
|
102
105
|
context: S.optional<typeof S.Object>;
|
|
103
106
|
}>;
|
|
104
|
-
export declare const TraceEvent: S.
|
|
105
|
-
|
|
106
|
-
outcome:
|
|
107
|
-
truncated:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
ingestionTimestampMs: number;
|
|
126
|
-
logs: {
|
|
127
|
-
readonly context?: object | undefined;
|
|
128
|
-
readonly timestampMs: number;
|
|
129
|
-
readonly message: string;
|
|
130
|
-
readonly level: string;
|
|
131
|
-
}[];
|
|
132
|
-
exceptions: {
|
|
133
|
-
readonly name: string;
|
|
134
|
-
readonly timestampMs: number;
|
|
135
|
-
readonly message: string;
|
|
136
|
-
readonly stack?: string | undefined;
|
|
137
|
-
}[];
|
|
138
|
-
}, never>;
|
|
107
|
+
export declare const TraceEvent: import("@dxos/echo-schema").EchoObjectSchema<S.Struct<{
|
|
108
|
+
id: import("@dxos/echo-schema").ObjectIdClass;
|
|
109
|
+
outcome: typeof S.String;
|
|
110
|
+
truncated: typeof S.Boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Time when the event was persisted.
|
|
113
|
+
*/
|
|
114
|
+
ingestionTimestampMs: typeof S.Number;
|
|
115
|
+
logs: S.Array$<S.Struct<{
|
|
116
|
+
timestampMs: typeof S.Number;
|
|
117
|
+
level: typeof S.String;
|
|
118
|
+
message: typeof S.String;
|
|
119
|
+
context: S.optional<typeof S.Object>;
|
|
120
|
+
}>>;
|
|
121
|
+
exceptions: S.Array$<S.Struct<{
|
|
122
|
+
timestampMs: typeof S.Number;
|
|
123
|
+
message: typeof S.String;
|
|
124
|
+
name: typeof S.String;
|
|
125
|
+
stack: S.optional<typeof S.String>;
|
|
126
|
+
}>>;
|
|
127
|
+
}>>;
|
|
139
128
|
export type TraceEvent = S.Schema.Type<typeof TraceEvent>;
|
|
129
|
+
/**
|
|
130
|
+
* TODO: remove
|
|
131
|
+
* Deprecated InvocationTrace event format.
|
|
132
|
+
*/
|
|
133
|
+
export type InvocationSpan = {
|
|
134
|
+
id: string;
|
|
135
|
+
timestampMs: number;
|
|
136
|
+
outcome: InvocationOutcome;
|
|
137
|
+
input: object;
|
|
138
|
+
durationMs: number;
|
|
139
|
+
invocationTraceQueue: Ref<Expando>;
|
|
140
|
+
invocationTarget: Ref<Expando>;
|
|
141
|
+
trigger?: Ref<FunctionTriggerType>;
|
|
142
|
+
exception?: TraceEventException;
|
|
143
|
+
};
|
|
144
|
+
export declare const createInvocationSpans: (items?: InvocationTraceEvent[]) => InvocationSpan[];
|
|
140
145
|
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../../../src/types/trace.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,OAAO,EAAY,GAAG,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../../../src/types/trace.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,OAAO,EAAY,GAAG,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAG1E,OAAO,EAAmB,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEpE,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,OAAO,YAAY;CACpB;AAED,oBAAY,wBAAwB;IAClC,KAAK,UAAU;IACf,GAAG,QAAQ;CACZ;AAED,eAAO,MAAM,mBAAmB;;;;;EAK9B,CAAC;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE5E,eAAO,MAAM,yBAAyB;IACpC;;OAEG;;;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|
"name": "@dxos/functions",
|
|
3
|
-
"version": "0.8.1-
|
|
3
|
+
"version": "0.8.1-staging.5be625a",
|
|
4
4
|
"description": "Functions API and runtime.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -67,27 +67,27 @@
|
|
|
67
67
|
"get-port-please": "^3.1.1",
|
|
68
68
|
"iso-did": "^1.6.0",
|
|
69
69
|
"ws": "^8.14.2",
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
74
|
-
"@dxos/echo-db": "0.8.1-
|
|
75
|
-
"@dxos/echo-
|
|
76
|
-
"@dxos/
|
|
77
|
-
"@dxos/
|
|
78
|
-
"@dxos/invariant": "0.8.1-
|
|
79
|
-
"@dxos/
|
|
80
|
-
"@dxos/
|
|
81
|
-
"@dxos/log": "0.8.1-
|
|
82
|
-
"@dxos/
|
|
83
|
-
"@dxos/
|
|
84
|
-
"@dxos/
|
|
85
|
-
"@dxos/
|
|
70
|
+
"@dxos/async": "0.8.1-staging.5be625a",
|
|
71
|
+
"@dxos/client": "0.8.1-staging.5be625a",
|
|
72
|
+
"@dxos/context": "0.8.1-staging.5be625a",
|
|
73
|
+
"@dxos/crypto": "0.8.1-staging.5be625a",
|
|
74
|
+
"@dxos/echo-db": "0.8.1-staging.5be625a",
|
|
75
|
+
"@dxos/echo-schema": "0.8.1-staging.5be625a",
|
|
76
|
+
"@dxos/echo-protocol": "0.8.1-staging.5be625a",
|
|
77
|
+
"@dxos/edge-client": "0.8.1-staging.5be625a",
|
|
78
|
+
"@dxos/invariant": "0.8.1-staging.5be625a",
|
|
79
|
+
"@dxos/keys": "0.8.1-staging.5be625a",
|
|
80
|
+
"@dxos/live-object": "0.8.1-staging.5be625a",
|
|
81
|
+
"@dxos/log": "0.8.1-staging.5be625a",
|
|
82
|
+
"@dxos/protocols": "0.8.1-staging.5be625a",
|
|
83
|
+
"@dxos/node-std": "0.8.1-staging.5be625a",
|
|
84
|
+
"@dxos/util": "0.8.1-staging.5be625a",
|
|
85
|
+
"@dxos/schema": "0.8.1-staging.5be625a"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@types/express": "^4.17.17",
|
|
89
89
|
"@types/ws": "^7.4.0",
|
|
90
|
-
"@dxos/agent": "0.8.1-
|
|
90
|
+
"@dxos/agent": "0.8.1-staging.5be625a"
|
|
91
91
|
},
|
|
92
92
|
"publishConfig": {
|
|
93
93
|
"access": "public"
|
package/src/edge/functions.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { type DID } from 'iso-did/types';
|
|
6
6
|
|
|
7
7
|
import { type Client } from '@dxos/client';
|
|
8
|
-
import {
|
|
8
|
+
import { createEdgeIdentity } from '@dxos/client/edge';
|
|
9
|
+
import { EdgeHttpClient } from '@dxos/edge-client';
|
|
9
10
|
import { invariant } from '@dxos/invariant';
|
|
10
11
|
import type { PublicKey, SpaceId } from '@dxos/keys';
|
|
11
12
|
import { log } from '@dxos/log';
|
|
@@ -46,26 +47,6 @@ export const uploadWorkerFunction = async ({
|
|
|
46
47
|
return response;
|
|
47
48
|
};
|
|
48
49
|
|
|
49
|
-
const createEdgeIdentity = (client: Client): EdgeIdentity => {
|
|
50
|
-
const identity = client.halo.identity.get();
|
|
51
|
-
const device = client.halo.device;
|
|
52
|
-
if (!identity || !device) {
|
|
53
|
-
throw new Error('Identity not available');
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
identityKey: identity.identityKey.toHex(),
|
|
57
|
-
peerKey: device.deviceKey.toHex(),
|
|
58
|
-
presentCredentials: async ({ challenge }) => {
|
|
59
|
-
const identityService = client.services.services.IdentityService!;
|
|
60
|
-
const authCredential = await identityService.createAuthCredential();
|
|
61
|
-
return identityService.signPresentation({
|
|
62
|
-
presentation: { credentials: [authCredential] },
|
|
63
|
-
nonce: challenge,
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
50
|
export const incrementSemverPatch = (version: string): string => {
|
|
70
51
|
const [major, minor, patch] = version.split('.');
|
|
71
52
|
const patchNum = Number(patch);
|
package/src/handler.ts
CHANGED
|
@@ -171,7 +171,7 @@ export type SubscriptionData = {
|
|
|
171
171
|
// TODO(burdon): Evolve into plugin definition like Composer.
|
|
172
172
|
export const subscriptionHandler = <TMeta>(
|
|
173
173
|
handler: FunctionHandler<SubscriptionData, TMeta>,
|
|
174
|
-
types?: S.Schema
|
|
174
|
+
types?: S.Schema.AnyNoContext[],
|
|
175
175
|
): FunctionHandler<RawSubscriptionData, TMeta> => {
|
|
176
176
|
return async ({ event: { data }, context, response, ...rest }) => {
|
|
177
177
|
const { client } = context;
|
|
@@ -199,7 +199,7 @@ export const subscriptionHandler = <TMeta>(
|
|
|
199
199
|
};
|
|
200
200
|
|
|
201
201
|
// TODO(burdon): Evolve types as part of function metadata.
|
|
202
|
-
const registerTypes = (space: Space, types: S.Schema
|
|
202
|
+
const registerTypes = (space: Space, types: S.Schema.AnyNoContext[] = []) => {
|
|
203
203
|
const registry = space.db.graph.schemaRegistry;
|
|
204
204
|
for (const type of types) {
|
|
205
205
|
if (!registry.hasSchema(type)) {
|
|
@@ -16,7 +16,8 @@ import { TriggerRegistry } from '../trigger';
|
|
|
16
16
|
import { TriggerKind, type FunctionManifest } from '../types';
|
|
17
17
|
|
|
18
18
|
// TODO(burdon): Test we can add and remove triggers.
|
|
19
|
-
|
|
19
|
+
// Flaky: https://cloud.nx.app/runs/uqhKOBA6JQ/task/functions%3Atest
|
|
20
|
+
describe.skip('scheduler', () => {
|
|
20
21
|
let testBuilder: TestBuilder;
|
|
21
22
|
let client: Client;
|
|
22
23
|
|
package/src/types/schema.ts
CHANGED
|
@@ -2,23 +2,25 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';
|
|
5
|
+
import { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, S, TypedObject } from '@dxos/echo-schema';
|
|
6
6
|
import { TextType } from '@dxos/schema';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Source script.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
12
|
-
typename: 'dxos.org/type/Script',
|
|
13
|
-
version: '0.1.0',
|
|
14
|
-
})({
|
|
11
|
+
export const ScriptType = S.Struct({
|
|
15
12
|
name: S.optional(S.String),
|
|
16
13
|
description: S.optional(S.String),
|
|
17
14
|
// TODO(burdon): Change to hash of deployed content.
|
|
18
15
|
// Whether source has changed since last deploy.
|
|
19
16
|
changed: S.optional(S.Boolean),
|
|
20
17
|
source: Ref(TextType),
|
|
21
|
-
})
|
|
18
|
+
})
|
|
19
|
+
.annotations({
|
|
20
|
+
[LabelAnnotationId]: 'name',
|
|
21
|
+
})
|
|
22
|
+
.pipe(EchoObject('dxos.org/type/Script', '0.1.0'));
|
|
23
|
+
export type ScriptType = S.Schema.Type<typeof ScriptType>;
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
26
|
* Function deployment.
|
package/src/types/trace.ts
CHANGED
|
@@ -3,27 +3,46 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { EchoObject, Expando, ObjectId, Ref, S } from '@dxos/echo-schema';
|
|
6
|
+
import { log } from '@dxos/log';
|
|
6
7
|
|
|
7
|
-
import { FunctionTrigger } from './types';
|
|
8
|
+
import { FunctionTrigger, type FunctionTriggerType } from './types';
|
|
8
9
|
|
|
9
10
|
export enum InvocationOutcome {
|
|
10
11
|
SUCCESS = 'success',
|
|
11
12
|
FAILURE = 'failure',
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
export enum InvocationTraceEventType {
|
|
16
|
+
START = 'start',
|
|
17
|
+
END = 'end',
|
|
18
|
+
}
|
|
19
|
+
|
|
14
20
|
export const TraceEventException = S.Struct({
|
|
15
21
|
timestampMs: S.Number,
|
|
16
22
|
message: S.String,
|
|
17
23
|
name: S.String,
|
|
18
24
|
stack: S.optional(S.String),
|
|
19
25
|
});
|
|
26
|
+
export type TraceEventException = S.Schema.Type<typeof TraceEventException>;
|
|
20
27
|
|
|
21
|
-
export const
|
|
28
|
+
export const InvocationTraceStartEvent = S.Struct({
|
|
29
|
+
/**
|
|
30
|
+
* Queue message id.
|
|
31
|
+
*/
|
|
22
32
|
id: ObjectId,
|
|
33
|
+
type: S.Literal(InvocationTraceEventType.START),
|
|
34
|
+
/**
|
|
35
|
+
* Invocation id, the same for invocation start and end events.
|
|
36
|
+
*/
|
|
37
|
+
invocationId: ObjectId,
|
|
38
|
+
/**
|
|
39
|
+
* Event generation time.
|
|
40
|
+
*/
|
|
23
41
|
timestampMs: S.Number,
|
|
24
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Data passed to function / workflow as an argument.
|
|
44
|
+
*/
|
|
25
45
|
input: S.Object,
|
|
26
|
-
durationMs: S.Number,
|
|
27
46
|
/**
|
|
28
47
|
* Queue DXN for function/workflow invocation events.
|
|
29
48
|
*/
|
|
@@ -36,13 +55,31 @@ export const InvocationTraceEvent = S.Struct({
|
|
|
36
55
|
* Present for automatic invocations.
|
|
37
56
|
*/
|
|
38
57
|
trigger: S.optional(Ref(FunctionTrigger)),
|
|
58
|
+
}).pipe(EchoObject('dxos.org/type/InvocationTraceStart', '0.1.0'));
|
|
59
|
+
|
|
60
|
+
export type InvocationTraceStartEvent = S.Schema.Type<typeof InvocationTraceStartEvent>;
|
|
61
|
+
|
|
62
|
+
export const InvocationTraceEndEvent = S.Struct({
|
|
63
|
+
/**
|
|
64
|
+
* Trace event id.
|
|
65
|
+
*/
|
|
66
|
+
id: ObjectId,
|
|
67
|
+
type: S.Literal(InvocationTraceEventType.END),
|
|
68
|
+
/**
|
|
69
|
+
* Invocation id, will be the same for invocation start and end.
|
|
70
|
+
*/
|
|
71
|
+
invocationId: ObjectId,
|
|
39
72
|
/**
|
|
40
|
-
*
|
|
73
|
+
* Event generation time.
|
|
41
74
|
*/
|
|
75
|
+
timestampMs: S.Number,
|
|
76
|
+
outcome: S.Enums(InvocationOutcome),
|
|
42
77
|
exception: S.optional(TraceEventException),
|
|
43
|
-
}).pipe(EchoObject('dxos.org/type/
|
|
78
|
+
}).pipe(EchoObject('dxos.org/type/InvocationTraceEnd', '0.1.0'));
|
|
79
|
+
|
|
80
|
+
export type InvocationTraceEndEvent = S.Schema.Type<typeof InvocationTraceEndEvent>;
|
|
44
81
|
|
|
45
|
-
export type InvocationTraceEvent =
|
|
82
|
+
export type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;
|
|
46
83
|
|
|
47
84
|
export const TraceEventLog = S.Struct({
|
|
48
85
|
timestampMs: S.Number,
|
|
@@ -64,3 +101,53 @@ export const TraceEvent = S.Struct({
|
|
|
64
101
|
}).pipe(EchoObject('dxos.org/type/TraceEvent', '0.1.0'));
|
|
65
102
|
|
|
66
103
|
export type TraceEvent = S.Schema.Type<typeof TraceEvent>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* TODO: remove
|
|
107
|
+
* Deprecated InvocationTrace event format.
|
|
108
|
+
*/
|
|
109
|
+
export type InvocationSpan = {
|
|
110
|
+
id: string;
|
|
111
|
+
timestampMs: number;
|
|
112
|
+
outcome: InvocationOutcome;
|
|
113
|
+
input: object;
|
|
114
|
+
durationMs: number;
|
|
115
|
+
invocationTraceQueue: Ref<Expando>;
|
|
116
|
+
invocationTarget: Ref<Expando>;
|
|
117
|
+
trigger?: Ref<FunctionTriggerType>;
|
|
118
|
+
exception?: TraceEventException;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {
|
|
122
|
+
if (!items) {
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
const startEvents = new Map<ObjectId, InvocationTraceStartEvent>();
|
|
126
|
+
const result: InvocationSpan[] = [];
|
|
127
|
+
for (const item of items) {
|
|
128
|
+
if (item.type === InvocationTraceEventType.START) {
|
|
129
|
+
startEvents.set(item.invocationId, item);
|
|
130
|
+
} else if (item.type === InvocationTraceEventType.END) {
|
|
131
|
+
const matchingStart = startEvents.get(item.invocationId);
|
|
132
|
+
if (!matchingStart) {
|
|
133
|
+
log.warn('end event without matching start', { item });
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
result.push({
|
|
137
|
+
id: item.invocationId,
|
|
138
|
+
durationMs: item.timestampMs - matchingStart.timestampMs,
|
|
139
|
+
timestampMs: item.timestampMs,
|
|
140
|
+
outcome: item.outcome,
|
|
141
|
+
exception: item.exception,
|
|
142
|
+
trigger: matchingStart.trigger,
|
|
143
|
+
input: matchingStart.input,
|
|
144
|
+
invocationTraceQueue: matchingStart.invocationTraceQueue,
|
|
145
|
+
invocationTarget: matchingStart.invocationTarget,
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
// TODO: remove, the deprecated InvocationTrace format is no longer produced by functions backend
|
|
149
|
+
result.push(item as InvocationSpan);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
};
|
|
@@ -1,7 +0,0 @@
|
|
|
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 { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\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\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\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 meta from function.\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';\n\nimport { FunctionTrigger } from './types';\n\nexport enum InvocationOutcome {\n SUCCESS = 'success',\n FAILURE = 'failure',\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});\n\nexport const InvocationTraceEvent = S.Struct({\n id: ObjectId,\n timestampMs: S.Number,\n outcome: S.Enums(InvocationOutcome),\n input: S.Object,\n durationMs: S.Number,\n /**\n * Queue DXN for function/workflow invocation events.\n */\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 /**\n * Present for outcome FAILURE.\n */\n exception: S.optional(TraceEventException),\n}).pipe(EchoObject('dxos.org/type/InvocationTrace', '0.1.0'));\n\nexport type InvocationTraceEvent = S.Schema.Type<typeof InvocationTraceEvent>;\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 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('dxos.org/type/TraceEvent', '0.1.0'));\n\nexport type TraceEvent = S.Schema.Type<typeof TraceEvent>;\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,gBAAgBC,KAAKC,GAAGC,mBAAmB;AACpD,SAASC,gBAAgB;AAKlB,IAAMC,aAAN,cAAyBC,YAAY;EAC1CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,MAAMC,EAAEC,SAASD,EAAEE,MAAM;EACzBC,aAAaH,EAAEC,SAASD,EAAEE,MAAM;;;EAGhCE,SAASJ,EAAEC,SAASD,EAAEK,OAAO;EAC7BC,QAAQC,IAAIC,QAAAA;AACd,CAAA,EAAA;AAAI;AAMG,IAAMC,eAAN,cAA2Bb,YAAY;EAC5CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,EAAEU;EACRZ,SAASE,EAAEE;EAEXC,aAAaH,EAAEC,SAASD,EAAEE,MAAM;;;EAIhCI,QAAQN,EAAEC,SAASM,IAAIZ,UAAAA,CAAAA;EAEvBgB,aAAaX,EAAEC,SAASW,cAAAA;EACxBC,cAAcb,EAAEC,SAASW,cAAAA;;EAGzBE,SAASd,EAAEC,SAASD,EAAEE,MAAM;AAC9B,CAAA,EAAA;AAAI;;;ACzCJ,SAASa,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,GAA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IAAIC,SAAQ;AACrB;",
|
|
6
|
-
"names": ["JsonSchemaType", "Ref", "S", "TypedObject", "TextType", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "FunctionType", "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", "InvocationOutcome", "TraceEventException", "S", "Struct", "timestampMs", "Number", "message", "String", "name", "stack", "optional", "InvocationTraceEvent", "id", "ObjectId", "outcome", "Enums", "input", "Object", "durationMs", "invocationTraceQueue", "Ref", "Expando", "invocationTarget", "trigger", "FunctionTrigger", "exception", "pipe", "EchoObject", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "Boolean", "ingestionTimestampMs", "logs", "Array", "exceptions", "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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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 { EdgeHttpClient, type EdgeIdentity } 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 name?: string;\n source: string;\n version: string;\n functionId?: string;\n spaceId: SpaceId;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n name,\n version,\n source,\n spaceId,\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 log('Uploaded', {\n functionId,\n source,\n name,\n identityKey: edgeIdentity.identityKey,\n response,\n });\n\n return response;\n};\n\nconst createEdgeIdentity = (client: Client): EdgeIdentity => {\n const identity = client.halo.identity.get();\n const device = client.halo.device;\n if (!identity || !device) {\n throw new Error('Identity not available');\n }\n return {\n identityKey: identity.identityKey.toHex(),\n peerKey: device.deviceKey.toHex(),\n presentCredentials: async ({ challenge }) => {\n const identityService = client.services.services.IdentityService!;\n const authCredential = await identityService.createAuthCredential();\n return identityService.signPresentation({\n presentation: { credentials: [authCredential] },\n nonce: challenge,\n });\n },\n };\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.');\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
|
|
5
|
-
"mappings": ";;;AAOA,SAASA,sBAAyC;AAClD,SAASC,iBAAiB;AAE1B,SAASC,WAAW;;AAYb,IAAMC,uBAAuB,OAAO,EACzCC,QACAC,MACAC,SACAC,QACAC,SACAC,WAAU,MACO;AACjB,QAAMC,UAAUN,OAAOO,OAAOC,OAAOC,SAASC,UAAUC,MAAMC;AAC9Df,YAAUS,SAAS,2BAAA;;;;;;;;;AACnB,QAAMO,aAAa,IAAIjB,eAAeU,OAAAA;AACtC,QAAMQ,eAAeC,mBAAmBf,MAAAA;AACxCa,aAAWG,YAAYF,YAAAA;AACvB,QAAMG,WAAW,MAAMJ,WAAWK,eAAe;IAAEd;IAASC;EAAW,GAAG;IAAEJ;IAAMC;IAASiB,QAAQhB;EAAO,CAAA;AAE1GL,MAAI,YAAY;IACdO;IACAF;IACAF;IACAmB,aAAaN,aAAaM;IAC1BH;EACF,GAAA;;;;;;AAEA,SAAOA;AACT;AAEA,IAAMF,qBAAqB,CAACf,WAAAA;AAC1B,QAAMqB,WAAWrB,OAAOsB,KAAKD,SAASE,IAAG;AACzC,QAAMC,SAASxB,OAAOsB,KAAKE;AAC3B,MAAI,CAACH,YAAY,CAACG,QAAQ;AACxB,UAAM,IAAIC,MAAM,wBAAA;EAClB;AACA,SAAO;IACLL,aAAaC,SAASD,YAAYM,MAAK;IACvCC,SAASH,OAAOI,UAAUF,MAAK;IAC/BG,oBAAoB,OAAO,EAAEC,UAAS,MAAE;AACtC,YAAMC,kBAAkB/B,OAAOU,SAASA,SAASsB;AACjD,YAAMC,iBAAiB,MAAMF,gBAAgBG,qBAAoB;AACjE,aAAOH,gBAAgBI,iBAAiB;QACtCC,cAAc;UAAEC,aAAa;YAACJ;;QAAgB;QAC9CK,OAAOR;MACT,CAAA;IACF;EACF;AACF;AAEO,IAAMS,uBAAuB,CAACrC,YAAAA;AACnC,QAAM,CAACsC,OAAOC,OAAOC,KAAAA,IAASxC,QAAQyC,MAAM,GAAA;AAC5C,QAAMC,WAAWC,OAAOH,KAAAA;AACxB7C,YAAU,CAACgD,OAAOC,MAAMF,QAAAA,GAAW,uCAAA;;;;;;;;;AACnC,SAAO;IAACJ;IAAOC;IAAOM,OAAOH,WAAW,CAAA;IAAII,KAAK,GAAA;AACnD;AAEO,IAAMC,iBAAiB,CAACC,QAAAA;AAC7B,SAAO,WAAWA,IAAIxB,MAAK,CAAA;AAC7B;",
|
|
6
|
-
"names": ["EdgeHttpClient", "invariant", "log", "uploadWorkerFunction", "client", "name", "version", "source", "spaceId", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "edgeClient", "edgeIdentity", "createEdgeIdentity", "setIdentity", "response", "uploadFunction", "script", "identityKey", "identity", "halo", "get", "device", "Error", "toHex", "peerKey", "deviceKey", "presentCredentials", "challenge", "identityService", "IdentityService", "authCredential", "createAuthCredential", "signPresentation", "presentation", "credentials", "nonce", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid", "key"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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 { JsonSchemaType, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport class ScriptType extends TypedObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n})({\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\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\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 meta from function.\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';\n\nimport { FunctionTrigger } from './types';\n\nexport enum InvocationOutcome {\n SUCCESS = 'success',\n FAILURE = 'failure',\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});\n\nexport const InvocationTraceEvent = S.Struct({\n id: ObjectId,\n timestampMs: S.Number,\n outcome: S.Enums(InvocationOutcome),\n input: S.Object,\n durationMs: S.Number,\n /**\n * Queue DXN for function/workflow invocation events.\n */\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 /**\n * Present for outcome FAILURE.\n */\n exception: S.optional(TraceEventException),\n}).pipe(EchoObject('dxos.org/type/InvocationTrace', '0.1.0'));\n\nexport type InvocationTraceEvent = S.Schema.Type<typeof InvocationTraceEvent>;\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 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('dxos.org/type/TraceEvent', '0.1.0'));\n\nexport type TraceEvent = S.Schema.Type<typeof TraceEvent>;\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,yBAAoD;AACpD,oBAAyB;ACDzB,IAAAA,sBAAyE;ACAzE,IAAAA,sBAAsD;AFM/C,IAAMC,aAAN,kBAAyBC,gCAAY;EAC1CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;EACDC,MAAMC,qBAAEC,SAASD,qBAAEE,MAAM;EACzBC,aAAaH,qBAAEC,SAASD,qBAAEE,MAAM;;;EAGhCE,SAASJ,qBAAEC,SAASD,qBAAEK,OAAO;EAC7BC,YAAQC,wBAAIC,sBAAAA;AACd,CAAA,EAAA;AAAI;AAMG,IAAMC,eAAN,kBAA2Bb,gCAAY;EAC5CC,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDC,MAAMC,qBAAEU;EACRZ,SAASE,qBAAEE;EAEXC,aAAaH,qBAAEC,SAASD,qBAAEE,MAAM;;;EAIhCI,QAAQN,qBAAEC,aAASM,wBAAIZ,UAAAA,CAAAA;EAEvBgB,aAAaX,qBAAEC,SAASW,iCAAAA;EACxBC,cAAcb,qBAAEC,SAASW,iCAAAA;;EAGzBE,SAASd,qBAAEC,SAASD,qBAAEE,MAAM;AAC9B,CAAA,EAAA;AAAI;;UClCQa,cAAAA;;;;;;GAAAA,gBAAAA,cAAAA,CAAAA,EAAAA;AASZ,IAAMC,yBAAyB;EAAE,CAACC,wBAAIC,iBAAiB,GAAG;AAAO;AAKjE,IAAMC,qBAAqBnB,oBAAAA,EAAEoB,OAAO;EAClCC,MAAMrB,oBAAAA,EAA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GAAqBrB;AACrE;AAEO,IAAM4B,+BAA+B,CAAC/C,MAAkBgD,gBAAAA;AAC7D,QAAM9D,MAAMc,KAAK6C,KAAKC,KAAK,CAAC5D,SAAQA,KAAIlC,WAAWwF,kBAAAA;AACnD,MAAItD,KAAK;AACP,QAAIA,IAAIiC,OAAO6B,aAAa;AAC1B,YAAM,IAAIC,MAAM,mBAAA;IAClB;EACF,OAAO;AACLjD,SAAK6C,KAAKK,KAAK;MAAElG,QAAQwF;MAAoBrB,IAAI6B;IAAY,CAAA;EAC/D;AACF;AAEO,IAAMG,mBAAmB,CAACH,aAAqBI,SAAiB7D,UAA6B,CAAC,MAAC;AACpG,QAAM8D,UAAU,IAAIC,IAAI,cAAcF,OAAAA;AAGtC,QAAMG,cAAcP,YAAYQ,QAAQ,OAAO,EAAA;AAC/C,QAAMC,MAAM,IAAIH,IAAI,KAAKC,WAAAA,IAAeF,QAAQK,SAAQ,CAAA;AACxDnE,UAAQoE,WAAWF,IAAIG,aAAaC,IAAI,WAAWtE,QAAQoE,OAAO;AAClEpE,UAAQuE,aAAaL,IAAIG,aAAaC,IAAI,aAAatE,QAAQuE,SAAS;AACxEL,MAAId,WAAWD,SAASe,IAAId,QAAQ,IAAI,UAAU;AAClD,SAAOc,IAAIC,SAAQ;AACrB;",
|
|
6
|
-
"names": ["import_echo_schema", "ScriptType", "TypedObject", "typename", "version", "name", "S", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "FunctionType", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "Struct", "type", "Literal", "annotations", "cron", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "fields", "FunctionDef", "uri", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES", "InvocationOutcome", "TraceEventException", "timestampMs", "message", "stack", "InvocationTraceEvent", "id", "ObjectId", "outcome", "Enums", "input", "Object", "durationMs", "invocationTraceQueue", "Expando", "invocationTarget", "trigger", "exception", "EchoObject", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "ingestionTimestampMs", "logs", "exceptions", "FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "isSecure", "protocol", "getUserFunctionUrlInMetadata", "keys", "find", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "push", "getInvocationUrl", "edgeUrl", "baseUrl", "URL", "relativeUrl", "replace", "url", "toString", "spaceId", "searchParams", "set", "subjectId"]
|
|
7
|
-
}
|