@dxos/functions 0.8.2-main.fbd8ed0 → 0.8.2-staging.42af850
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.map +3 -3
- package/dist/lib/browser/index.mjs +175 -32
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/bundler/index.cjs.map +3 -3
- package/dist/lib/node/index.cjs +167 -30
- 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.map +3 -3
- package/dist/lib/node-esm/index.mjs +175 -32
- 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/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 +7 -3
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/schema.d.ts.map +1 -1
- 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 +9 -8
- package/dist/types/src/trace.d.ts.map +1 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +20 -20
- package/src/bundler/bundler.ts +7 -1
- package/src/executor/executor.ts +47 -0
- package/src/executor/index.ts +5 -0
- package/src/handler.ts +8 -3
- package/src/index.ts +4 -0
- package/src/schema.ts +8 -9
- 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/trace.ts +4 -4
- package/src/types.ts +17 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/functions",
|
|
3
|
-
"version": "0.8.2-
|
|
3
|
+
"version": "0.8.2-staging.42af850",
|
|
4
4
|
"description": "Functions API and runtime.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"src"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@preact/signals-core": "^1.
|
|
45
|
+
"@preact/signals-core": "^1.9.0",
|
|
46
46
|
"cron": "^3.1.6",
|
|
47
47
|
"cron-schedule": "^5.0.4",
|
|
48
48
|
"effect": "3.14.21",
|
|
@@ -51,28 +51,28 @@
|
|
|
51
51
|
"get-port-please": "^3.1.1",
|
|
52
52
|
"iso-did": "^1.6.0",
|
|
53
53
|
"ws": "^8.14.2",
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/
|
|
59
|
-
"@dxos/echo-
|
|
60
|
-
"@dxos/echo-
|
|
61
|
-
"@dxos/
|
|
62
|
-
"@dxos/
|
|
63
|
-
"@dxos/
|
|
64
|
-
"@dxos/
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/
|
|
70
|
-
"@dxos/protocols": "0.8.2-
|
|
54
|
+
"@dxos/ai": "0.8.2-staging.42af850",
|
|
55
|
+
"@dxos/async": "0.8.2-staging.42af850",
|
|
56
|
+
"@dxos/client": "0.8.2-staging.42af850",
|
|
57
|
+
"@dxos/context": "0.8.2-staging.42af850",
|
|
58
|
+
"@dxos/echo-db": "0.8.2-staging.42af850",
|
|
59
|
+
"@dxos/echo-protocol": "0.8.2-staging.42af850",
|
|
60
|
+
"@dxos/echo-schema": "0.8.2-staging.42af850",
|
|
61
|
+
"@dxos/crypto": "0.8.2-staging.42af850",
|
|
62
|
+
"@dxos/invariant": "0.8.2-staging.42af850",
|
|
63
|
+
"@dxos/log": "0.8.2-staging.42af850",
|
|
64
|
+
"@dxos/edge-client": "0.8.2-staging.42af850",
|
|
65
|
+
"@dxos/live-object": "0.8.2-staging.42af850",
|
|
66
|
+
"@dxos/keys": "0.8.2-staging.42af850",
|
|
67
|
+
"@dxos/node-std": "0.8.2-staging.42af850",
|
|
68
|
+
"@dxos/schema": "0.8.2-staging.42af850",
|
|
69
|
+
"@dxos/util": "0.8.2-staging.42af850",
|
|
70
|
+
"@dxos/protocols": "0.8.2-staging.42af850"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@types/express": "^4.17.17",
|
|
74
74
|
"@types/ws": "^7.4.0",
|
|
75
|
-
"@dxos/agent": "0.8.2-
|
|
75
|
+
"@dxos/agent": "0.8.2-staging.42af850"
|
|
76
76
|
},
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
package/src/bundler/bundler.ts
CHANGED
|
@@ -171,7 +171,13 @@ export class Bundler {
|
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
analyzeSourceFileImports(code: string) {
|
|
174
|
+
analyzeSourceFileImports(code: string): {
|
|
175
|
+
defaultImportName: string;
|
|
176
|
+
namedImports: string[];
|
|
177
|
+
wildcardImportName: string;
|
|
178
|
+
moduleIdentifier: string;
|
|
179
|
+
quotes: string;
|
|
180
|
+
}[] {
|
|
175
181
|
// TODO(dmaretskyi): Support import aliases and wildcard imports.
|
|
176
182
|
const parsedImports = allMatches(IMPORT_REGEX, code);
|
|
177
183
|
return parsedImports.map((capture) => {
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Effect, Schema } from 'effect';
|
|
6
|
+
|
|
7
|
+
import type { SpaceId } from '@dxos/client/echo';
|
|
8
|
+
|
|
9
|
+
import type { FunctionContext, FunctionDefinition } from '../handler';
|
|
10
|
+
import type { ServiceContainer } from '../services';
|
|
11
|
+
|
|
12
|
+
export class FunctionExecutor {
|
|
13
|
+
constructor(private readonly _services: ServiceContainer) {}
|
|
14
|
+
|
|
15
|
+
// TODO(dmaretskyi): Invocation context: queue, space, etc...
|
|
16
|
+
async invoke<F extends FunctionDefinition<any, any>>(
|
|
17
|
+
fnDef: F,
|
|
18
|
+
input: F extends FunctionDefinition<infer I, infer _O> ? I : never,
|
|
19
|
+
): Promise<F extends FunctionDefinition<infer _I, infer O> ? O : never> {
|
|
20
|
+
// Assert input matches schema
|
|
21
|
+
const assertInput = fnDef.inputSchema.pipe(Schema.asserts);
|
|
22
|
+
(assertInput as any)(input);
|
|
23
|
+
|
|
24
|
+
const context: FunctionContext = {
|
|
25
|
+
getService: this._services.getService.bind(this._services),
|
|
26
|
+
getSpace: async (_spaceId: SpaceId) => {
|
|
27
|
+
throw new Error('Not available. Use the database service instead.');
|
|
28
|
+
},
|
|
29
|
+
space: undefined,
|
|
30
|
+
get ai(): never {
|
|
31
|
+
throw new Error('Not available. Use the ai service instead.');
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const result = await fnDef.handler({ context, data: input });
|
|
36
|
+
|
|
37
|
+
// Assert output matches schema
|
|
38
|
+
const assertOutput = fnDef.outputSchema?.pipe(Schema.asserts);
|
|
39
|
+
(assertOutput as any)(result);
|
|
40
|
+
|
|
41
|
+
if (Effect.isEffect(result)) {
|
|
42
|
+
return Effect.runPromise(result as any);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return result as any;
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/handler.ts
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Schema } from 'effect';
|
|
6
|
-
import { type Effect } from 'effect';
|
|
5
|
+
import { Schema, type Context, type Effect } from 'effect';
|
|
7
6
|
|
|
8
|
-
import { type AIServiceClient } from '@dxos/
|
|
7
|
+
import { type AIServiceClient } from '@dxos/ai';
|
|
9
8
|
// import { type Space } from '@dxos/client/echo';
|
|
10
9
|
import type { CoreDatabase, EchoDatabase } from '@dxos/echo-db';
|
|
11
10
|
import { type HasId } from '@dxos/echo-schema';
|
|
@@ -38,6 +37,12 @@ export type FunctionHandler<TData = {}, TOutput = any> = (params: {
|
|
|
38
37
|
* Function context.
|
|
39
38
|
*/
|
|
40
39
|
export interface FunctionContext {
|
|
40
|
+
/**
|
|
41
|
+
* Resolves a service available to the function.
|
|
42
|
+
* @throws if the service is not available.
|
|
43
|
+
*/
|
|
44
|
+
getService: <T extends Context.Tag<any, any>>(tag: T) => Context.Tag.Service<T>;
|
|
45
|
+
|
|
41
46
|
getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;
|
|
42
47
|
|
|
43
48
|
/**
|
package/src/index.ts
CHANGED
package/src/schema.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
|
-
import { EchoObject, JsonSchemaType,
|
|
7
|
+
import { EchoObject, JsonSchemaType, LabelAnnotation, Ref, TypedObject } from '@dxos/echo-schema';
|
|
8
8
|
import { DataType } from '@dxos/schema';
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -17,14 +17,13 @@ export const ScriptType = Schema.Struct({
|
|
|
17
17
|
// Whether source has changed since last deploy.
|
|
18
18
|
changed: Schema.optional(Schema.Boolean),
|
|
19
19
|
source: Ref(DataType.Text),
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
20
|
+
}).pipe(
|
|
21
|
+
EchoObject({
|
|
22
|
+
typename: 'dxos.org/type/Script',
|
|
23
|
+
version: '0.1.0',
|
|
24
|
+
}),
|
|
25
|
+
LabelAnnotation.set(['name']),
|
|
26
|
+
);
|
|
28
27
|
|
|
29
28
|
export type ScriptType = Schema.Schema.Type<typeof ScriptType>;
|
|
30
29
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Context } from 'effect';
|
|
6
|
+
|
|
7
|
+
import type { AIServiceClient } from '@dxos/ai';
|
|
8
|
+
|
|
9
|
+
// TODO(burdon): Move to @dxos/ai.
|
|
10
|
+
export class AiService extends Context.Tag('AiService')<
|
|
11
|
+
AiService,
|
|
12
|
+
{
|
|
13
|
+
readonly client: AIServiceClient;
|
|
14
|
+
}
|
|
15
|
+
>() {}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Context } from 'effect';
|
|
6
|
+
|
|
7
|
+
type CredentialQuery = {
|
|
8
|
+
service?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// TODO(dmaretskyi): Unify with other apis.
|
|
12
|
+
// packages/sdk/schema/src/common/access-token.ts
|
|
13
|
+
type ServiceCredential = {
|
|
14
|
+
service: string;
|
|
15
|
+
|
|
16
|
+
// TODO(dmaretskyi): Build out.
|
|
17
|
+
apiKey?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export class CredentialsService extends Context.Tag('CredentialsService')<
|
|
21
|
+
CredentialsService,
|
|
22
|
+
{
|
|
23
|
+
/**
|
|
24
|
+
* Query all.
|
|
25
|
+
*/
|
|
26
|
+
queryCredentials: (query: CredentialQuery) => Promise<ServiceCredential[]>;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get a single credential.
|
|
30
|
+
* @throws {Error} If no credential is found.
|
|
31
|
+
*/
|
|
32
|
+
getCredential: (query: CredentialQuery) => Promise<ServiceCredential>;
|
|
33
|
+
}
|
|
34
|
+
>() {}
|
|
35
|
+
|
|
36
|
+
export class ConfiguredCredentialsService implements Context.Tag.Service<CredentialsService> {
|
|
37
|
+
constructor(private readonly credentials: ServiceCredential[] = []) {}
|
|
38
|
+
|
|
39
|
+
addCredentials(credentials: ServiceCredential[]): ConfiguredCredentialsService {
|
|
40
|
+
this.credentials.push(...credentials);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async queryCredentials(query: CredentialQuery): Promise<ServiceCredential[]> {
|
|
45
|
+
return this.credentials.filter((credential) => credential.service === query.service);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async getCredential(query: CredentialQuery): Promise<ServiceCredential> {
|
|
49
|
+
const credential = this.credentials.find((credential) => credential.service === query.service);
|
|
50
|
+
if (!credential) {
|
|
51
|
+
throw new Error(`Credential not found for service: ${query.service}`);
|
|
52
|
+
}
|
|
53
|
+
return credential;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Context } from 'effect';
|
|
6
|
+
|
|
7
|
+
import type { EchoDatabase } from '@dxos/echo-db';
|
|
8
|
+
|
|
9
|
+
export class DatabaseService extends Context.Tag('DatabaseService')<
|
|
10
|
+
DatabaseService,
|
|
11
|
+
{
|
|
12
|
+
readonly db: EchoDatabase;
|
|
13
|
+
}
|
|
14
|
+
>() {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Context } from 'effect';
|
|
6
|
+
|
|
7
|
+
import type { Queue, QueueFactory } from '@dxos/echo-db';
|
|
8
|
+
|
|
9
|
+
export class QueuesService extends Context.Tag('QueuesService')<
|
|
10
|
+
QueuesService,
|
|
11
|
+
{
|
|
12
|
+
readonly contextQueue: Queue | undefined;
|
|
13
|
+
|
|
14
|
+
readonly queues: QueueFactory;
|
|
15
|
+
}
|
|
16
|
+
>() {}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Context } from 'effect';
|
|
6
|
+
|
|
7
|
+
import { AiService } from './ai';
|
|
8
|
+
import { CredentialsService } from './credentials';
|
|
9
|
+
import { DatabaseService } from './database';
|
|
10
|
+
import { QueuesService } from './queues';
|
|
11
|
+
import { TracingService } from './tracing';
|
|
12
|
+
|
|
13
|
+
export interface Services {
|
|
14
|
+
database: Context.Tag.Service<DatabaseService>;
|
|
15
|
+
ai: Context.Tag.Service<AiService>;
|
|
16
|
+
queues: Context.Tag.Service<QueuesService>;
|
|
17
|
+
credentials: Context.Tag.Service<CredentialsService>;
|
|
18
|
+
tracing: Context.Tag.Service<TracingService>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const SERVICE_MAPPING: Record<string, keyof Services> = {
|
|
22
|
+
[DatabaseService.key]: 'database',
|
|
23
|
+
[AiService.key]: 'ai',
|
|
24
|
+
[QueuesService.key]: 'queues',
|
|
25
|
+
[CredentialsService.key]: 'credentials',
|
|
26
|
+
[TracingService.key]: 'tracing',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const DEFAULT_SERVICES: Partial<Services> = {
|
|
30
|
+
tracing: TracingService.noop,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export class ServiceContainer {
|
|
34
|
+
private _services: Partial<Services> = { ...DEFAULT_SERVICES };
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Set services.
|
|
38
|
+
* @param services - Services to set.
|
|
39
|
+
* @returns The container instance.
|
|
40
|
+
*/
|
|
41
|
+
setServices(services: Partial<Services>): this {
|
|
42
|
+
this._services = { ...this._services, ...services };
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
getService<T extends Context.Tag<any, any>>(tag: T): Context.Tag.Service<T> {
|
|
47
|
+
const serviceKey = SERVICE_MAPPING[tag.key];
|
|
48
|
+
const service = serviceKey != null ? this._services[serviceKey] : undefined;
|
|
49
|
+
if (!service) {
|
|
50
|
+
throw new Error(`Service not available: ${tag.key}`);
|
|
51
|
+
}
|
|
52
|
+
return service as Context.Tag.Service<T>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
clone(): ServiceContainer {
|
|
56
|
+
return new ServiceContainer().setServices({ ...this._services });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Context } from 'effect';
|
|
6
|
+
|
|
7
|
+
import type { AnyEchoObject } from '@dxos/echo-schema';
|
|
8
|
+
|
|
9
|
+
export class TracingService extends Context.Tag('TracingService')<
|
|
10
|
+
TracingService,
|
|
11
|
+
{
|
|
12
|
+
/**
|
|
13
|
+
* Write an event to the tracing queue.
|
|
14
|
+
* @param event - The event to write. Must be an a typed object.
|
|
15
|
+
*/
|
|
16
|
+
write(event: AnyEchoObject): void;
|
|
17
|
+
}
|
|
18
|
+
>() {
|
|
19
|
+
static noop: Context.Tag.Service<TracingService> = { write: () => {} };
|
|
20
|
+
|
|
21
|
+
static console: Context.Tag.Service<TracingService> = {
|
|
22
|
+
write: (event) => {
|
|
23
|
+
// eslint-disable-next-line no-console
|
|
24
|
+
console.log(event);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
package/src/trace.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Schema } from 'effect';
|
|
6
6
|
|
|
7
|
+
import { Queue } from '@dxos/echo-db';
|
|
7
8
|
import { EchoObject, Expando, ObjectId, Ref } from '@dxos/echo-schema';
|
|
8
9
|
import { log } from '@dxos/log';
|
|
9
10
|
|
|
@@ -49,10 +50,9 @@ export const InvocationTraceStartEvent = Schema.Struct({
|
|
|
49
50
|
// TODO(burdon): Input schema?
|
|
50
51
|
input: Schema.Object,
|
|
51
52
|
/**
|
|
52
|
-
* Queue
|
|
53
|
+
* Queue for function/workflow invocation events.
|
|
53
54
|
*/
|
|
54
|
-
|
|
55
|
-
invocationTraceQueue: Ref(Expando),
|
|
55
|
+
invocationTraceQueue: Ref(Queue),
|
|
56
56
|
/**
|
|
57
57
|
* DXN of the invoked function/workflow.
|
|
58
58
|
*/
|
|
@@ -121,7 +121,7 @@ export type InvocationSpan = {
|
|
|
121
121
|
outcome: InvocationOutcome;
|
|
122
122
|
input: object;
|
|
123
123
|
durationMs: number;
|
|
124
|
-
invocationTraceQueue: Ref<
|
|
124
|
+
invocationTraceQueue: Ref<Queue>;
|
|
125
125
|
invocationTarget: Ref<Expando>;
|
|
126
126
|
trigger?: Ref<FunctionTriggerType>;
|
|
127
127
|
exception?: TraceEventException;
|
package/src/types.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
import { Schema, SchemaAST } from 'effect';
|
|
6
6
|
|
|
7
|
-
import { Expando, OptionsAnnotationId, TypedObject,
|
|
7
|
+
import { Expando, OptionsAnnotationId, TypedObject, Ref, RawObject } from '@dxos/echo-schema';
|
|
8
|
+
import { DXN } from '@dxos/keys';
|
|
8
9
|
|
|
9
10
|
import { FunctionType } from './schema';
|
|
10
11
|
|
|
@@ -21,7 +22,7 @@ export enum TriggerKind {
|
|
|
21
22
|
Queue = 'queue',
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
const kindLiteralAnnotations = {
|
|
25
|
+
const kindLiteralAnnotations = { title: 'Kind' };
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Cron timer.
|
|
@@ -29,7 +30,7 @@ const kindLiteralAnnotations = { [SchemaAST.TitleAnnotationId]: 'Kind' };
|
|
|
29
30
|
const TimerTriggerSchema = Schema.Struct({
|
|
30
31
|
kind: Schema.Literal(TriggerKind.Timer).annotations(kindLiteralAnnotations),
|
|
31
32
|
cron: Schema.String.annotations({
|
|
32
|
-
|
|
33
|
+
title: 'Cron',
|
|
33
34
|
[SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
|
|
34
35
|
}),
|
|
35
36
|
}).pipe(Schema.mutable);
|
|
@@ -42,7 +43,7 @@ export type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;
|
|
|
42
43
|
|
|
43
44
|
const QueueTriggerSchema = Schema.Struct({
|
|
44
45
|
kind: Schema.Literal(TriggerKind.Queue).annotations(kindLiteralAnnotations),
|
|
45
|
-
queue: DXN,
|
|
46
|
+
queue: DXN.Schema,
|
|
46
47
|
}).pipe(Schema.mutable);
|
|
47
48
|
export type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;
|
|
48
49
|
|
|
@@ -53,13 +54,13 @@ const WebhookTriggerSchema = Schema.Struct({
|
|
|
53
54
|
kind: Schema.Literal(TriggerKind.Webhook).annotations(kindLiteralAnnotations),
|
|
54
55
|
method: Schema.optional(
|
|
55
56
|
Schema.String.annotations({
|
|
56
|
-
|
|
57
|
+
title: 'Method',
|
|
57
58
|
[OptionsAnnotationId]: ['GET', 'POST'],
|
|
58
59
|
}),
|
|
59
60
|
),
|
|
60
61
|
port: Schema.optional(
|
|
61
62
|
Schema.Number.annotations({
|
|
62
|
-
|
|
63
|
+
title: 'Port',
|
|
63
64
|
}),
|
|
64
65
|
),
|
|
65
66
|
}).pipe(Schema.mutable);
|
|
@@ -67,9 +68,9 @@ export type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;
|
|
|
67
68
|
|
|
68
69
|
// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).
|
|
69
70
|
const QuerySchema = Schema.Struct({
|
|
70
|
-
type: Schema.optional(Schema.String.annotations({
|
|
71
|
+
type: Schema.optional(Schema.String.annotations({ title: 'Type' })),
|
|
71
72
|
props: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
|
|
72
|
-
}).annotations({
|
|
73
|
+
}).annotations({ title: 'Query' });
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
76
|
* Subscription.
|
|
@@ -81,10 +82,10 @@ const SubscriptionTriggerSchema = Schema.Struct({
|
|
|
81
82
|
options: Schema.optional(
|
|
82
83
|
Schema.Struct({
|
|
83
84
|
// Watch changes to object (not just creation).
|
|
84
|
-
deep: Schema.optional(Schema.Boolean.annotations({
|
|
85
|
+
deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
|
|
85
86
|
// Debounce changes (delay in ms).
|
|
86
|
-
delay: Schema.optional(Schema.Number.annotations({
|
|
87
|
-
}).annotations({
|
|
87
|
+
delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
|
|
88
|
+
}).annotations({ title: 'Options' }),
|
|
88
89
|
),
|
|
89
90
|
}).pipe(Schema.mutable);
|
|
90
91
|
export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
|
|
@@ -99,7 +100,7 @@ export const TriggerSchema = Schema.Union(
|
|
|
99
100
|
EmailTriggerSchema,
|
|
100
101
|
QueueTriggerSchema,
|
|
101
102
|
).annotations({
|
|
102
|
-
|
|
103
|
+
title: 'Trigger',
|
|
103
104
|
});
|
|
104
105
|
export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
|
|
105
106
|
|
|
@@ -134,7 +135,7 @@ export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutpu
|
|
|
134
135
|
|
|
135
136
|
export const QueueTriggerOutput = Schema.mutable(
|
|
136
137
|
Schema.Struct({
|
|
137
|
-
queue: DXN,
|
|
138
|
+
queue: DXN.Schema,
|
|
138
139
|
item: Schema.Any,
|
|
139
140
|
cursor: Schema.String,
|
|
140
141
|
}),
|
|
@@ -159,16 +160,16 @@ export const FunctionTriggerSchema = Schema.Struct({
|
|
|
159
160
|
* Function or workflow to invoke.
|
|
160
161
|
*/
|
|
161
162
|
// TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
|
|
162
|
-
function: Schema.optional(Ref(Expando).annotations({
|
|
163
|
+
function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
|
|
163
164
|
|
|
164
165
|
/**
|
|
165
166
|
* Only used for workflowSchema.
|
|
166
167
|
* Specifies the input node in the circuit.
|
|
167
168
|
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
168
169
|
*/
|
|
169
|
-
inputNodeId: Schema.optional(Schema.String.annotations({
|
|
170
|
+
inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
|
|
170
171
|
|
|
171
|
-
enabled: Schema.optional(Schema.Boolean.annotations({
|
|
172
|
+
enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
|
|
172
173
|
|
|
173
174
|
spec: Schema.optional(TriggerSchema),
|
|
174
175
|
|