@dxos/functions 0.8.4-main.fffef41 → 0.9.0
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/LICENSE +102 -5
- package/README.md +5 -7
- package/dist/lib/neutral/index.mjs +584 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
- package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
- package/dist/types/src/protocol/functions-ai-http-client.test.d.ts +2 -0
- package/dist/types/src/protocol/functions-ai-http-client.test.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +14 -2
- package/dist/types/src/protocol/protocol.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts +5 -84
- package/dist/types/src/sdk.d.ts.map +1 -1
- package/dist/types/src/services/credentials.d.ts +17 -38
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +10 -3
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +1 -6
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +1 -50
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +0 -4
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/url.d.ts +6 -5
- package/dist/types/src/types/url.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +25 -18
- package/src/index.ts +0 -2
- package/src/protocol/functions-ai-http-client.test.ts +105 -0
- package/src/protocol/functions-ai-http-client.ts +141 -0
- package/src/protocol/protocol.test.ts +10 -10
- package/src/protocol/protocol.ts +355 -86
- package/src/sdk.ts +12 -209
- package/src/services/credentials.ts +80 -108
- package/src/services/function-invocation-service.ts +20 -7
- package/src/services/index.ts +1 -7
- package/src/services/tracing.ts +0 -100
- package/src/types/index.ts +0 -4
- package/src/types/url.ts +6 -5
- package/dist/lib/browser/index.mjs +0 -927
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -928
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/types/src/errors.d.ts +0 -129
- package/dist/types/src/errors.d.ts.map +0 -1
- package/dist/types/src/example/fib.d.ts +0 -7
- package/dist/types/src/example/fib.d.ts.map +0 -1
- package/dist/types/src/example/forex-effect.d.ts +0 -3
- package/dist/types/src/example/forex-effect.d.ts.map +0 -1
- package/dist/types/src/example/index.d.ts +0 -12
- package/dist/types/src/example/index.d.ts.map +0 -1
- package/dist/types/src/example/reply.d.ts +0 -3
- package/dist/types/src/example/reply.d.ts.map +0 -1
- package/dist/types/src/example/sleep.d.ts +0 -5
- package/dist/types/src/example/sleep.d.ts.map +0 -1
- package/dist/types/src/services/event-logger.d.ts +0 -87
- package/dist/types/src/services/event-logger.d.ts.map +0 -1
- package/dist/types/src/services/queues.d.ts +0 -47
- package/dist/types/src/services/queues.d.ts.map +0 -1
- package/dist/types/src/types/Function.d.ts +0 -58
- package/dist/types/src/types/Function.d.ts.map +0 -1
- package/dist/types/src/types/Script.d.ts +0 -28
- package/dist/types/src/types/Script.d.ts.map +0 -1
- package/dist/types/src/types/Trigger.d.ts +0 -139
- package/dist/types/src/types/Trigger.d.ts.map +0 -1
- package/dist/types/src/types/TriggerEvent.d.ts +0 -44
- package/dist/types/src/types/TriggerEvent.d.ts.map +0 -1
- package/src/errors.ts +0 -21
- package/src/example/fib.ts +0 -32
- package/src/example/forex-effect.ts +0 -40
- package/src/example/index.ts +0 -13
- package/src/example/reply.ts +0 -21
- package/src/example/sleep.ts +0 -24
- package/src/services/event-logger.ts +0 -127
- package/src/services/queues.ts +0 -84
- package/src/types/Function.ts +0 -62
- package/src/types/Script.ts +0 -33
- package/src/types/Trigger.ts +0 -139
- package/src/types/TriggerEvent.ts +0 -62
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
import { Obj, Type } from '@dxos/echo';
|
|
3
|
-
import { Ref } from '@dxos/echo/internal';
|
|
4
|
-
/**
|
|
5
|
-
* Function deployment.
|
|
6
|
-
*/
|
|
7
|
-
export declare const Function: Type.obj<Schema.Struct<{
|
|
8
|
-
/**
|
|
9
|
-
* Global registry ID.
|
|
10
|
-
* NOTE: The `key` property refers to the original registry entry.
|
|
11
|
-
*/
|
|
12
|
-
key: Schema.optional<typeof Schema.String>;
|
|
13
|
-
name: typeof Schema.NonEmptyString;
|
|
14
|
-
version: typeof Schema.String;
|
|
15
|
-
description: Schema.optional<typeof Schema.String>;
|
|
16
|
-
/**
|
|
17
|
-
* ISO date string of the last deployment.
|
|
18
|
-
*/
|
|
19
|
-
updated: Schema.optional<typeof Schema.String>;
|
|
20
|
-
source: Schema.optional<import("@dxos/echo/internal").Ref$<Type.OfKind<import("@dxos/echo/internal").EntityKind.Object> & {
|
|
21
|
-
description?: string | undefined;
|
|
22
|
-
source: Ref<Type.OfKind<import("@dxos/echo/internal").EntityKind.Object> & {
|
|
23
|
-
content: string;
|
|
24
|
-
}>;
|
|
25
|
-
name?: string | undefined;
|
|
26
|
-
changed?: boolean | undefined;
|
|
27
|
-
}>>;
|
|
28
|
-
inputSchema: Schema.optional<Schema.Schema<Type.JsonSchema, Type.JsonSchema, never>>;
|
|
29
|
-
outputSchema: Schema.optional<Schema.Schema<Type.JsonSchema, Type.JsonSchema, never>>;
|
|
30
|
-
/**
|
|
31
|
-
* List of required services.
|
|
32
|
-
* Match the Context.Tag keys of the FunctionServices variants.
|
|
33
|
-
*/
|
|
34
|
-
services: Schema.optional<Schema.Array$<typeof Schema.String>>;
|
|
35
|
-
binding: Schema.optional<typeof Schema.String>;
|
|
36
|
-
}>>;
|
|
37
|
-
export interface Function extends Schema.Schema.Type<typeof Function> {
|
|
38
|
-
}
|
|
39
|
-
export declare const make: (props: Obj.MakeProps<typeof Function>) => import("@dxos/live-object").Live<Type.OfKind<import("@dxos/echo/internal").EntityKind.Object> & {
|
|
40
|
-
description?: string | undefined;
|
|
41
|
-
version: string;
|
|
42
|
-
source?: Ref<Type.OfKind<import("@dxos/echo/internal").EntityKind.Object> & {
|
|
43
|
-
description?: string | undefined;
|
|
44
|
-
source: Ref<Type.OfKind<import("@dxos/echo/internal").EntityKind.Object> & {
|
|
45
|
-
content: string;
|
|
46
|
-
}>;
|
|
47
|
-
name?: string | undefined;
|
|
48
|
-
changed?: boolean | undefined;
|
|
49
|
-
}> | undefined;
|
|
50
|
-
name: string;
|
|
51
|
-
key?: string | undefined;
|
|
52
|
-
updated?: string | undefined;
|
|
53
|
-
inputSchema?: Type.JsonSchema | undefined;
|
|
54
|
-
outputSchema?: Type.JsonSchema | undefined;
|
|
55
|
-
services?: readonly string[] | undefined;
|
|
56
|
-
binding?: string | undefined;
|
|
57
|
-
}>;
|
|
58
|
-
//# sourceMappingURL=Function.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Function.d.ts","sourceRoot":"","sources":["../../../../src/types/Function.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAmC,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAI3E;;GAEG;AACH,eAAO,MAAM,QAAQ;IACnB;;;OAGG;;;;;IAcH;;OAEG;;;;;;;;;;;;IAUH;;;OAGG;;;GAWJ,CAAC;AACF,MAAM,WAAW,QAAS,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC;CAAG;AAExE,eAAO,MAAM,IAAI,GAAI,OAAO,GAAG,CAAC,SAAS,CAAC,OAAO,QAAQ,CAAC;;;;;;;;;;;;;;;;;;EAA8B,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
import { Obj, Type } from '@dxos/echo';
|
|
3
|
-
/**
|
|
4
|
-
* Source script.
|
|
5
|
-
*/
|
|
6
|
-
export declare const Script: Type.obj<Schema.Struct<{
|
|
7
|
-
name: Schema.optional<typeof Schema.String>;
|
|
8
|
-
description: Schema.optional<typeof Schema.String>;
|
|
9
|
-
changed: Schema.optional<typeof Schema.Boolean>;
|
|
10
|
-
source: Type.ref<Type.obj<Schema.Struct<{
|
|
11
|
-
content: typeof Schema.String;
|
|
12
|
-
}>>>;
|
|
13
|
-
}>>;
|
|
14
|
-
export interface Script extends Schema.Schema.Type<typeof Script> {
|
|
15
|
-
}
|
|
16
|
-
type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & {
|
|
17
|
-
source?: string;
|
|
18
|
-
};
|
|
19
|
-
export declare const make: ({ source, ...props }?: Props) => import("@dxos/live-object").Live<Type.OfKind<import("@dxos/echo/internal").EntityKind.Object> & {
|
|
20
|
-
description?: string | undefined;
|
|
21
|
-
source: import("@dxos/echo/internal").Ref<Type.OfKind<import("@dxos/echo/internal").EntityKind.Object> & {
|
|
22
|
-
content: string;
|
|
23
|
-
}>;
|
|
24
|
-
name?: string | undefined;
|
|
25
|
-
changed?: boolean | undefined;
|
|
26
|
-
}>;
|
|
27
|
-
export {};
|
|
28
|
-
//# sourceMappingURL=Script.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Script.d.ts","sourceRoot":"","sources":["../../../../src/types/Script.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,GAAG,EAAO,IAAI,EAAE,MAAM,YAAY,CAAC;AAI5C;;GAEG;AACH,eAAO,MAAM,MAAM;;;;;;;GAalB,CAAC;AACF,MAAM,WAAW,MAAO,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,MAAM,CAAC;CAAG;AAEpE,KAAK,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,OAAO,MAAM,CAAC,EAAE,QAAQ,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhF,eAAO,MAAM,IAAI,GAAI,uBAA2B,KAAU;;;;;;;EACW,CAAC"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
import { Obj, QueryAST, Type } from '@dxos/echo';
|
|
3
|
-
import { Expando, Ref } from '@dxos/echo/internal';
|
|
4
|
-
/**
|
|
5
|
-
* Type discriminator for TriggerType.
|
|
6
|
-
* Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
|
|
7
|
-
* https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
|
|
8
|
-
*/
|
|
9
|
-
export declare const Kinds: readonly ["email", "queue", "subscription", "timer", "webhook"];
|
|
10
|
-
export type Kind = (typeof Kinds)[number];
|
|
11
|
-
export declare const EmailSpec: Schema.mutable<Schema.Struct<{
|
|
12
|
-
kind: Schema.Literal<["email"]>;
|
|
13
|
-
}>>;
|
|
14
|
-
export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
|
|
15
|
-
export declare const QueueSpec: Schema.mutable<Schema.Struct<{
|
|
16
|
-
kind: Schema.Literal<["queue"]>;
|
|
17
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
18
|
-
}>>;
|
|
19
|
-
export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
|
|
20
|
-
/**
|
|
21
|
-
* Subscription.
|
|
22
|
-
*/
|
|
23
|
-
export declare const SubscriptionSpec: Schema.mutable<Schema.Struct<{
|
|
24
|
-
kind: Schema.Literal<["subscription"]>;
|
|
25
|
-
query: Schema.mutable<Schema.Struct<{
|
|
26
|
-
raw: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
27
|
-
ast: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
|
|
28
|
-
}>>;
|
|
29
|
-
options: Schema.optional<Schema.Struct<{
|
|
30
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
31
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
32
|
-
}>>;
|
|
33
|
-
}>>;
|
|
34
|
-
export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
|
|
35
|
-
/**
|
|
36
|
-
* Cron timer.
|
|
37
|
-
*/
|
|
38
|
-
export declare const TimerSpec: Schema.mutable<Schema.Struct<{
|
|
39
|
-
kind: Schema.Literal<["timer"]>;
|
|
40
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
41
|
-
}>>;
|
|
42
|
-
export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
|
|
43
|
-
/**
|
|
44
|
-
* Webhook.
|
|
45
|
-
*/
|
|
46
|
-
export declare const WebhookSpec: Schema.mutable<Schema.Struct<{
|
|
47
|
-
kind: Schema.Literal<["webhook"]>;
|
|
48
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
49
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
50
|
-
}>>;
|
|
51
|
-
export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
|
|
52
|
-
/**
|
|
53
|
-
* Trigger schema.
|
|
54
|
-
*/
|
|
55
|
-
export declare const Spec: Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
56
|
-
kind: Schema.Literal<["email"]>;
|
|
57
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
58
|
-
kind: Schema.Literal<["queue"]>;
|
|
59
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
60
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
61
|
-
kind: Schema.Literal<["subscription"]>;
|
|
62
|
-
query: Schema.mutable<Schema.Struct<{
|
|
63
|
-
raw: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
64
|
-
ast: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
|
|
65
|
-
}>>;
|
|
66
|
-
options: Schema.optional<Schema.Struct<{
|
|
67
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
68
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
69
|
-
}>>;
|
|
70
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
71
|
-
kind: Schema.Literal<["timer"]>;
|
|
72
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
73
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
74
|
-
kind: Schema.Literal<["webhook"]>;
|
|
75
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
76
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
77
|
-
}>>]>;
|
|
78
|
-
export type Spec = Schema.Schema.Type<typeof Spec>;
|
|
79
|
-
/**
|
|
80
|
-
* Function trigger.
|
|
81
|
-
* Function is invoked with the `payload` passed as input data.
|
|
82
|
-
* The event that triggers the function is available in the function context.
|
|
83
|
-
*/
|
|
84
|
-
declare const Trigger_: Type.obj<Schema.Struct<{
|
|
85
|
-
/**
|
|
86
|
-
* Function or workflow to invoke.
|
|
87
|
-
*/
|
|
88
|
-
function: Schema.optional<Schema.SchemaClass<Ref<Expando>, import("@dxos/echo-protocol").EncodedReference, never>>;
|
|
89
|
-
/**
|
|
90
|
-
* Only used for workflowSchema.
|
|
91
|
-
* Specifies the input node in the circuit.
|
|
92
|
-
* @deprecated Remove and enforce a single input node in all compute graphSchema.
|
|
93
|
-
*/
|
|
94
|
-
inputNodeId: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
95
|
-
enabled: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
96
|
-
spec: Schema.optional<Schema.Union<[Schema.mutable<Schema.Struct<{
|
|
97
|
-
kind: Schema.Literal<["email"]>;
|
|
98
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
99
|
-
kind: Schema.Literal<["queue"]>;
|
|
100
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
101
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
102
|
-
kind: Schema.Literal<["subscription"]>;
|
|
103
|
-
query: Schema.mutable<Schema.Struct<{
|
|
104
|
-
raw: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
105
|
-
ast: Schema.Schema<QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, QueryAST.QuerySelectClause | QueryAST.QueryFilterClause | QueryAST.QueryReferenceTraversalClause | QueryAST.QueryIncomingReferencesClause | QueryAST.QueryRelationClause | QueryAST.QueryRelationTraversalClause | QueryAST.QueryUnionClause | QueryAST.QuerySetDifferenceClause | QueryAST.QueryOrderClause | QueryAST.QueryOptionsClause, never>;
|
|
106
|
-
}>>;
|
|
107
|
-
options: Schema.optional<Schema.Struct<{
|
|
108
|
-
deep: Schema.optional<Schema.SchemaClass<boolean, boolean, never>>;
|
|
109
|
-
delay: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
110
|
-
}>>;
|
|
111
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
112
|
-
kind: Schema.Literal<["timer"]>;
|
|
113
|
-
cron: Schema.SchemaClass<string, string, never>;
|
|
114
|
-
}>>, Schema.mutable<Schema.Struct<{
|
|
115
|
-
kind: Schema.Literal<["webhook"]>;
|
|
116
|
-
method: Schema.optional<Schema.SchemaClass<string, string, never>>;
|
|
117
|
-
port: Schema.optional<Schema.SchemaClass<number, number, never>>;
|
|
118
|
-
}>>]>>;
|
|
119
|
-
/**
|
|
120
|
-
* Passed as the input data to the function.
|
|
121
|
-
* Must match the function's input schema.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* {
|
|
125
|
-
* item: '{{$.trigger.event}}',
|
|
126
|
-
* instructions: 'Summarize and perform entity-extraction'
|
|
127
|
-
* mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
|
|
128
|
-
* }
|
|
129
|
-
*/
|
|
130
|
-
input: Schema.optional<Schema.mutable<Schema.Record$<typeof Schema.String, typeof Schema.Any>>>;
|
|
131
|
-
}>>;
|
|
132
|
-
export interface Trigger extends Schema.Schema.Type<typeof Trigger_> {
|
|
133
|
-
}
|
|
134
|
-
export interface TriggerEncoded extends Schema.Schema.Encoded<typeof Trigger_> {
|
|
135
|
-
}
|
|
136
|
-
export declare const Trigger: Schema.Schema<Trigger, TriggerEncoded>;
|
|
137
|
-
export declare const make: (props: Obj.MakeProps<typeof Trigger>) => import("@dxos/live-object").Live<Trigger>;
|
|
138
|
-
export {};
|
|
139
|
-
//# sourceMappingURL=Trigger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Trigger.d.ts","sourceRoot":"","sources":["../../../../src/types/Trigger.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,OAAO,EAAuB,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAGxE;;;;GAIG;AACH,eAAO,MAAM,KAAK,iEAAkE,CAAC;AACrF,MAAM,MAAM,IAAI,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC;AAI1C,eAAO,MAAM,SAAS;;GAEC,CAAC;AACxB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC,CAAC;AAE7D,eAAO,MAAM,SAAS;;;GAKC,CAAC;AACxB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;GAcN,CAAC;AACxB,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE3E;;GAEG;AACH,eAAO,MAAM,SAAS;;;GAMC,CAAC;AACxB,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,SAAS,CAAC,CAAC;AAE7D;;GAEG;AACH,eAAO,MAAM,WAAW;;;;GAaD,CAAC;AACxB,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,CAAC;AAEjE;;GAEG;AACH,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;KAEf,CAAC;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnD;;;;GAIG;AACH,QAAA,MAAM,QAAQ;IACZ;;OAEG;;IAIH;;;;OAIG;;;;;;;;;;;;;;;;;;;;;;;;;;IAOH;;;;;;;;;;OAUG;;GAOJ,CAAC;AACF,MAAM,WAAW,OAAQ,SAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,QAAQ,CAAC;CAAG;AACvE,MAAM,WAAW,cAAe,SAAQ,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,QAAQ,CAAC;CAAG;AACjF,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAY,CAAC;AAExE,eAAO,MAAM,IAAI,GAAI,OAAO,GAAG,CAAC,SAAS,CAAC,OAAO,OAAO,CAAC,8CAA6B,CAAC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import * as Schema from 'effect/Schema';
|
|
2
|
-
import { Type } from '@dxos/echo';
|
|
3
|
-
export type TriggerEvent = EmailEvent | QueueEvent | SubscriptionEvent | TimerEvent | WebhookEvent;
|
|
4
|
-
export declare const EmailEvent: Schema.mutable<Schema.Struct<{
|
|
5
|
-
from: typeof Schema.String;
|
|
6
|
-
to: typeof Schema.String;
|
|
7
|
-
subject: typeof Schema.String;
|
|
8
|
-
created: typeof Schema.String;
|
|
9
|
-
body: typeof Schema.String;
|
|
10
|
-
}>>;
|
|
11
|
-
export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
|
|
12
|
-
export declare const QueueEvent: Schema.mutable<Schema.Struct<{
|
|
13
|
-
queue: Schema.refine<string, typeof Schema.NonEmptyString>;
|
|
14
|
-
item: typeof Schema.Any;
|
|
15
|
-
cursor: typeof Schema.String;
|
|
16
|
-
}>>;
|
|
17
|
-
export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
|
|
18
|
-
export declare const SubscriptionEvent: Schema.mutable<Schema.Struct<{
|
|
19
|
-
/**
|
|
20
|
-
* Type of the mutation.
|
|
21
|
-
*/
|
|
22
|
-
type: typeof Schema.String;
|
|
23
|
-
/**
|
|
24
|
-
* Reference to the object that was changed or created.
|
|
25
|
-
*/
|
|
26
|
-
subject: Type.ref<Type.obj<Schema.Struct<{}>>>;
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated
|
|
29
|
-
*/
|
|
30
|
-
changedObjectId: Schema.optional<typeof Schema.String>;
|
|
31
|
-
}>>;
|
|
32
|
-
export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
|
|
33
|
-
export declare const TimerEvent: Schema.mutable<Schema.Struct<{
|
|
34
|
-
tick: typeof Schema.Number;
|
|
35
|
-
}>>;
|
|
36
|
-
export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
|
|
37
|
-
export declare const WebhookEvent: Schema.mutable<Schema.Struct<{
|
|
38
|
-
url: typeof Schema.String;
|
|
39
|
-
method: Schema.Literal<["GET", "POST"]>;
|
|
40
|
-
headers: Schema.Record$<typeof Schema.String, typeof Schema.String>;
|
|
41
|
-
bodyText: typeof Schema.String;
|
|
42
|
-
}>>;
|
|
43
|
-
export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
|
|
44
|
-
//# sourceMappingURL=TriggerEvent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TriggerEvent.d.ts","sourceRoot":"","sources":["../../../../src/types/TriggerEvent.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,MAAM,eAAe,CAAC;AAExC,OAAO,EAAY,IAAI,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,UAAU,GAAG,iBAAiB,GAAG,UAAU,GAAG,YAAY,CAAC;AAGnG,eAAO,MAAM,UAAU;;;;;;GAQtB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,eAAO,MAAM,UAAU;;;;GAMtB,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,eAAO,MAAM,iBAAiB;IAC5B;;OAEG;;IAIH;;OAEG;;IAGH;;OAEG;;GAEkB,CAAC;AACxB,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE7E,eAAO,MAAM,UAAU;;GAAyD,CAAC;AACjF,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC;AAE/D,eAAO,MAAM,YAAY;;;;;GAOxB,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
package/src/errors.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { BaseError, type BaseErrorOptions } from '@dxos/errors';
|
|
6
|
-
|
|
7
|
-
export class ServiceNotAvailableError extends BaseError.extend('SERVICE_NOT_AVAILABLE', 'Service not available') {
|
|
8
|
-
constructor(service: string, options?: Omit<BaseErrorOptions, 'context'>) {
|
|
9
|
-
super({ context: { service }, ...options });
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class FunctionNotFoundError extends BaseError.extend('FUNCTION_NOT_FOUND', 'Function not found') {
|
|
14
|
-
constructor(functionKey: string, options?: Omit<BaseErrorOptions, 'context'>) {
|
|
15
|
-
super({ context: { function: functionKey }, ...options });
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class FunctionError extends BaseError.extend('FUNCTION_ERROR', 'Function invocation error') {}
|
|
20
|
-
|
|
21
|
-
export class TriggerStateNotFoundError extends BaseError.extend('TRIGGER_STATE_NOT_FOUND', 'Trigger state not found') {}
|
package/src/example/fib.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Effect from 'effect/Effect';
|
|
6
|
-
import * as Schema from 'effect/Schema';
|
|
7
|
-
|
|
8
|
-
import { defineFunction } from '../sdk';
|
|
9
|
-
|
|
10
|
-
export default defineFunction({
|
|
11
|
-
key: 'example.org/function/fib',
|
|
12
|
-
name: 'Fibonacci',
|
|
13
|
-
description: 'Function that calculates a Fibonacci number',
|
|
14
|
-
inputSchema: Schema.Struct({
|
|
15
|
-
iterations: Schema.optional(Schema.Number).annotations({
|
|
16
|
-
description: 'Number of iterations',
|
|
17
|
-
default: 100_000,
|
|
18
|
-
}),
|
|
19
|
-
}),
|
|
20
|
-
outputSchema: Schema.Struct({
|
|
21
|
-
result: Schema.String,
|
|
22
|
-
}),
|
|
23
|
-
handler: Effect.fn(function* ({ data: { iterations = 100_000 } }) {
|
|
24
|
-
let a = 0n;
|
|
25
|
-
let b = 1n;
|
|
26
|
-
for (let i = 0; i < iterations; i++) {
|
|
27
|
-
a += b;
|
|
28
|
-
b = a - b;
|
|
29
|
-
}
|
|
30
|
-
return { result: a.toString() };
|
|
31
|
-
}),
|
|
32
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import { S, defineFunction } from 'dxos:functions';
|
|
7
|
-
import {
|
|
8
|
-
FetchHttpClient,
|
|
9
|
-
HttpClient,
|
|
10
|
-
HttpClientRequest,
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
} from 'https://esm.sh/@effect/platform@0.89.0?deps=effect@3.17.0&bundle=false';
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
import { Effect, Schedule } from 'https://esm.sh/effect@3.17.0?bundle=false';
|
|
15
|
-
|
|
16
|
-
export default defineFunction({
|
|
17
|
-
key: 'dxos.org/script/forex-effect',
|
|
18
|
-
name: 'Forex Effect',
|
|
19
|
-
description: 'Returns the exchange rate between two currencies.',
|
|
20
|
-
|
|
21
|
-
inputSchema: S.Struct({
|
|
22
|
-
from: S.String.annotations({ description: 'The source currency' }),
|
|
23
|
-
to: S.String.annotations({ description: 'The target currency' }),
|
|
24
|
-
}),
|
|
25
|
-
|
|
26
|
-
outputSchema: S.String.annotations({ description: 'The exchange rate between the two currencies' }),
|
|
27
|
-
|
|
28
|
-
handler: async ({ data: { from, to } }: any) =>
|
|
29
|
-
Effect.gen(function* () {
|
|
30
|
-
const res = yield* HttpClientRequest.get(`https://free.ratesdb.com/v1/rates?from=${from}&to=${to}`).pipe(
|
|
31
|
-
HttpClient.execute,
|
|
32
|
-
Effect.flatMap((res: any) => res.json),
|
|
33
|
-
Effect.timeout('1 second'),
|
|
34
|
-
Effect.retry(Schedule.exponential(1_000).pipe(Schedule.compose(Schedule.recurs(3)))),
|
|
35
|
-
Effect.scoped,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
return res.data.rates[to].toString();
|
|
39
|
-
}).pipe(Effect.provide(FetchHttpClient.layer)),
|
|
40
|
-
});
|
package/src/example/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { default as fib$ } from './fib';
|
|
6
|
-
import { default as reply$ } from './reply';
|
|
7
|
-
import { default as sleep$ } from './sleep';
|
|
8
|
-
|
|
9
|
-
export namespace Example {
|
|
10
|
-
export const fib = fib$;
|
|
11
|
-
export const reply = reply$;
|
|
12
|
-
export const sleep = sleep$;
|
|
13
|
-
}
|
package/src/example/reply.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Console from 'effect/Console';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as Schema from 'effect/Schema';
|
|
8
|
-
|
|
9
|
-
import { defineFunction } from '../sdk';
|
|
10
|
-
|
|
11
|
-
export default defineFunction({
|
|
12
|
-
key: 'example.org/function/reply',
|
|
13
|
-
name: 'Reply',
|
|
14
|
-
description: 'Function that echoes the input',
|
|
15
|
-
inputSchema: Schema.Any,
|
|
16
|
-
outputSchema: Schema.Any,
|
|
17
|
-
handler: Effect.fn(function* ({ data }) {
|
|
18
|
-
yield* Console.log('reply', { data });
|
|
19
|
-
return data;
|
|
20
|
-
}),
|
|
21
|
-
});
|
package/src/example/sleep.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Effect from 'effect/Effect';
|
|
6
|
-
import * as Schema from 'effect/Schema';
|
|
7
|
-
|
|
8
|
-
import { defineFunction } from '../sdk';
|
|
9
|
-
|
|
10
|
-
export default defineFunction({
|
|
11
|
-
key: 'example.org/function/sleep',
|
|
12
|
-
name: 'Sleep',
|
|
13
|
-
description: 'Function that sleeps for a given amount of time',
|
|
14
|
-
inputSchema: Schema.Struct({
|
|
15
|
-
duration: Schema.optional(Schema.Number).annotations({
|
|
16
|
-
description: 'Milliseconds to sleep',
|
|
17
|
-
default: 100_000,
|
|
18
|
-
}),
|
|
19
|
-
}),
|
|
20
|
-
outputSchema: Schema.Void,
|
|
21
|
-
handler: Effect.fn(function* ({ data: { duration = 100_000 } }) {
|
|
22
|
-
yield* Effect.sleep(duration);
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Context from 'effect/Context';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as Layer from 'effect/Layer';
|
|
8
|
-
import * as Schema from 'effect/Schema';
|
|
9
|
-
|
|
10
|
-
import { Obj, Type } from '@dxos/echo';
|
|
11
|
-
import { invariant } from '@dxos/invariant';
|
|
12
|
-
import { LogLevel, log } from '@dxos/log';
|
|
13
|
-
|
|
14
|
-
import { TracingService } from './tracing';
|
|
15
|
-
|
|
16
|
-
export const ComputeEventPayload = Schema.Union(
|
|
17
|
-
Schema.Struct({
|
|
18
|
-
type: Schema.Literal('begin-compute'),
|
|
19
|
-
nodeId: Schema.String,
|
|
20
|
-
/**
|
|
21
|
-
* Names of the inputs begin computed.
|
|
22
|
-
*/
|
|
23
|
-
inputs: Schema.Array(Schema.String),
|
|
24
|
-
}),
|
|
25
|
-
Schema.Struct({
|
|
26
|
-
type: Schema.Literal('end-compute'),
|
|
27
|
-
nodeId: Schema.String,
|
|
28
|
-
/**
|
|
29
|
-
* Names of the outputs computed.
|
|
30
|
-
*/
|
|
31
|
-
outputs: Schema.Array(Schema.String),
|
|
32
|
-
}),
|
|
33
|
-
Schema.Struct({
|
|
34
|
-
type: Schema.Literal('compute-input'),
|
|
35
|
-
nodeId: Schema.String,
|
|
36
|
-
property: Schema.String,
|
|
37
|
-
value: Schema.Any,
|
|
38
|
-
}),
|
|
39
|
-
Schema.Struct({
|
|
40
|
-
type: Schema.Literal('compute-output'),
|
|
41
|
-
nodeId: Schema.String,
|
|
42
|
-
property: Schema.String,
|
|
43
|
-
value: Schema.Any,
|
|
44
|
-
}),
|
|
45
|
-
Schema.Struct({
|
|
46
|
-
type: Schema.Literal('custom'),
|
|
47
|
-
nodeId: Schema.String,
|
|
48
|
-
event: Schema.Any,
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
export type ComputeEventPayload = Schema.Schema.Type<typeof ComputeEventPayload>;
|
|
52
|
-
|
|
53
|
-
export const ComputeEvent = Schema.Struct({
|
|
54
|
-
payload: ComputeEventPayload,
|
|
55
|
-
}).pipe(Type.Obj({ typename: 'dxos.org/type/ComputeEvent', version: '0.1.0' }));
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Logs event for the compute workflows.
|
|
59
|
-
*/
|
|
60
|
-
export class ComputeEventLogger extends Context.Tag('@dxos/functions/ComputeEventLogger')<
|
|
61
|
-
ComputeEventLogger,
|
|
62
|
-
{ readonly log: (event: ComputeEventPayload) => void; readonly nodeId: string | undefined }
|
|
63
|
-
>() {
|
|
64
|
-
static noop: Context.Tag.Service<ComputeEventLogger> = {
|
|
65
|
-
log: () => {},
|
|
66
|
-
nodeId: undefined,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Implements ComputeEventLogger using TracingService.
|
|
71
|
-
*/
|
|
72
|
-
static layerFromTracing = Layer.effect(
|
|
73
|
-
ComputeEventLogger,
|
|
74
|
-
Effect.gen(function* () {
|
|
75
|
-
const tracing = yield* TracingService;
|
|
76
|
-
return {
|
|
77
|
-
log: (event: ComputeEventPayload) => {
|
|
78
|
-
tracing.write(Obj.make(ComputeEvent, { payload: event }));
|
|
79
|
-
},
|
|
80
|
-
nodeId: undefined,
|
|
81
|
-
};
|
|
82
|
-
}),
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const logCustomEvent = (data: any) =>
|
|
87
|
-
Effect.gen(function* () {
|
|
88
|
-
const logger = yield* ComputeEventLogger;
|
|
89
|
-
if (!logger.nodeId) {
|
|
90
|
-
throw new Error('logCustomEvent must be called within a node compute function');
|
|
91
|
-
}
|
|
92
|
-
logger.log({
|
|
93
|
-
type: 'custom',
|
|
94
|
-
nodeId: logger.nodeId,
|
|
95
|
-
event: data,
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
export const createDefectLogger = <A, E, R>(): ((self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>) =>
|
|
100
|
-
Effect.catchAll((error) =>
|
|
101
|
-
Effect.gen(function* () {
|
|
102
|
-
log.error('unhandled effect error', { error });
|
|
103
|
-
throw error;
|
|
104
|
-
}),
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
export const createEventLogger = (
|
|
108
|
-
level: LogLevel,
|
|
109
|
-
message: string = 'event',
|
|
110
|
-
): Context.Tag.Service<ComputeEventLogger> => {
|
|
111
|
-
const logFunction = (
|
|
112
|
-
{
|
|
113
|
-
[LogLevel.WARN]: log.warn,
|
|
114
|
-
[LogLevel.VERBOSE]: log.verbose,
|
|
115
|
-
[LogLevel.DEBUG]: log.debug,
|
|
116
|
-
[LogLevel.INFO]: log.info,
|
|
117
|
-
[LogLevel.ERROR]: log.error,
|
|
118
|
-
} as any
|
|
119
|
-
)[level];
|
|
120
|
-
invariant(logFunction);
|
|
121
|
-
return {
|
|
122
|
-
log: (event: ComputeEventPayload) => {
|
|
123
|
-
logFunction(message, event);
|
|
124
|
-
},
|
|
125
|
-
nodeId: undefined,
|
|
126
|
-
};
|
|
127
|
-
};
|
package/src/services/queues.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Context from 'effect/Context';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
import * as Layer from 'effect/Layer';
|
|
8
|
-
|
|
9
|
-
import type { Obj, Relation } from '@dxos/echo';
|
|
10
|
-
import type { Queue, QueueAPI, QueueFactory } from '@dxos/echo-db';
|
|
11
|
-
import type { DXN, QueueSubspaceTag } from '@dxos/keys';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Gives access to all queues.
|
|
15
|
-
*/
|
|
16
|
-
export class QueueService extends Context.Tag('@dxos/functions/QueueService')<
|
|
17
|
-
QueueService,
|
|
18
|
-
{
|
|
19
|
-
/**
|
|
20
|
-
* API to access the queues.
|
|
21
|
-
*/
|
|
22
|
-
readonly queues: QueueAPI;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The queue that is used to store the context of the current research.
|
|
26
|
-
* @deprecated Use `ContextQueueService` instead.
|
|
27
|
-
*/
|
|
28
|
-
readonly queue: Queue | undefined;
|
|
29
|
-
}
|
|
30
|
-
>() {
|
|
31
|
-
static notAvailable = Layer.succeed(QueueService, {
|
|
32
|
-
queues: {
|
|
33
|
-
get(_dxn) {
|
|
34
|
-
throw new Error('Queues not available');
|
|
35
|
-
},
|
|
36
|
-
create() {
|
|
37
|
-
throw new Error('Queues not available');
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
queue: undefined,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
static make = (queues: QueueFactory, queue?: Queue): Context.Tag.Service<QueueService> => {
|
|
44
|
-
return {
|
|
45
|
-
queues,
|
|
46
|
-
queue,
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
static layer = (queues: QueueFactory, queue?: Queue): Layer.Layer<QueueService> =>
|
|
51
|
-
Layer.succeed(QueueService, QueueService.make(queues, queue));
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Gets a queue by its DXN.
|
|
55
|
-
*/
|
|
56
|
-
static getQueue = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(
|
|
57
|
-
dxn: DXN,
|
|
58
|
-
): Effect.Effect<Queue<T>, never, QueueService> => QueueService.pipe(Effect.map(({ queues }) => queues.get<T>(dxn)));
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Creates a new queue.
|
|
62
|
-
*/
|
|
63
|
-
static createQueue = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(options?: {
|
|
64
|
-
subspaceTag?: QueueSubspaceTag;
|
|
65
|
-
}): Effect.Effect<Queue<T>, never, QueueService> =>
|
|
66
|
-
QueueService.pipe(Effect.map(({ queues }) => queues.create<T>(options)));
|
|
67
|
-
|
|
68
|
-
static append = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(
|
|
69
|
-
queue: Queue<T>,
|
|
70
|
-
objects: T[],
|
|
71
|
-
): Effect.Effect<void> => Effect.promise(() => queue.append(objects));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Gives access to a specific queue passed as a context.
|
|
76
|
-
*/
|
|
77
|
-
export class ContextQueueService extends Context.Tag('@dxos/functions/ContextQueueService')<
|
|
78
|
-
ContextQueueService,
|
|
79
|
-
{
|
|
80
|
-
readonly queue: Queue;
|
|
81
|
-
}
|
|
82
|
-
>() {
|
|
83
|
-
static layer = (queue: Queue) => Layer.succeed(ContextQueueService, { queue });
|
|
84
|
-
}
|