@dxos/functions 0.8.1 → 0.8.2-main.10c050d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/bundler/index.mjs +0 -3
- package/dist/lib/browser/bundler/index.mjs.map +3 -3
- package/dist/lib/browser/edge/index.mjs +63 -7
- package/dist/lib/browser/edge/index.mjs.map +4 -4
- package/dist/lib/browser/index.mjs +513 -100
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/bundler/index.cjs +0 -1
- package/dist/lib/node/bundler/index.cjs.map +3 -3
- package/dist/lib/node/edge/index.cjs +65 -5
- package/dist/lib/node/edge/index.cjs.map +4 -4
- package/dist/lib/node/index.cjs +519 -92
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/bundler/index.mjs +0 -1
- package/dist/lib/node-esm/bundler/index.mjs.map +3 -3
- package/dist/lib/node-esm/edge/index.mjs +64 -6
- package/dist/lib/node-esm/edge/index.mjs.map +4 -4
- package/dist/lib/node-esm/index.mjs +513 -98
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/bundler/bundler.d.ts.map +1 -1
- package/dist/types/src/edge/functions.d.ts +3 -3
- package/dist/types/src/edge/functions.d.ts.map +1 -1
- package/dist/types/src/edge/index.d.ts.map +1 -1
- package/dist/types/src/executor/executor.d.ts +8 -0
- package/dist/types/src/executor/executor.d.ts.map +1 -0
- package/dist/types/src/executor/index.d.ts +2 -0
- package/dist/types/src/executor/index.d.ts.map +1 -0
- package/dist/types/src/handler.d.ts +23 -67
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +5 -3
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/schema.d.ts +57 -0
- package/dist/types/src/schema.d.ts.map +1 -0
- package/dist/types/src/services/ai.d.ts +9 -0
- package/dist/types/src/services/ai.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +30 -0
- package/dist/types/src/services/credentials.d.ts.map +1 -0
- package/dist/types/src/services/database.d.ts +9 -0
- package/dist/types/src/services/database.d.ts.map +1 -0
- package/dist/types/src/services/index.d.ts +7 -0
- package/dist/types/src/services/index.d.ts.map +1 -0
- package/dist/types/src/services/queues.d.ts +10 -0
- package/dist/types/src/services/queues.d.ts.map +1 -0
- package/dist/types/src/services/service-container.d.ts +25 -0
- package/dist/types/src/services/service-container.d.ts.map +1 -0
- package/dist/types/src/services/tracing.d.ts +15 -0
- package/dist/types/src/services/tracing.d.ts.map +1 -0
- package/dist/types/src/trace.d.ts +149 -0
- package/dist/types/src/trace.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +2 -1
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +407 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/dist/types/src/{types/url.d.ts → url.d.ts} +6 -0
- package/dist/types/src/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -36
- package/src/bundler/bundler.ts +7 -1
- package/src/edge/functions.ts +7 -4
- package/src/edge/index.ts +4 -0
- package/src/executor/executor.ts +47 -0
- package/src/executor/index.ts +5 -0
- package/src/handler.ts +29 -125
- package/src/index.ts +8 -5
- package/src/schema.ts +52 -0
- package/src/services/ai.ts +15 -0
- package/src/services/credentials.ts +55 -0
- package/src/services/database.ts +14 -0
- package/src/services/index.ts +10 -0
- package/src/services/queues.ts +16 -0
- package/src/services/service-container.ts +58 -0
- package/src/services/tracing.ts +27 -0
- package/src/{types/trace.ts → trace.ts} +37 -35
- package/src/translations.ts +1 -1
- package/src/types.ts +211 -0
- package/src/{types/url.ts → url.ts} +5 -0
- package/dist/lib/browser/chunk-HI7YZO2K.mjs +0 -482
- package/dist/lib/browser/chunk-HI7YZO2K.mjs.map +0 -7
- package/dist/lib/browser/chunk-LT4LR4VU.mjs +0 -72
- package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +0 -7
- package/dist/lib/browser/chunk-RVSG6WTL.mjs +0 -358
- package/dist/lib/browser/chunk-RVSG6WTL.mjs.map +0 -7
- package/dist/lib/browser/chunk-XRCXIG74.mjs +0 -12
- package/dist/lib/browser/chunk-XRCXIG74.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -670
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/browser/types/index.mjs +0 -49
- package/dist/lib/browser/types/index.mjs.map +0 -7
- package/dist/lib/node/chunk-DSUGRAAL.cjs +0 -392
- package/dist/lib/node/chunk-DSUGRAAL.cjs.map +0 -7
- package/dist/lib/node/chunk-JEQ2X3Z6.cjs +0 -34
- package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +0 -7
- package/dist/lib/node/chunk-NXZNXVT3.cjs +0 -94
- package/dist/lib/node/chunk-NXZNXVT3.cjs.map +0 -7
- package/dist/lib/node/chunk-RXMCVAMJ.cjs +0 -496
- package/dist/lib/node/chunk-RXMCVAMJ.cjs.map +0 -7
- package/dist/lib/node/testing/index.cjs +0 -687
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node/types/index.cjs +0 -70
- package/dist/lib/node/types/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +0 -12
- package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HBD2FZXO.mjs +0 -358
- package/dist/lib/node-esm/chunk-HBD2FZXO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +0 -72
- package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-SQSJO5HI.mjs +0 -482
- package/dist/lib/node-esm/chunk-SQSJO5HI.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -670
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/types/index.mjs +0 -49
- package/dist/lib/node-esm/types/index.mjs.map +0 -7
- package/dist/types/src/browser/index.d.ts +0 -2
- package/dist/types/src/browser/index.d.ts.map +0 -1
- package/dist/types/src/function/function-registry.d.ts +0 -25
- package/dist/types/src/function/function-registry.d.ts.map +0 -1
- package/dist/types/src/function/function-registry.test.d.ts +0 -2
- package/dist/types/src/function/function-registry.test.d.ts.map +0 -1
- package/dist/types/src/function/index.d.ts +0 -2
- package/dist/types/src/function/index.d.ts.map +0 -1
- package/dist/types/src/runtime/dev-server.d.ts +0 -52
- package/dist/types/src/runtime/dev-server.d.ts.map +0 -1
- package/dist/types/src/runtime/dev-server.test.d.ts +0 -2
- package/dist/types/src/runtime/dev-server.test.d.ts.map +0 -1
- package/dist/types/src/runtime/index.d.ts +0 -3
- package/dist/types/src/runtime/index.d.ts.map +0 -1
- package/dist/types/src/runtime/scheduler.d.ts +0 -34
- package/dist/types/src/runtime/scheduler.d.ts.map +0 -1
- package/dist/types/src/runtime/scheduler.test.d.ts +0 -2
- package/dist/types/src/runtime/scheduler.test.d.ts.map +0 -1
- package/dist/types/src/testing/functions-integration.test.d.ts +0 -2
- package/dist/types/src/testing/functions-integration.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -5
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/manifest.d.ts +0 -3
- package/dist/types/src/testing/manifest.d.ts.map +0 -1
- package/dist/types/src/testing/plugin-init.d.ts +0 -6
- package/dist/types/src/testing/plugin-init.d.ts.map +0 -1
- package/dist/types/src/testing/setup.d.ts +0 -15
- package/dist/types/src/testing/setup.d.ts.map +0 -1
- package/dist/types/src/testing/test/handler.d.ts +0 -4
- package/dist/types/src/testing/test/handler.d.ts.map +0 -1
- package/dist/types/src/testing/test/index.d.ts +0 -3
- package/dist/types/src/testing/test/index.d.ts.map +0 -1
- package/dist/types/src/testing/types.d.ts +0 -10
- package/dist/types/src/testing/types.d.ts.map +0 -1
- package/dist/types/src/testing/util.d.ts +0 -5
- package/dist/types/src/testing/util.d.ts.map +0 -1
- package/dist/types/src/trigger/index.d.ts +0 -3
- package/dist/types/src/trigger/index.d.ts.map +0 -1
- package/dist/types/src/trigger/trigger-registry.d.ts +0 -38
- package/dist/types/src/trigger/trigger-registry.d.ts.map +0 -1
- package/dist/types/src/trigger/trigger-registry.test.d.ts +0 -2
- package/dist/types/src/trigger/trigger-registry.test.d.ts.map +0 -1
- package/dist/types/src/trigger/type/index.d.ts +0 -3
- package/dist/types/src/trigger/type/index.d.ts.map +0 -1
- package/dist/types/src/trigger/type/subscription-trigger.d.ts +0 -4
- package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +0 -1
- package/dist/types/src/trigger/type/timer-trigger.d.ts +0 -4
- package/dist/types/src/trigger/type/timer-trigger.d.ts.map +0 -1
- package/dist/types/src/trigger/type/webhook-trigger.d.ts +0 -4
- package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +0 -1
- package/dist/types/src/types/index.d.ts +0 -5
- package/dist/types/src/types/index.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -53
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/dist/types/src/types/trace.d.ts +0 -146
- package/dist/types/src/types/trace.d.ts.map +0 -1
- package/dist/types/src/types/types.d.ts +0 -265
- package/dist/types/src/types/types.d.ts.map +0 -1
- package/dist/types/src/types/url.d.ts.map +0 -1
- package/dist/types/tools/schema.d.ts +0 -2
- package/dist/types/tools/schema.d.ts.map +0 -1
- package/schema/functions.json +0 -211
- package/src/browser/index.ts +0 -5
- package/src/function/function-registry.test.ts +0 -118
- package/src/function/function-registry.ts +0 -104
- package/src/function/index.ts +0 -5
- package/src/runtime/dev-server.test.ts +0 -79
- package/src/runtime/dev-server.ts +0 -240
- package/src/runtime/index.ts +0 -6
- package/src/runtime/scheduler.test.ts +0 -152
- package/src/runtime/scheduler.ts +0 -170
- package/src/testing/functions-integration.test.ts +0 -65
- package/src/testing/index.ts +0 -8
- package/src/testing/manifest.ts +0 -15
- package/src/testing/plugin-init.ts +0 -20
- package/src/testing/setup.ts +0 -109
- package/src/testing/test/handler.ts +0 -15
- package/src/testing/test/index.ts +0 -7
- package/src/testing/types.ts +0 -9
- package/src/testing/util.ts +0 -26
- package/src/trigger/index.ts +0 -6
- package/src/trigger/trigger-registry.test.ts +0 -278
- package/src/trigger/trigger-registry.ts +0 -218
- package/src/trigger/type/index.ts +0 -7
- package/src/trigger/type/subscription-trigger.ts +0 -84
- package/src/trigger/type/timer-trigger.ts +0 -48
- package/src/trigger/type/webhook-trigger.ts +0 -48
- package/src/types/index.ts +0 -8
- package/src/types/schema.ts +0 -46
- package/src/types/types.ts +0 -163
package/src/types.ts
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Schema, SchemaAST } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { Expando, OptionsAnnotationId, TypedObject, Ref, RawObject } from '@dxos/echo-schema';
|
|
8
|
+
import { DXN } from '@dxos/keys';
|
|
9
|
+
|
|
10
|
+
import { FunctionType } from './schema';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Type discriminator for TriggerType.
|
|
14
|
+
* Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
|
|
15
|
+
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
16
|
+
*/
|
|
17
|
+
export enum TriggerKind {
|
|
18
|
+
Timer = 'timer',
|
|
19
|
+
Webhook = 'webhook',
|
|
20
|
+
Subscription = 'subscription',
|
|
21
|
+
Email = 'email',
|
|
22
|
+
Queue = 'queue',
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const kindLiteralAnnotations = { title: 'Kind' };
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Cron timer.
|
|
29
|
+
*/
|
|
30
|
+
const TimerTriggerSchema = Schema.Struct({
|
|
31
|
+
kind: Schema.Literal(TriggerKind.Timer).annotations(kindLiteralAnnotations),
|
|
32
|
+
cron: Schema.String.annotations({
|
|
33
|
+
title: 'Cron',
|
|
34
|
+
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
35
|
+
}),
|
|
36
|
+
}).pipe(Schema.mutable);
|
|
37
|
+
export type TimerTrigger = Schema.Schema.Type<typeof TimerTriggerSchema>;
|
|
38
|
+
|
|
39
|
+
const EmailTriggerSchema = Schema.Struct({
|
|
40
|
+
kind: Schema.Literal(TriggerKind.Email).annotations(kindLiteralAnnotations),
|
|
41
|
+
}).pipe(Schema.mutable);
|
|
42
|
+
export type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;
|
|
43
|
+
|
|
44
|
+
const QueueTriggerSchema = Schema.Struct({
|
|
45
|
+
kind: Schema.Literal(TriggerKind.Queue).annotations(kindLiteralAnnotations),
|
|
46
|
+
queue: DXN.Schema,
|
|
47
|
+
}).pipe(Schema.mutable);
|
|
48
|
+
export type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Webhook.
|
|
52
|
+
*/
|
|
53
|
+
const WebhookTriggerSchema = Schema.Struct({
|
|
54
|
+
kind: Schema.Literal(TriggerKind.Webhook).annotations(kindLiteralAnnotations),
|
|
55
|
+
method: Schema.optional(
|
|
56
|
+
Schema.String.annotations({
|
|
57
|
+
title: 'Method',
|
|
58
|
+
[OptionsAnnotationId]: ['GET', 'POST'],
|
|
59
|
+
}),
|
|
60
|
+
),
|
|
61
|
+
port: Schema.optional(
|
|
62
|
+
Schema.Number.annotations({
|
|
63
|
+
title: 'Port',
|
|
64
|
+
}),
|
|
65
|
+
),
|
|
66
|
+
}).pipe(Schema.mutable);
|
|
67
|
+
export type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;
|
|
68
|
+
|
|
69
|
+
// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).
|
|
70
|
+
const QuerySchema = Schema.Struct({
|
|
71
|
+
type: Schema.optional(Schema.String.annotations({ title: 'Type' })),
|
|
72
|
+
props: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
73
|
+
}).annotations({ title: 'Query' });
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Subscription.
|
|
77
|
+
*/
|
|
78
|
+
const SubscriptionTriggerSchema = Schema.Struct({
|
|
79
|
+
kind: Schema.Literal(TriggerKind.Subscription).annotations(kindLiteralAnnotations),
|
|
80
|
+
// TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
|
|
81
|
+
filter: QuerySchema,
|
|
82
|
+
options: Schema.optional(
|
|
83
|
+
Schema.Struct({
|
|
84
|
+
// Watch changes to object (not just creation).
|
|
85
|
+
deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
|
|
86
|
+
// Debounce changes (delay in ms).
|
|
87
|
+
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
88
|
+
}).annotations({ title: 'Options' }),
|
|
89
|
+
),
|
|
90
|
+
}).pipe(Schema.mutable);
|
|
91
|
+
export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Trigger schema (discriminated union).
|
|
95
|
+
*/
|
|
96
|
+
export const TriggerSchema = Schema.Union(
|
|
97
|
+
TimerTriggerSchema,
|
|
98
|
+
WebhookTriggerSchema,
|
|
99
|
+
SubscriptionTriggerSchema,
|
|
100
|
+
EmailTriggerSchema,
|
|
101
|
+
QueueTriggerSchema,
|
|
102
|
+
).annotations({
|
|
103
|
+
title: 'Trigger',
|
|
104
|
+
});
|
|
105
|
+
export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
|
|
106
|
+
|
|
107
|
+
export type EventType =
|
|
108
|
+
| EmailTriggerOutput
|
|
109
|
+
| WebhookTriggerOutput
|
|
110
|
+
| QueueTriggerOutput
|
|
111
|
+
| SubscriptionTriggerOutput
|
|
112
|
+
| TimerTriggerOutput;
|
|
113
|
+
|
|
114
|
+
// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
|
|
115
|
+
export const EmailTriggerOutput = Schema.mutable(
|
|
116
|
+
Schema.Struct({
|
|
117
|
+
from: Schema.String,
|
|
118
|
+
to: Schema.String,
|
|
119
|
+
subject: Schema.String,
|
|
120
|
+
created: Schema.String,
|
|
121
|
+
body: Schema.String,
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
export type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;
|
|
125
|
+
|
|
126
|
+
export const WebhookTriggerOutput = Schema.mutable(
|
|
127
|
+
Schema.Struct({
|
|
128
|
+
url: Schema.String,
|
|
129
|
+
method: Schema.Literal('GET', 'POST'),
|
|
130
|
+
headers: Schema.Record({ key: Schema.String, value: Schema.String }),
|
|
131
|
+
bodyText: Schema.String,
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;
|
|
135
|
+
|
|
136
|
+
export const QueueTriggerOutput = Schema.mutable(
|
|
137
|
+
Schema.Struct({
|
|
138
|
+
queue: DXN.Schema,
|
|
139
|
+
item: Schema.Any,
|
|
140
|
+
cursor: Schema.String,
|
|
141
|
+
}),
|
|
142
|
+
);
|
|
143
|
+
export type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;
|
|
144
|
+
|
|
145
|
+
export const SubscriptionTriggerOutput = Schema.mutable(
|
|
146
|
+
Schema.Struct({ type: Schema.String, changedObjectId: Schema.String }),
|
|
147
|
+
);
|
|
148
|
+
export type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;
|
|
149
|
+
|
|
150
|
+
export const TimerTriggerOutput = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
|
|
151
|
+
export type TimerTriggerOutput = Schema.Schema.Type<typeof TimerTriggerOutput>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Function trigger.
|
|
155
|
+
* Function is invoked with the `payload` passed as input data.
|
|
156
|
+
* The event that triggers the function is available in the function context.
|
|
157
|
+
*/
|
|
158
|
+
export const FunctionTriggerSchema = Schema.Struct({
|
|
159
|
+
/**
|
|
160
|
+
* Function or workflow to invoke.
|
|
161
|
+
*/
|
|
162
|
+
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
163
|
+
function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Only used for workflowSchema.
|
|
167
|
+
* Specifies the input node in the circuit.
|
|
168
|
+
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
169
|
+
*/
|
|
170
|
+
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
171
|
+
|
|
172
|
+
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
173
|
+
|
|
174
|
+
spec: Schema.optional(TriggerSchema),
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Passed as the input data to the function.
|
|
178
|
+
* Must match the function's input schema.
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* {
|
|
182
|
+
* item: '{{$.trigger.event}}',
|
|
183
|
+
* instructions: 'Summarize and perform entity-extraction'
|
|
184
|
+
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
185
|
+
* }
|
|
186
|
+
*/
|
|
187
|
+
input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
export type FunctionTriggerType = Schema.Schema.Type<typeof FunctionTriggerSchema>;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Function trigger.
|
|
194
|
+
*/
|
|
195
|
+
export class FunctionTrigger extends TypedObject({
|
|
196
|
+
typename: 'dxos.org/type/FunctionTrigger',
|
|
197
|
+
version: '0.2.0',
|
|
198
|
+
})(FunctionTriggerSchema.fields) {}
|
|
199
|
+
|
|
200
|
+
// TODO(wittjosiah): Remove?
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Function manifest file.
|
|
204
|
+
*/
|
|
205
|
+
export const FunctionManifestSchema = Schema.Struct({
|
|
206
|
+
functions: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionType)))),
|
|
207
|
+
triggers: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionTrigger)))),
|
|
208
|
+
});
|
|
209
|
+
export type FunctionManifest = Schema.Schema.Type<typeof FunctionManifestSchema>;
|
|
210
|
+
|
|
211
|
+
export const FUNCTION_TYPES = [FunctionType, FunctionTrigger];
|
|
@@ -29,6 +29,11 @@ export const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: stri
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* NOTE: functionId is backend ID, not ECHO object id.
|
|
34
|
+
*/
|
|
35
|
+
export const makeFunctionUrl = (fn: { functionId: string }) => `/${fn.functionId}`;
|
|
36
|
+
|
|
32
37
|
export const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {
|
|
33
38
|
const baseUrl = new URL('functions/', edgeUrl);
|
|
34
39
|
|
|
@@ -1,482 +0,0 @@
|
|
|
1
|
-
import "@dxos/node-std/globals";
|
|
2
|
-
import {
|
|
3
|
-
FunctionDef,
|
|
4
|
-
FunctionTrigger
|
|
5
|
-
} from "./chunk-RVSG6WTL.mjs";
|
|
6
|
-
|
|
7
|
-
// packages/core/functions/src/function/function-registry.ts
|
|
8
|
-
import { Event } from "@dxos/async";
|
|
9
|
-
import { create, Filter } from "@dxos/client/echo";
|
|
10
|
-
import { Resource } from "@dxos/context";
|
|
11
|
-
import { PublicKey } from "@dxos/keys";
|
|
12
|
-
import { log } from "@dxos/log";
|
|
13
|
-
import { ComplexMap, diff } from "@dxos/util";
|
|
14
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/function/function-registry.ts";
|
|
15
|
-
var FunctionRegistry = class extends Resource {
|
|
16
|
-
constructor(_client) {
|
|
17
|
-
super();
|
|
18
|
-
this._client = _client;
|
|
19
|
-
this._functionBySpaceKey = new ComplexMap(PublicKey.hash);
|
|
20
|
-
this.registered = new Event();
|
|
21
|
-
}
|
|
22
|
-
getFunctions(space) {
|
|
23
|
-
return this._functionBySpaceKey.get(space.key) ?? [];
|
|
24
|
-
}
|
|
25
|
-
getUniqueByUri() {
|
|
26
|
-
const uniqueByUri = [
|
|
27
|
-
...this._functionBySpaceKey.values()
|
|
28
|
-
].flatMap((defs) => defs).reduce((acc, v) => {
|
|
29
|
-
acc.set(v.uri, v);
|
|
30
|
-
return acc;
|
|
31
|
-
}, /* @__PURE__ */ new Map());
|
|
32
|
-
return [
|
|
33
|
-
...uniqueByUri.values()
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Loads function definitions from the manifest into the space.
|
|
38
|
-
* We first load all the definitions from the space to deduplicate by functionId.
|
|
39
|
-
*/
|
|
40
|
-
async register(space, functions) {
|
|
41
|
-
log("register", {
|
|
42
|
-
space: space.key,
|
|
43
|
-
functions: functions?.length ?? 0
|
|
44
|
-
}, {
|
|
45
|
-
F: __dxlog_file,
|
|
46
|
-
L: 48,
|
|
47
|
-
S: this,
|
|
48
|
-
C: (f, a) => f(...a)
|
|
49
|
-
});
|
|
50
|
-
if (!functions?.length) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (!space.db.graph.schemaRegistry.hasSchema(FunctionDef)) {
|
|
54
|
-
space.db.graph.schemaRegistry.addSchema([
|
|
55
|
-
FunctionDef
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
58
|
-
const { objects: existing } = await space.db.query(Filter.schema(FunctionDef)).run();
|
|
59
|
-
const { added } = diff(existing, functions, (a, b) => a.uri === b.uri);
|
|
60
|
-
added.forEach((def) => space.db.add(create(FunctionDef, def)));
|
|
61
|
-
if (added.length > 0) {
|
|
62
|
-
await space.db.flush({
|
|
63
|
-
indexes: true,
|
|
64
|
-
updates: true
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
async _open() {
|
|
69
|
-
log.info("opening...", void 0, {
|
|
70
|
-
F: __dxlog_file,
|
|
71
|
-
L: 68,
|
|
72
|
-
S: this,
|
|
73
|
-
C: (f, a) => f(...a)
|
|
74
|
-
});
|
|
75
|
-
const spacesSubscription = this._client.spaces.subscribe(async (spaces) => {
|
|
76
|
-
for (const space of spaces) {
|
|
77
|
-
if (this._functionBySpaceKey.has(space.key)) {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
const registered = [];
|
|
81
|
-
this._functionBySpaceKey.set(space.key, registered);
|
|
82
|
-
await space.waitUntilReady();
|
|
83
|
-
if (this._ctx.disposed) {
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
this._ctx.onDispose(space.db.query(Filter.schema(FunctionDef)).subscribe(({ objects }) => {
|
|
87
|
-
const { added } = diff(registered, objects, (a, b) => a.uri === b.uri);
|
|
88
|
-
if (added.length > 0) {
|
|
89
|
-
registered.push(...added);
|
|
90
|
-
this.registered.emit({
|
|
91
|
-
space,
|
|
92
|
-
added
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}));
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
this._ctx.onDispose(() => spacesSubscription.unsubscribe());
|
|
99
|
-
}
|
|
100
|
-
async _close(_) {
|
|
101
|
-
log.info("closing...", void 0, {
|
|
102
|
-
F: __dxlog_file,
|
|
103
|
-
L: 101,
|
|
104
|
-
S: this,
|
|
105
|
-
C: (f, a) => f(...a)
|
|
106
|
-
});
|
|
107
|
-
this._functionBySpaceKey.clear();
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
// packages/core/functions/src/trigger/type/subscription-trigger.ts
|
|
112
|
-
import { debounce, UpdateScheduler } from "@dxos/async";
|
|
113
|
-
import { Filter as Filter2 } from "@dxos/client/echo";
|
|
114
|
-
import { createSubscription } from "@dxos/echo-db";
|
|
115
|
-
import { log as log2 } from "@dxos/log";
|
|
116
|
-
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/subscription-trigger.ts";
|
|
117
|
-
var createSubscriptionTrigger = async (ctx, space, spec, callback) => {
|
|
118
|
-
const objectIds = /* @__PURE__ */ new Set();
|
|
119
|
-
const task = new UpdateScheduler(ctx, async () => {
|
|
120
|
-
if (objectIds.size > 0) {
|
|
121
|
-
const objects = Array.from(objectIds);
|
|
122
|
-
objectIds.clear();
|
|
123
|
-
await callback({
|
|
124
|
-
objects
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}, {
|
|
128
|
-
maxFrequency: 4
|
|
129
|
-
});
|
|
130
|
-
const subscriptions = [];
|
|
131
|
-
const subscription = createSubscription(({ added, updated }) => {
|
|
132
|
-
const sizeBefore = objectIds.size;
|
|
133
|
-
for (const object of added) {
|
|
134
|
-
objectIds.add(object.id);
|
|
135
|
-
}
|
|
136
|
-
for (const object of updated) {
|
|
137
|
-
objectIds.add(object.id);
|
|
138
|
-
}
|
|
139
|
-
if (objectIds.size > sizeBefore) {
|
|
140
|
-
log2.info("updated", {
|
|
141
|
-
added: added.length,
|
|
142
|
-
updated: updated.length
|
|
143
|
-
}, {
|
|
144
|
-
F: __dxlog_file2,
|
|
145
|
-
L: 46,
|
|
146
|
-
S: void 0,
|
|
147
|
-
C: (f, a) => f(...a)
|
|
148
|
-
});
|
|
149
|
-
task.trigger();
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
subscriptions.push(() => subscription.unsubscribe());
|
|
153
|
-
const { filter, options: { deep, delay } = {} } = spec;
|
|
154
|
-
const update = ({ objects }) => {
|
|
155
|
-
log2.info("update", {
|
|
156
|
-
objects: objects.length
|
|
157
|
-
}, {
|
|
158
|
-
F: __dxlog_file2,
|
|
159
|
-
L: 56,
|
|
160
|
-
S: void 0,
|
|
161
|
-
C: (f, a) => f(...a)
|
|
162
|
-
});
|
|
163
|
-
subscription.update(objects);
|
|
164
|
-
if (deep) {
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
log2.info("subscription", {
|
|
168
|
-
filter
|
|
169
|
-
}, {
|
|
170
|
-
F: __dxlog_file2,
|
|
171
|
-
L: 74,
|
|
172
|
-
S: void 0,
|
|
173
|
-
C: (f, a) => f(...a)
|
|
174
|
-
});
|
|
175
|
-
if (filter.type) {
|
|
176
|
-
const query = space.db.query(Filter2.typename(filter.type, filter.props));
|
|
177
|
-
subscriptions.push(query.subscribe(delay ? debounce(update, delay) : update));
|
|
178
|
-
}
|
|
179
|
-
ctx.onDispose(() => {
|
|
180
|
-
subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
// packages/core/functions/src/trigger/type/timer-trigger.ts
|
|
185
|
-
import { parseCronExpression } from "cron-schedule";
|
|
186
|
-
import { DeferredTask } from "@dxos/async";
|
|
187
|
-
import { log as log3 } from "@dxos/log";
|
|
188
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/type/timer-trigger.ts";
|
|
189
|
-
var createTimerTrigger = async (ctx, space, spec, callback) => {
|
|
190
|
-
const task = new DeferredTask(ctx, async () => {
|
|
191
|
-
await callback({});
|
|
192
|
-
});
|
|
193
|
-
let last = 0;
|
|
194
|
-
let run = 0;
|
|
195
|
-
const schedule = parseCronExpression(spec.cron);
|
|
196
|
-
const getRunTimeout = () => Date.now() - schedule.getNextDate().getTime();
|
|
197
|
-
const runCron = () => {
|
|
198
|
-
if (ctx.disposed) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const now = Date.now();
|
|
202
|
-
const delta = last ? now - last : 0;
|
|
203
|
-
last = now;
|
|
204
|
-
run++;
|
|
205
|
-
log3.info("tick", {
|
|
206
|
-
space: space.key.truncate(),
|
|
207
|
-
count: run,
|
|
208
|
-
delta
|
|
209
|
-
}, {
|
|
210
|
-
F: __dxlog_file3,
|
|
211
|
-
L: 39,
|
|
212
|
-
S: void 0,
|
|
213
|
-
C: (f, a) => f(...a)
|
|
214
|
-
});
|
|
215
|
-
task.schedule();
|
|
216
|
-
timeout = setTimeout(runCron, getRunTimeout());
|
|
217
|
-
};
|
|
218
|
-
let timeout = setTimeout(runCron, getRunTimeout());
|
|
219
|
-
ctx.onDispose(() => clearTimeout(timeout));
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// packages/core/functions/src/trigger/trigger-registry.ts
|
|
223
|
-
import { Event as Event2 } from "@dxos/async";
|
|
224
|
-
import { create as create2, Filter as Filter3, getMeta, compareForeignKeys } from "@dxos/client/echo";
|
|
225
|
-
import { Context, Resource as Resource2 } from "@dxos/context";
|
|
226
|
-
import { ECHO_ATTR_META, foreignKey } from "@dxos/echo-schema";
|
|
227
|
-
import { invariant } from "@dxos/invariant";
|
|
228
|
-
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
229
|
-
import { log as log4 } from "@dxos/log";
|
|
230
|
-
import { ComplexMap as ComplexMap2, diff as diff2 } from "@dxos/util";
|
|
231
|
-
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/functions/src/trigger/trigger-registry.ts";
|
|
232
|
-
var triggerFactory = {
|
|
233
|
-
timer: createTimerTrigger,
|
|
234
|
-
// TODO(burdon): Cannot use in browser.
|
|
235
|
-
// webhook: createWebhookTrigger,
|
|
236
|
-
subscription: createSubscriptionTrigger
|
|
237
|
-
};
|
|
238
|
-
var TriggerRegistry = class extends Resource2 {
|
|
239
|
-
constructor(_client, _options) {
|
|
240
|
-
super();
|
|
241
|
-
this._client = _client;
|
|
242
|
-
this._options = _options;
|
|
243
|
-
this._triggersBySpaceKey = new ComplexMap2(PublicKey2.hash);
|
|
244
|
-
this.registered = new Event2();
|
|
245
|
-
this.removed = new Event2();
|
|
246
|
-
}
|
|
247
|
-
getActiveTriggers(space) {
|
|
248
|
-
return this._getTriggers(space, (t) => t.activationCtx != null);
|
|
249
|
-
}
|
|
250
|
-
getInactiveTriggers(space) {
|
|
251
|
-
return this._getTriggers(space, (t) => t.activationCtx == null);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Set callback for trigger.
|
|
255
|
-
*/
|
|
256
|
-
async activate(space, trigger, callback) {
|
|
257
|
-
log4("activate", {
|
|
258
|
-
space: space.key,
|
|
259
|
-
trigger
|
|
260
|
-
}, {
|
|
261
|
-
F: __dxlog_file4,
|
|
262
|
-
L: 75,
|
|
263
|
-
S: this,
|
|
264
|
-
C: (f, a) => f(...a)
|
|
265
|
-
});
|
|
266
|
-
const activationCtx = new Context({
|
|
267
|
-
name: `FunctionTrigger-${trigger.function}`
|
|
268
|
-
}, {
|
|
269
|
-
F: __dxlog_file4,
|
|
270
|
-
L: 77
|
|
271
|
-
});
|
|
272
|
-
this._ctx.onDispose(() => activationCtx.dispose());
|
|
273
|
-
const registeredTrigger = this._triggersBySpaceKey.get(space.key)?.find((reg) => reg.trigger.id === trigger.id);
|
|
274
|
-
invariant(registeredTrigger, `Trigger is not registered: ${trigger.function}`, {
|
|
275
|
-
F: __dxlog_file4,
|
|
276
|
-
L: 80,
|
|
277
|
-
S: this,
|
|
278
|
-
A: [
|
|
279
|
-
"registeredTrigger",
|
|
280
|
-
"`Trigger is not registered: ${trigger.function}`"
|
|
281
|
-
]
|
|
282
|
-
});
|
|
283
|
-
registeredTrigger.activationCtx = activationCtx;
|
|
284
|
-
try {
|
|
285
|
-
invariant(trigger.spec, void 0, {
|
|
286
|
-
F: __dxlog_file4,
|
|
287
|
-
L: 85,
|
|
288
|
-
S: this,
|
|
289
|
-
A: [
|
|
290
|
-
"trigger.spec",
|
|
291
|
-
""
|
|
292
|
-
]
|
|
293
|
-
});
|
|
294
|
-
const options = this._options?.[trigger.spec.type];
|
|
295
|
-
const createTrigger = triggerFactory[trigger.spec.type];
|
|
296
|
-
invariant(createTrigger, `Trigger factory not found: ${trigger.spec.type}`, {
|
|
297
|
-
F: __dxlog_file4,
|
|
298
|
-
L: 88,
|
|
299
|
-
S: this,
|
|
300
|
-
A: [
|
|
301
|
-
"createTrigger",
|
|
302
|
-
"`Trigger factory not found: ${trigger.spec.type}`"
|
|
303
|
-
]
|
|
304
|
-
});
|
|
305
|
-
await createTrigger(activationCtx, space, trigger.spec, callback, options);
|
|
306
|
-
} catch (err) {
|
|
307
|
-
delete registeredTrigger.activationCtx;
|
|
308
|
-
throw err;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Loads triggers from the manifest into the space.
|
|
313
|
-
*/
|
|
314
|
-
async register(space, manifest) {
|
|
315
|
-
log4("register", {
|
|
316
|
-
space: space.key
|
|
317
|
-
}, {
|
|
318
|
-
F: __dxlog_file4,
|
|
319
|
-
L: 100,
|
|
320
|
-
S: this,
|
|
321
|
-
C: (f, a) => f(...a)
|
|
322
|
-
});
|
|
323
|
-
if (!manifest.triggers?.length) {
|
|
324
|
-
return;
|
|
325
|
-
}
|
|
326
|
-
if (!space.db.graph.schemaRegistry.hasSchema(FunctionTrigger)) {
|
|
327
|
-
space.db.graph.schemaRegistry.addSchema([
|
|
328
|
-
FunctionTrigger
|
|
329
|
-
]);
|
|
330
|
-
}
|
|
331
|
-
const manifestTriggers = manifest.triggers.map((trigger) => {
|
|
332
|
-
let keys = trigger[ECHO_ATTR_META]?.keys;
|
|
333
|
-
delete trigger[ECHO_ATTR_META];
|
|
334
|
-
if (!keys?.length) {
|
|
335
|
-
keys = [
|
|
336
|
-
foreignKey("manifest", [
|
|
337
|
-
trigger.function,
|
|
338
|
-
trigger.spec?.type
|
|
339
|
-
].join(":"))
|
|
340
|
-
];
|
|
341
|
-
}
|
|
342
|
-
return create2(FunctionTrigger, trigger, {
|
|
343
|
-
keys
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
const { objects: existing } = await space.db.query(Filter3.schema(FunctionTrigger)).run();
|
|
347
|
-
const { added } = diff2(existing, manifestTriggers, compareForeignKeys);
|
|
348
|
-
added.forEach((trigger) => {
|
|
349
|
-
space.db.add(trigger);
|
|
350
|
-
log4.info("added", {
|
|
351
|
-
meta: getMeta(trigger)
|
|
352
|
-
}, {
|
|
353
|
-
F: __dxlog_file4,
|
|
354
|
-
L: 127,
|
|
355
|
-
S: this,
|
|
356
|
-
C: (f, a) => f(...a)
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
if (added.length > 0) {
|
|
360
|
-
await space.db.flush();
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
async _open() {
|
|
364
|
-
log4.info("open...", void 0, {
|
|
365
|
-
F: __dxlog_file4,
|
|
366
|
-
L: 136,
|
|
367
|
-
S: this,
|
|
368
|
-
C: (f, a) => f(...a)
|
|
369
|
-
});
|
|
370
|
-
const spaceListSubscription = this._client.spaces.subscribe(async (spaces) => {
|
|
371
|
-
for (const space of spaces) {
|
|
372
|
-
if (this._triggersBySpaceKey.has(space.key)) {
|
|
373
|
-
continue;
|
|
374
|
-
}
|
|
375
|
-
const registered = [];
|
|
376
|
-
this._triggersBySpaceKey.set(space.key, registered);
|
|
377
|
-
await space.waitUntilReady();
|
|
378
|
-
if (this._ctx.disposed) {
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
this._ctx.onDispose(space.db.query(Filter3.schema(FunctionTrigger)).subscribe(async ({ objects: current }) => {
|
|
382
|
-
log4.info("update", {
|
|
383
|
-
space: space.key,
|
|
384
|
-
registered: registered.length,
|
|
385
|
-
current: current.length
|
|
386
|
-
}, {
|
|
387
|
-
F: __dxlog_file4,
|
|
388
|
-
L: 153,
|
|
389
|
-
S: this,
|
|
390
|
-
C: (f, a) => f(...a)
|
|
391
|
-
});
|
|
392
|
-
await this._handleRemovedTriggers(space, current, registered);
|
|
393
|
-
this._handleNewTriggers(space, current, registered);
|
|
394
|
-
}));
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
this._ctx.onDispose(() => spaceListSubscription.unsubscribe());
|
|
398
|
-
log4.info("opened", void 0, {
|
|
399
|
-
F: __dxlog_file4,
|
|
400
|
-
L: 162,
|
|
401
|
-
S: this,
|
|
402
|
-
C: (f, a) => f(...a)
|
|
403
|
-
});
|
|
404
|
-
}
|
|
405
|
-
async _close(_) {
|
|
406
|
-
log4.info("close...", void 0, {
|
|
407
|
-
F: __dxlog_file4,
|
|
408
|
-
L: 166,
|
|
409
|
-
S: this,
|
|
410
|
-
C: (f, a) => f(...a)
|
|
411
|
-
});
|
|
412
|
-
this._triggersBySpaceKey.clear();
|
|
413
|
-
log4.info("closed", void 0, {
|
|
414
|
-
F: __dxlog_file4,
|
|
415
|
-
L: 168,
|
|
416
|
-
S: this,
|
|
417
|
-
C: (f, a) => f(...a)
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
_handleNewTriggers(space, current, registered) {
|
|
421
|
-
const added = current.filter((candidate) => {
|
|
422
|
-
return candidate.enabled && registered.find((reg) => reg.trigger.id === candidate.id) == null;
|
|
423
|
-
});
|
|
424
|
-
if (added.length > 0) {
|
|
425
|
-
const newRegisteredTriggers = added.map((trigger) => ({
|
|
426
|
-
trigger
|
|
427
|
-
}));
|
|
428
|
-
registered.push(...newRegisteredTriggers);
|
|
429
|
-
log4.info("added", () => ({
|
|
430
|
-
spaceKey: space.key,
|
|
431
|
-
triggers: added.map((trigger) => trigger.function)
|
|
432
|
-
}), {
|
|
433
|
-
F: __dxlog_file4,
|
|
434
|
-
L: 179,
|
|
435
|
-
S: this,
|
|
436
|
-
C: (f, a) => f(...a)
|
|
437
|
-
});
|
|
438
|
-
this.registered.emit({
|
|
439
|
-
space,
|
|
440
|
-
triggers: added
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
async _handleRemovedTriggers(space, current, registered) {
|
|
445
|
-
const removed = [];
|
|
446
|
-
for (let i = registered.length - 1; i >= 0; i--) {
|
|
447
|
-
const wasRemoved = current.filter((trigger) => trigger.enabled).find((trigger) => trigger.id === registered[i].trigger.id) == null;
|
|
448
|
-
if (wasRemoved) {
|
|
449
|
-
const unregistered = registered.splice(i, 1)[0];
|
|
450
|
-
await unregistered.activationCtx?.dispose();
|
|
451
|
-
removed.push(unregistered.trigger);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
if (removed.length > 0) {
|
|
455
|
-
log4.info("removed", () => ({
|
|
456
|
-
spaceKey: space.key,
|
|
457
|
-
triggers: removed.map((trigger) => trigger.function)
|
|
458
|
-
}), {
|
|
459
|
-
F: __dxlog_file4,
|
|
460
|
-
L: 205,
|
|
461
|
-
S: this,
|
|
462
|
-
C: (f, a) => f(...a)
|
|
463
|
-
});
|
|
464
|
-
this.removed.emit({
|
|
465
|
-
space,
|
|
466
|
-
triggers: removed
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
_getTriggers(space, predicate) {
|
|
471
|
-
const allSpaceTriggers = this._triggersBySpaceKey.get(space.key) ?? [];
|
|
472
|
-
return allSpaceTriggers.filter(predicate).map((trigger) => trigger.trigger);
|
|
473
|
-
}
|
|
474
|
-
};
|
|
475
|
-
|
|
476
|
-
export {
|
|
477
|
-
FunctionRegistry,
|
|
478
|
-
createSubscriptionTrigger,
|
|
479
|
-
createTimerTrigger,
|
|
480
|
-
TriggerRegistry
|
|
481
|
-
};
|
|
482
|
-
//# sourceMappingURL=chunk-HI7YZO2K.mjs.map
|