@dxos/functions 0.8.1-main.ae460ac → 0.8.1-staging.31c3ee1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/dist/lib/browser/{chunk-TMUL6AZC.mjs → chunk-HI7YZO2K.mjs} +27 -25
  2. package/dist/lib/browser/chunk-HI7YZO2K.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-LT4LR4VU.mjs +72 -0
  4. package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-XK3NINVF.mjs → chunk-RVSG6WTL.mjs} +156 -19
  6. package/dist/lib/browser/chunk-RVSG6WTL.mjs.map +7 -0
  7. package/dist/lib/browser/edge/index.mjs +1 -9
  8. package/dist/lib/browser/index.mjs +16 -10
  9. package/dist/lib/browser/index.mjs.map +2 -2
  10. package/dist/lib/browser/meta.json +1 -1
  11. package/dist/lib/browser/testing/index.mjs +2 -2
  12. package/dist/lib/browser/types/index.mjs +19 -5
  13. package/dist/lib/node/{chunk-3J6FVYUV.cjs → chunk-DSUGRAAL.cjs} +164 -22
  14. package/dist/lib/node/chunk-DSUGRAAL.cjs.map +7 -0
  15. package/dist/lib/node/chunk-NXZNXVT3.cjs +94 -0
  16. package/dist/lib/node/chunk-NXZNXVT3.cjs.map +7 -0
  17. package/dist/lib/node/{chunk-BGDVH6JU.cjs → chunk-RXMCVAMJ.cjs} +40 -38
  18. package/dist/lib/node/chunk-RXMCVAMJ.cjs.map +7 -0
  19. package/dist/lib/node/edge/index.cjs +4 -12
  20. package/dist/lib/node/edge/index.cjs.map +2 -2
  21. package/dist/lib/node/index.cjs +35 -29
  22. package/dist/lib/node/index.cjs.map +2 -2
  23. package/dist/lib/node/meta.json +1 -1
  24. package/dist/lib/node/testing/index.cjs +7 -7
  25. package/dist/lib/node/types/index.cjs +31 -17
  26. package/dist/lib/node/types/index.cjs.map +2 -2
  27. package/dist/lib/node-esm/{chunk-QRMVAODA.mjs → chunk-HBD2FZXO.mjs} +156 -19
  28. package/dist/lib/node-esm/chunk-HBD2FZXO.mjs.map +7 -0
  29. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +72 -0
  30. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +7 -0
  31. package/dist/lib/node-esm/{chunk-V3VOPFP3.mjs → chunk-SQSJO5HI.mjs} +27 -25
  32. package/dist/lib/node-esm/chunk-SQSJO5HI.mjs.map +7 -0
  33. package/dist/lib/node-esm/edge/index.mjs +1 -9
  34. package/dist/lib/node-esm/index.mjs +16 -10
  35. package/dist/lib/node-esm/index.mjs.map +2 -2
  36. package/dist/lib/node-esm/meta.json +1 -1
  37. package/dist/lib/node-esm/testing/index.mjs +2 -2
  38. package/dist/lib/node-esm/types/index.mjs +19 -5
  39. package/dist/types/src/edge/functions.d.ts +3 -12
  40. package/dist/types/src/edge/functions.d.ts.map +1 -1
  41. package/dist/types/src/handler.d.ts +1 -1
  42. package/dist/types/src/handler.d.ts.map +1 -1
  43. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -1
  44. package/dist/types/src/types/index.d.ts +1 -0
  45. package/dist/types/src/types/index.d.ts.map +1 -1
  46. package/dist/types/src/types/schema.d.ts +20 -26
  47. package/dist/types/src/types/schema.d.ts.map +1 -1
  48. package/dist/types/src/types/trace.d.ts +103 -97
  49. package/dist/types/src/types/trace.d.ts.map +1 -1
  50. package/dist/types/src/types/types.d.ts +7 -7
  51. package/dist/types/src/types/types.d.ts.map +1 -1
  52. package/dist/types/src/types/url.d.ts +11 -0
  53. package/dist/types/src/types/url.d.ts.map +1 -0
  54. package/package.json +20 -19
  55. package/src/edge/functions.ts +12 -71
  56. package/src/handler.ts +2 -2
  57. package/src/runtime/scheduler.test.ts +2 -1
  58. package/src/trigger/type/timer-trigger.ts +21 -18
  59. package/src/types/index.ts +1 -0
  60. package/src/types/schema.ts +7 -7
  61. package/src/types/trace.ts +120 -8
  62. package/src/types/types.ts +2 -1
  63. package/src/types/url.ts +47 -0
  64. package/dist/lib/browser/chunk-TMUL6AZC.mjs.map +0 -7
  65. package/dist/lib/browser/chunk-XK3NINVF.mjs.map +0 -7
  66. package/dist/lib/browser/chunk-YJEIETRB.mjs +0 -128
  67. package/dist/lib/browser/chunk-YJEIETRB.mjs.map +0 -7
  68. package/dist/lib/node/chunk-3J6FVYUV.cjs.map +0 -7
  69. package/dist/lib/node/chunk-BGDVH6JU.cjs.map +0 -7
  70. package/dist/lib/node/chunk-MZMHE4DC.cjs +0 -154
  71. package/dist/lib/node/chunk-MZMHE4DC.cjs.map +0 -7
  72. package/dist/lib/node-esm/chunk-QRMVAODA.mjs.map +0 -7
  73. package/dist/lib/node-esm/chunk-T2KBXTMR.mjs +0 -128
  74. package/dist/lib/node-esm/chunk-T2KBXTMR.mjs.map +0 -7
  75. package/dist/lib/node-esm/chunk-V3VOPFP3.mjs.map +0 -7
@@ -5,33 +5,28 @@
5
5
  import { type DID } from 'iso-did/types';
6
6
 
7
7
  import { type Client } from '@dxos/client';
8
- import { type ObjectMeta } from '@dxos/echo-schema';
9
- import { EdgeHttpClient, type EdgeIdentity } from '@dxos/edge-client';
8
+ import { createEdgeIdentity } from '@dxos/client/edge';
9
+ import { EdgeHttpClient } from '@dxos/edge-client';
10
10
  import { invariant } from '@dxos/invariant';
11
11
  import type { PublicKey, SpaceId } from '@dxos/keys';
12
12
  import { log } from '@dxos/log';
13
13
  import { type UploadFunctionResponseBody } from '@dxos/protocols';
14
14
 
15
- // TODO: use URL scheme for source?
16
- const FUNCTIONS_META_KEY = 'dxos.org/service/function';
17
-
18
- export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
19
-
20
15
  export type UploadWorkerArgs = {
21
16
  client: Client;
22
- name?: string;
17
+ spaceId: SpaceId;
23
18
  source: string;
24
19
  version: string;
20
+ name?: string;
25
21
  functionId?: string;
26
- spaceId: SpaceId;
27
22
  };
28
23
 
29
24
  export const uploadWorkerFunction = async ({
30
25
  client,
31
- name,
26
+ spaceId,
32
27
  version,
33
28
  source,
34
- spaceId,
29
+ name,
35
30
  functionId,
36
31
  }: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {
37
32
  const edgeUrl = client.config.values.runtime?.services?.edge?.url;
@@ -41,80 +36,26 @@ export const uploadWorkerFunction = async ({
41
36
  edgeClient.setIdentity(edgeIdentity);
42
37
  const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });
43
38
 
44
- log('Uploaded', {
39
+ // TODO(burdon): Edge service log.
40
+ log.info('Uploaded', {
41
+ identityKey: edgeIdentity.identityKey,
45
42
  functionId,
46
- source,
47
43
  name,
48
- identityKey: edgeIdentity.identityKey,
44
+ source: source.length,
49
45
  response,
50
46
  });
51
47
 
52
48
  return response;
53
49
  };
54
50
 
55
- export const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {
56
- return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
57
- };
58
-
59
- export const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {
60
- const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
61
- if (key) {
62
- if (key.id !== functionUrl) {
63
- throw new Error('Metadata mismatch');
64
- }
65
- } else {
66
- meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });
67
- }
68
- };
69
-
70
- export const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {
71
- const baseUrl = new URL('functions/', edgeUrl);
72
-
73
- // Leading slashes cause the URL to be treated as an absolute path.
74
- const relativeUrl = functionUrl.replace(/^\//, '');
75
- const url = new URL(`./${relativeUrl}`, baseUrl.toString());
76
- options.spaceId && url.searchParams.set('spaceId', options.spaceId);
77
- options.subjectId && url.searchParams.set('subjectId', options.subjectId);
78
- url.protocol = isSecure(url.protocol) ? 'https' : 'http';
79
- return url.toString();
80
- };
81
-
82
- const isSecure = (protocol: string) => {
83
- return protocol === 'https:' || protocol === 'wss:';
84
- };
85
-
86
- const createEdgeIdentity = (client: Client): EdgeIdentity => {
87
- const identity = client.halo.identity.get();
88
- const device = client.halo.device;
89
- if (!identity || !device) {
90
- throw new Error('Identity not available');
91
- }
92
- return {
93
- identityKey: identity.identityKey.toHex(),
94
- peerKey: device.deviceKey.toHex(),
95
- presentCredentials: async ({ challenge }) => {
96
- const identityService = client.services.services.IdentityService!;
97
- const authCredential = await identityService.createAuthCredential();
98
- return identityService.signPresentation({
99
- presentation: { credentials: [authCredential] },
100
- nonce: challenge,
101
- });
102
- },
103
- };
104
- };
105
-
106
51
  export const incrementSemverPatch = (version: string): string => {
107
52
  const [major, minor, patch] = version.split('.');
108
53
  const patchNum = Number(patch);
109
- invariant(!Number.isNaN(patchNum), 'Unexpected function version format.');
54
+ invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`);
110
55
  return [major, minor, String(patchNum + 1)].join('.');
111
56
  };
112
57
 
58
+ // TODO(burdon): Factor out.
113
59
  export const publicKeyToDid = (key: PublicKey): DID => {
114
60
  return `did:key:${key.toHex()}`;
115
61
  };
116
-
117
- export type InvocationOptions = {
118
- spaceId?: SpaceId;
119
- subjectId?: string;
120
- };
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<any>[],
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<any>[] = []) => {
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
- describe('scheduler', () => {
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
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { CronJob } from 'cron';
5
+ import { parseCronExpression } from 'cron-schedule';
6
6
 
7
7
  import { DeferredTask } from '@dxos/async';
8
8
  import { type Space } from '@dxos/client/echo';
@@ -24,22 +24,25 @@ export const createTimerTrigger: TriggerFactory<TimerTrigger> = async (
24
24
 
25
25
  let last = 0;
26
26
  let run = 0;
27
- // https://www.npmjs.com/package/cron#constructor
28
- const job = CronJob.from({
29
- cronTime: spec.cron,
30
- runOnInit: false,
31
- onTick: () => {
32
- // TODO(burdon): Check greater than 30s (use cron-parser).
33
- const now = Date.now();
34
- const delta = last ? now - last : 0;
35
- last = now;
36
-
37
- run++;
38
- log.info('tick', { space: space.key.truncate(), count: run, delta });
39
- task.schedule();
40
- },
41
- });
27
+ const schedule = parseCronExpression(spec.cron);
28
+ const getRunTimeout = () => Date.now() - schedule.getNextDate().getTime();
29
+ const runCron = () => {
30
+ if (ctx.disposed) {
31
+ return;
32
+ }
33
+ // TODO(burdon): Check greater than 30s (use cron-parser).
34
+ const now = Date.now();
35
+ const delta = last ? now - last : 0;
36
+ last = now;
37
+
38
+ run++;
39
+ log.info('tick', { space: space.key.truncate(), count: run, delta });
40
+ task.schedule();
41
+
42
+ timeout = setTimeout(runCron, getRunTimeout());
43
+ };
44
+
45
+ let timeout = setTimeout(runCron, getRunTimeout());
42
46
 
43
- job.start();
44
- ctx.onDispose(() => job.stop());
47
+ ctx.onDispose(() => clearTimeout(timeout));
45
48
  };
@@ -5,3 +5,4 @@
5
5
  export * from './schema';
6
6
  export * from './types';
7
7
  export * from './trace';
8
+ export * from './url';
@@ -2,28 +2,28 @@
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 class ScriptType extends TypedObject({
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({ [LabelAnnotationId]: 'name' })
20
+ .pipe(EchoObject({ typename: 'dxos.org/type/Script', version: '0.1.0' }));
21
+
22
+ export type ScriptType = S.Schema.Type<typeof ScriptType>;
22
23
 
23
24
  /**
24
25
  * Function deployment.
25
26
  */
26
- // TODO(burdon): Move to core/functions.
27
27
  export class FunctionType extends TypedObject({
28
28
  typename: 'dxos.org/type/Function',
29
29
  version: '0.1.0',
@@ -3,12 +3,20 @@
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',
13
+ PENDING = 'pending',
14
+ }
15
+
16
+ // TODO(burdon): Convert to extensible discriminated union of EDGE events.
17
+ export enum InvocationTraceEventType {
18
+ START = 'start',
19
+ END = 'end',
12
20
  }
13
21
 
14
22
  export const TraceEventException = S.Struct({
@@ -17,16 +25,31 @@ export const TraceEventException = S.Struct({
17
25
  name: S.String,
18
26
  stack: S.optional(S.String),
19
27
  });
28
+ export type TraceEventException = S.Schema.Type<typeof TraceEventException>;
20
29
 
21
- export const InvocationTraceEvent = S.Struct({
30
+ export const InvocationTraceStartEvent = S.Struct({
31
+ /**
32
+ * Queue message id.
33
+ */
22
34
  id: ObjectId,
35
+ type: S.Literal(InvocationTraceEventType.START),
36
+ /**
37
+ * Invocation id, the same for invocation start and end events.
38
+ */
39
+ invocationId: ObjectId,
40
+ /**
41
+ * Event generation time.
42
+ */
23
43
  timestampMs: S.Number,
24
- outcome: S.Enums(InvocationOutcome),
44
+ /**
45
+ * Data passed to function / workflow as an argument.
46
+ */
47
+ // TODO(burdon): Input schema?
25
48
  input: S.Object,
26
- durationMs: S.Number,
27
49
  /**
28
50
  * Queue DXN for function/workflow invocation events.
29
51
  */
52
+ // TODO(burdon): Need reference type for queue. vs. string?
30
53
  invocationTraceQueue: Ref(Expando),
31
54
  /**
32
55
  * DXN of the invoked function/workflow.
@@ -36,13 +59,32 @@ export const InvocationTraceEvent = S.Struct({
36
59
  * Present for automatic invocations.
37
60
  */
38
61
  trigger: S.optional(Ref(FunctionTrigger)),
62
+ }).pipe(EchoObject({ typename: 'dxos.org/type/InvocationTraceStart', version: '0.1.0' }));
63
+
64
+ export type InvocationTraceStartEvent = S.Schema.Type<typeof InvocationTraceStartEvent>;
65
+
66
+ export const InvocationTraceEndEvent = S.Struct({
67
+ /**
68
+ * Trace event id.
69
+ */
70
+ id: ObjectId,
71
+ type: S.Literal(InvocationTraceEventType.END),
39
72
  /**
40
- * Present for outcome FAILURE.
73
+ * Invocation id, will be the same for invocation start and end.
41
74
  */
75
+ invocationId: ObjectId,
76
+ /**
77
+ * Event generation time.
78
+ */
79
+ // TODO(burdon): Remove ms suffix.
80
+ timestampMs: S.Number,
81
+ outcome: S.Enums(InvocationOutcome),
42
82
  exception: S.optional(TraceEventException),
43
- }).pipe(EchoObject('dxos.org/type/InvocationTrace', '0.1.0'));
83
+ }).pipe(EchoObject({ typename: 'dxos.org/type/InvocationTraceEnd', version: '0.1.0' }));
44
84
 
45
- export type InvocationTraceEvent = S.Schema.Type<typeof InvocationTraceEvent>;
85
+ export type InvocationTraceEndEvent = S.Schema.Type<typeof InvocationTraceEndEvent>;
86
+
87
+ export type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;
46
88
 
47
89
  export const TraceEventLog = S.Struct({
48
90
  timestampMs: S.Number,
@@ -53,6 +95,7 @@ export const TraceEventLog = S.Struct({
53
95
 
54
96
  export const TraceEvent = S.Struct({
55
97
  id: ObjectId,
98
+ // TODO(burdon): Need enum/numeric result (not string).
56
99
  outcome: S.String,
57
100
  truncated: S.Boolean,
58
101
  /**
@@ -61,6 +104,75 @@ export const TraceEvent = S.Struct({
61
104
  ingestionTimestampMs: S.Number,
62
105
  logs: S.Array(TraceEventLog),
63
106
  exceptions: S.Array(TraceEventException),
64
- }).pipe(EchoObject('dxos.org/type/TraceEvent', '0.1.0'));
107
+ }).pipe(EchoObject({ typename: 'dxos.org/type/TraceEvent', version: '0.1.0' }));
65
108
 
66
109
  export type TraceEvent = S.Schema.Type<typeof TraceEvent>;
110
+
111
+ /**
112
+ * Deprecated InvocationTrace event format.
113
+ * @deprecated
114
+ */
115
+ // TODO(burdon): Remove.
116
+ export type InvocationSpan = {
117
+ id: string;
118
+ timestampMs: number;
119
+ outcome: InvocationOutcome;
120
+ input: object;
121
+ durationMs: number;
122
+ invocationTraceQueue: Ref<Expando>;
123
+ invocationTarget: Ref<Expando>;
124
+ trigger?: Ref<FunctionTriggerType>;
125
+ exception?: TraceEventException;
126
+ };
127
+
128
+ export const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {
129
+ if (!items) {
130
+ return [];
131
+ }
132
+
133
+ const eventsByInvocationId = new Map<string, { start?: InvocationTraceStartEvent; end?: InvocationTraceEndEvent }>();
134
+ for (const event of items) {
135
+ if (!('invocationId' in event)) {
136
+ // Skip legacy format entries.
137
+ continue;
138
+ }
139
+
140
+ const invocationId = event.invocationId;
141
+ const entry = eventsByInvocationId.get(invocationId) || { start: undefined, end: undefined };
142
+ if (event.type === InvocationTraceEventType.START) {
143
+ entry.start = event as InvocationTraceStartEvent;
144
+ } else if (event.type === InvocationTraceEventType.END) {
145
+ entry.end = event as InvocationTraceEndEvent;
146
+ }
147
+
148
+ eventsByInvocationId.set(invocationId, entry);
149
+ }
150
+
151
+ const now = Date.now();
152
+ const result: InvocationSpan[] = [];
153
+
154
+ // Create spans for each invocation
155
+ for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
156
+ if (!start) {
157
+ // No start event, can't create a meaningful span
158
+ log.warn('found end event without matching start', { invocationId });
159
+ continue;
160
+ }
161
+
162
+ const isInProgress = end === undefined;
163
+
164
+ result.push({
165
+ id: invocationId,
166
+ timestampMs: start.timestampMs,
167
+ durationMs: isInProgress ? now - start.timestampMs : end!.timestampMs - start.timestampMs,
168
+ outcome: end?.outcome ?? InvocationOutcome.PENDING,
169
+ exception: end?.exception,
170
+ input: start.input,
171
+ invocationTraceQueue: start.invocationTraceQueue,
172
+ invocationTarget: start.invocationTarget,
173
+ trigger: start.trigger,
174
+ });
175
+ }
176
+
177
+ return result;
178
+ };
@@ -119,7 +119,8 @@ export const FunctionTriggerSchema = S.Struct({
119
119
  // TODO(burdon): Flatten entire schema.
120
120
  spec: S.optional(TriggerSchema),
121
121
 
122
- // TODO(burdon): Get meta from function.
122
+ // TODO(burdon): Get schema as partial from function.
123
+ // TODO(wittjosiah): Rename to payload.
123
124
  // The `meta` property is merged into the event data passed to the function.
124
125
  meta: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),
125
126
  });
@@ -0,0 +1,47 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type ObjectMeta } from '@dxos/echo-schema';
6
+ import { type SpaceId } from '@dxos/keys';
7
+
8
+ // TODO: use URL scheme for source?
9
+ const FUNCTIONS_META_KEY = 'dxos.org/service/function';
10
+
11
+ export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
12
+
13
+ const isSecure = (protocol: string) => {
14
+ return protocol === 'https:' || protocol === 'wss:';
15
+ };
16
+
17
+ export const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {
18
+ return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
19
+ };
20
+
21
+ export const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {
22
+ const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
23
+ if (key) {
24
+ if (key.id !== functionUrl) {
25
+ throw new Error('Metadata mismatch');
26
+ }
27
+ } else {
28
+ meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });
29
+ }
30
+ };
31
+
32
+ export const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {
33
+ const baseUrl = new URL('functions/', edgeUrl);
34
+
35
+ // Leading slashes cause the URL to be treated as an absolute path.
36
+ const relativeUrl = functionUrl.replace(/^\//, '');
37
+ const url = new URL(`./${relativeUrl}`, baseUrl.toString());
38
+ options.spaceId && url.searchParams.set('spaceId', options.spaceId);
39
+ options.subjectId && url.searchParams.set('subjectId', options.subjectId);
40
+ url.protocol = isSecure(url.protocol) ? 'https' : 'http';
41
+ return url.toString();
42
+ };
43
+
44
+ export type InvocationOptions = {
45
+ spaceId?: SpaceId;
46
+ subjectId?: string;
47
+ };
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/function/function-registry.ts", "../../../src/trigger/type/subscription-trigger.ts", "../../../src/trigger/type/timer-trigger.ts", "../../../src/trigger/trigger-registry.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { create, Filter, type Space } from '@dxos/client/echo';\nimport { type Context, Resource } from '@dxos/context';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, diff } from '@dxos/util';\n\nimport { FunctionDef, type FunctionManifest } from '../types';\n\nexport type FunctionsRegisteredEvent = {\n space: Space;\n added: FunctionDef[];\n};\n\nexport class FunctionRegistry extends Resource {\n private readonly _functionBySpaceKey = new ComplexMap<PublicKey, FunctionDef[]>(PublicKey.hash);\n\n public readonly registered = new Event<FunctionsRegisteredEvent>();\n\n constructor(private readonly _client: Client) {\n super();\n }\n\n public getFunctions(space: Space): FunctionDef[] {\n return this._functionBySpaceKey.get(space.key) ?? [];\n }\n\n public getUniqueByUri(): FunctionDef[] {\n const uniqueByUri = [...this._functionBySpaceKey.values()]\n .flatMap((defs) => defs)\n .reduce((acc, v) => {\n acc.set(v.uri, v);\n return acc;\n }, new Map<string, FunctionDef>());\n return [...uniqueByUri.values()];\n }\n\n /**\n * Loads function definitions from the manifest into the space.\n * We first load all the definitions from the space to deduplicate by functionId.\n */\n public async register(space: Space, functions: FunctionManifest['functions']): Promise<void> {\n log('register', { space: space.key, functions: functions?.length ?? 0 });\n if (!functions?.length) {\n return;\n }\n if (!space.db.graph.schemaRegistry.hasSchema(FunctionDef)) {\n space.db.graph.schemaRegistry.addSchema([FunctionDef]);\n }\n\n // Sync definitions.\n const { objects: existing } = await space.db.query(Filter.schema(FunctionDef)).run();\n const { added } = diff(existing, functions, (a, b) => a.uri === b.uri);\n // TODO(burdon): Update existing templates.\n added.forEach((def) => space.db.add(create(FunctionDef, def)));\n\n if (added.length > 0) {\n await space.db.flush({ indexes: true, updates: true });\n }\n }\n\n protected override async _open(): Promise<void> {\n log.info('opening...');\n const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n if (this._functionBySpaceKey.has(space.key)) {\n continue;\n }\n\n const registered: FunctionDef[] = [];\n this._functionBySpaceKey.set(space.key, registered);\n await space.waitUntilReady();\n if (this._ctx.disposed) {\n break;\n }\n\n // Subscribe to updates.\n this._ctx.onDispose(\n space.db.query(Filter.schema(FunctionDef)).subscribe(({ objects }) => {\n const { added } = diff(registered, objects, (a, b) => a.uri === b.uri);\n // TODO(burdon): Update and remove.\n if (added.length > 0) {\n registered.push(...added);\n this.registered.emit({ space, added });\n }\n }),\n );\n }\n });\n\n // TODO(burdon): API: Normalize unsubscribe methods.\n this._ctx.onDispose(() => spacesSubscription.unsubscribe());\n }\n\n protected override async _close(_: Context): Promise<void> {\n log.info('closing...');\n this._functionBySpaceKey.clear();\n }\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { debounce, UpdateScheduler } from '@dxos/async';\nimport { Filter, type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { createSubscription, type Query } from '@dxos/echo-db';\nimport { log } from '@dxos/log';\n\nimport type { SubscriptionTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createSubscriptionTrigger: TriggerFactory<SubscriptionTrigger> = async (\n ctx: Context,\n space: Space,\n spec: SubscriptionTrigger,\n callback: TriggerCallback,\n) => {\n const objectIds = new Set<string>();\n const task = new UpdateScheduler(\n ctx,\n async () => {\n if (objectIds.size > 0) {\n const objects = Array.from(objectIds);\n objectIds.clear();\n await callback({ objects });\n }\n },\n { maxFrequency: 4 },\n );\n\n // TODO(burdon): Factor out diff.\n // TODO(burdon): Don't fire initially?\n // TODO(burdon): Create queue. Only allow one invocation per trigger at a time?\n const subscriptions: (() => void)[] = [];\n const subscription = createSubscription(({ added, updated }) => {\n const sizeBefore = objectIds.size;\n for (const object of added) {\n objectIds.add(object.id);\n }\n for (const object of updated) {\n objectIds.add(object.id);\n }\n if (objectIds.size > sizeBefore) {\n log.info('updated', { added: added.length, updated: updated.length });\n task.trigger();\n }\n });\n\n subscriptions.push(() => subscription.unsubscribe());\n\n // TODO(burdon): Disable trigger if keeps failing.\n const { filter, options: { deep, delay } = {} } = spec;\n const update = ({ objects }: Query) => {\n log.info('update', { objects: objects.length });\n subscription.update(objects);\n\n // TODO(burdon): Hack to monitor changes to Document's text object.\n if (deep) {\n // TODO(dmaretskyi): Removed to not have dependency on markdown-plugin.\n // for (const object of objects) {\n // const content = object.content;\n // if (content instanceof TextType) {\n // subscriptions.push(getObjectCore(content).updates.on(debounce(() => subscription.update([object]), 1_000)));\n // }\n // }\n }\n };\n\n // TODO(burdon): OR not working.\n // TODO(burdon): [Bug]: all callbacks are fired on the first mutation.\n // TODO(burdon): [Bug]: not updated when document is deleted (either top or hierarchically).\n log.info('subscription', { filter });\n // const query = triggerCtx.space.db.query(Filter.or(filter.map(({ type, props }) => Filter.typename(type, props))));\n if (filter.type) {\n const query = space.db.query(Filter.typename(filter.type, filter.props));\n subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));\n }\n\n ctx.onDispose(() => {\n subscriptions.forEach((unsubscribe) => unsubscribe());\n });\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { CronJob } from 'cron';\n\nimport { DeferredTask } from '@dxos/async';\nimport { type Space } from '@dxos/client/echo';\nimport { type Context } from '@dxos/context';\nimport { log } from '@dxos/log';\n\nimport type { TimerTrigger } from '../../types';\nimport { type TriggerCallback, type TriggerFactory } from '../trigger-registry';\n\nexport const createTimerTrigger: TriggerFactory<TimerTrigger> = async (\n ctx: Context,\n space: Space,\n spec: TimerTrigger,\n callback: TriggerCallback,\n) => {\n const task = new DeferredTask(ctx, async () => {\n await callback({});\n });\n\n let last = 0;\n let run = 0;\n // https://www.npmjs.com/package/cron#constructor\n const job = CronJob.from({\n cronTime: spec.cron,\n runOnInit: false,\n onTick: () => {\n // TODO(burdon): Check greater than 30s (use cron-parser).\n const now = Date.now();\n const delta = last ? now - last : 0;\n last = now;\n\n run++;\n log.info('tick', { space: space.key.truncate(), count: run, delta });\n task.schedule();\n },\n });\n\n job.start();\n ctx.onDispose(() => job.stop());\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { create, Filter, getMeta, type Space, compareForeignKeys } from '@dxos/client/echo';\nimport { Context, Resource } from '@dxos/context';\nimport { ECHO_ATTR_META, foreignKey } from '@dxos/echo-schema';\nimport { invariant } from '@dxos/invariant';\nimport { PublicKey } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { ComplexMap, diff } from '@dxos/util';\n\nimport { createSubscriptionTrigger, createTimerTrigger } from './type';\nimport { type FunctionManifest, FunctionTrigger, type TriggerKind, type TriggerType } from '../types';\n\ntype ResponseCode = number;\n\nexport type TriggerCallback = (args: object) => Promise<ResponseCode>;\n\n// TODO(burdon): Make object?\nexport type TriggerFactory<Spec extends TriggerType, Options = any> = (\n ctx: Context,\n space: Space,\n spec: Spec,\n callback: TriggerCallback,\n options?: Options,\n) => Promise<void>;\n\nexport type TriggerFactoryMap = Partial<Record<TriggerKind, TriggerFactory<any>>>;\n\nconst triggerFactory: TriggerFactoryMap = {\n timer: createTimerTrigger,\n // TODO(burdon): Cannot use in browser.\n // webhook: createWebhookTrigger,\n subscription: createSubscriptionTrigger,\n};\n\nexport type TriggerEvent = {\n space: Space;\n triggers: FunctionTrigger[];\n};\n\ntype RegisteredTrigger = {\n activationCtx?: Context;\n trigger: FunctionTrigger;\n};\n\nexport class TriggerRegistry extends Resource {\n private readonly _triggersBySpaceKey = new ComplexMap<PublicKey, RegisteredTrigger[]>(PublicKey.hash);\n\n public readonly registered = new Event<TriggerEvent>();\n public readonly removed = new Event<TriggerEvent>();\n\n constructor(\n private readonly _client: Client,\n private readonly _options?: TriggerFactoryMap,\n ) {\n super();\n }\n\n public getActiveTriggers(space: Space): FunctionTrigger[] {\n return this._getTriggers(space, (t) => t.activationCtx != null);\n }\n\n public getInactiveTriggers(space: Space): FunctionTrigger[] {\n return this._getTriggers(space, (t) => t.activationCtx == null);\n }\n\n /**\n * Set callback for trigger.\n */\n public async activate(space: Space, trigger: FunctionTrigger, callback: TriggerCallback): Promise<void> {\n log('activate', { space: space.key, trigger });\n\n const activationCtx = new Context({ name: `FunctionTrigger-${trigger.function}` });\n this._ctx.onDispose(() => activationCtx.dispose());\n const registeredTrigger = this._triggersBySpaceKey.get(space.key)?.find((reg) => reg.trigger.id === trigger.id);\n invariant(registeredTrigger, `Trigger is not registered: ${trigger.function}`);\n registeredTrigger.activationCtx = activationCtx;\n\n try {\n // Create trigger.\n invariant(trigger.spec);\n const options = this._options?.[trigger.spec.type];\n const createTrigger = triggerFactory[trigger.spec.type];\n invariant(createTrigger, `Trigger factory not found: ${trigger.spec.type}`);\n await createTrigger(activationCtx, space, trigger.spec, callback, options);\n } catch (err) {\n delete registeredTrigger.activationCtx;\n throw err;\n }\n }\n\n /**\n * Loads triggers from the manifest into the space.\n */\n public async register(space: Space, manifest: FunctionManifest): Promise<void> {\n log('register', { space: space.key });\n if (!manifest.triggers?.length) {\n return;\n }\n\n if (!space.db.graph.schemaRegistry.hasSchema(FunctionTrigger)) {\n space.db.graph.schemaRegistry.addSchema([FunctionTrigger]);\n }\n\n // Create FK to enable syncing if none are set (NOTE: Possible collision).\n const manifestTriggers = manifest.triggers.map((trigger) => {\n let keys = trigger[ECHO_ATTR_META]?.keys;\n delete trigger[ECHO_ATTR_META];\n if (!keys?.length) {\n keys = [foreignKey('manifest', [trigger.function, trigger.spec?.type].join(':'))];\n }\n\n return create(FunctionTrigger, trigger, { keys });\n });\n\n // Sync triggers.\n const { objects: existing } = await space.db.query(Filter.schema(FunctionTrigger)).run();\n const { added } = diff(existing, manifestTriggers, compareForeignKeys);\n\n // TODO(burdon): Update existing.\n added.forEach((trigger) => {\n space.db.add(trigger);\n log.info('added', { meta: getMeta(trigger) });\n });\n\n if (added.length > 0) {\n await space.db.flush();\n }\n }\n\n protected override async _open(): Promise<void> {\n log.info('open...');\n const spaceListSubscription = this._client.spaces.subscribe(async (spaces) => {\n for (const space of spaces) {\n if (this._triggersBySpaceKey.has(space.key)) {\n continue;\n }\n\n const registered: RegisteredTrigger[] = [];\n this._triggersBySpaceKey.set(space.key, registered);\n await space.waitUntilReady();\n if (this._ctx.disposed) {\n break;\n }\n\n // Subscribe to updates.\n this._ctx.onDispose(\n space.db.query(Filter.schema(FunctionTrigger)).subscribe(async ({ objects: current }) => {\n log.info('update', { space: space.key, registered: registered.length, current: current.length });\n await this._handleRemovedTriggers(space, current, registered);\n this._handleNewTriggers(space, current, registered);\n }),\n );\n }\n });\n\n this._ctx.onDispose(() => spaceListSubscription.unsubscribe());\n log.info('opened');\n }\n\n protected override async _close(_: Context): Promise<void> {\n log.info('close...');\n this._triggersBySpaceKey.clear();\n log.info('closed');\n }\n\n private _handleNewTriggers(space: Space, current: FunctionTrigger[], registered: RegisteredTrigger[]) {\n const added = current.filter((candidate) => {\n return candidate.enabled && registered.find((reg) => reg.trigger.id === candidate.id) == null;\n });\n\n if (added.length > 0) {\n const newRegisteredTriggers: RegisteredTrigger[] = added.map((trigger) => ({ trigger }));\n registered.push(...newRegisteredTriggers);\n log.info('added', () => ({\n spaceKey: space.key,\n triggers: added.map((trigger) => trigger.function),\n }));\n\n this.registered.emit({ space, triggers: added });\n }\n }\n\n private async _handleRemovedTriggers(\n space: Space,\n current: FunctionTrigger[],\n registered: RegisteredTrigger[],\n ): Promise<void> {\n const removed: FunctionTrigger[] = [];\n for (let i = registered.length - 1; i >= 0; i--) {\n const wasRemoved =\n current.filter((trigger) => trigger.enabled).find((trigger) => trigger.id === registered[i].trigger.id) == null;\n if (wasRemoved) {\n const unregistered = registered.splice(i, 1)[0];\n await unregistered.activationCtx?.dispose();\n removed.push(unregistered.trigger);\n }\n }\n\n if (removed.length > 0) {\n log.info('removed', () => ({\n spaceKey: space.key,\n triggers: removed.map((trigger) => trigger.function),\n }));\n\n this.removed.emit({ space, triggers: removed });\n }\n }\n\n private _getTriggers(space: Space, predicate: (trigger: RegisteredTrigger) => boolean): FunctionTrigger[] {\n const allSpaceTriggers = this._triggersBySpaceKey.get(space.key) ?? [];\n return allSpaceTriggers.filter(predicate).map((trigger) => trigger.trigger);\n }\n}\n"],
5
- "mappings": ";;;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E,MAAAA,KAAI+C,KAAK,SAAS,OAAO;QACvBwB,UAAU/E,MAAMS;QAChBoB,UAAUqB,MAAMZ,IAAI,CAAChC,YAAYA,QAAQM,QAAQ;MACnD,IAAA;;;;;;AAEA,WAAKhB,WAAWoF,KAAK;QAAEhF;QAAO6B,UAAUqB;MAAM,CAAA;IAChD;EACF;EAEA,MAAckB,uBACZpE,OACAmE,SACAvE,YACe;AACf,UAAME,UAA6B,CAAA;AACnC,aAASmF,IAAIrF,WAAWkC,SAAS,GAAGmD,KAAK,GAAGA,KAAK;AAC/C,YAAMC,aACJf,QAAQO,OAAO,CAACpE,YAAYA,QAAQsE,OAAO,EAAE1D,KAAK,CAACZ,YAAYA,QAAQc,OAAOxB,WAAWqF,CAAAA,EAAG3E,QAAQc,EAAE,KAAK;AAC7G,UAAI8D,YAAY;AACd,cAAMC,eAAevF,WAAWwF,OAAOH,GAAG,CAAA,EAAG,CAAA;AAC7C,cAAME,aAAahF,eAAeY,QAAAA;AAClCjB,gBAAQgF,KAAKK,aAAa7E,OAAO;MACnC;IACF;AAEA,QAAIR,QAAQgC,SAAS,GAAG;AACtBtB,MAAAA,KAAI+C,KAAK,WAAW,OAAO;QACzBwB,UAAU/E,MAAMS;QAChBoB,UAAU/B,QAAQwC,IAAI,CAAChC,YAAYA,QAAQM,QAAQ;MACrD,IAAA;;;;;;AAEA,WAAKd,QAAQkF,KAAK;QAAEhF;QAAO6B,UAAU/B;MAAQ,CAAA;IAC/C;EACF;EAEQG,aAAaD,OAAcqF,WAAuE;AACxG,UAAMC,mBAAmB,KAAK9F,oBAAoByB,IAAIjB,MAAMS,GAAG,KAAK,CAAA;AACpE,WAAO6E,iBAAiBZ,OAAOW,SAAAA,EAAW/C,IAAI,CAAChC,YAAYA,QAAQA,OAAO;EAC5E;AACF;",
6
- "names": ["Event", "create", "Filter", "Resource", "PublicKey", "log", "ComplexMap", "diff", "FunctionRegistry", "Resource", "constructor", "_client", "_functionBySpaceKey", "ComplexMap", "PublicKey", "hash", "registered", "Event", "getFunctions", "space", "get", "key", "getUniqueByUri", "uniqueByUri", "values", "flatMap", "defs", "reduce", "acc", "v", "set", "uri", "Map", "register", "functions", "log", "length", "db", "graph", "schemaRegistry", "hasSchema", "FunctionDef", "addSchema", "objects", "existing", "query", "Filter", "schema", "run", "added", "diff", "a", "b", "forEach", "def", "add", "create", "flush", "indexes", "updates", "_open", "info", "spacesSubscription", "spaces", "subscribe", "has", "waitUntilReady", "_ctx", "disposed", "onDispose", "push", "emit", "unsubscribe", "_close", "_", "clear", "debounce", "UpdateScheduler", "Filter", "createSubscription", "log", "createSubscriptionTrigger", "ctx", "space", "spec", "callback", "objectIds", "Set", "task", "size", "objects", "Array", "from", "clear", "maxFrequency", "subscriptions", "subscription", "added", "updated", "sizeBefore", "object", "add", "id", "info", "length", "trigger", "push", "unsubscribe", "filter", "options", "deep", "delay", "update", "type", "query", "db", "typename", "props", "subscribe", "onDispose", "forEach", "CronJob", "DeferredTask", "log", "createTimerTrigger", "ctx", "space", "spec", "callback", "task", "last", "run", "job", "from", "cronTime", "cron", "runOnInit", "onTick", "now", "Date", "delta", "info", "key", "truncate", "count", "schedule", "start", "onDispose", "stop", "Event", "create", "Filter", "getMeta", "compareForeignKeys", "Context", "Resource", "ECHO_ATTR_META", "foreignKey", "invariant", "PublicKey", "log", "ComplexMap", "diff", "triggerFactory", "timer", "createTimerTrigger", "subscription", "createSubscriptionTrigger", "TriggerRegistry", "Resource", "constructor", "_client", "_options", "_triggersBySpaceKey", "ComplexMap", "PublicKey", "hash", "registered", "Event", "removed", "getActiveTriggers", "space", "_getTriggers", "t", "activationCtx", "getInactiveTriggers", "activate", "trigger", "callback", "log", "key", "Context", "name", "function", "_ctx", "onDispose", "dispose", "registeredTrigger", "get", "find", "reg", "id", "invariant", "spec", "options", "type", "createTrigger", "err", "register", "manifest", "triggers", "length", "db", "graph", "schemaRegistry", "hasSchema", "FunctionTrigger", "addSchema", "manifestTriggers", "map", "keys", "ECHO_ATTR_META", "foreignKey", "join", "create", "objects", "existing", "query", "Filter", "schema", "run", "added", "diff", "compareForeignKeys", "forEach", "add", "info", "meta", "getMeta", "flush", "_open", "spaceListSubscription", "spaces", "subscribe", "has", "set", "waitUntilReady", "disposed", "current", "_handleRemovedTriggers", "_handleNewTriggers", "unsubscribe", "_close", "_", "clear", "filter", "candidate", "enabled", "newRegisteredTriggers", "push", "spaceKey", "emit", "i", "wasRemoved", "unregistered", "splice", "predicate", "allSpaceTriggers"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts", "../../../src/types/trace.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(Tra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AAAA;AACtB,CAAA,EAAGyB,KAAKC,WAAW,4BAA4B,OAAA,CAAA;",
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"]
7
- }