@dxos/functions 0.7.5-labs.ea4b4c2 → 0.7.5-labs.f400bbc
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 +20 -20
- package/dist/lib/browser/bundler/index.mjs.map +3 -3
- package/dist/lib/browser/{chunk-PI2DP37S.mjs → chunk-IXJNRWJP.mjs} +40 -10
- package/dist/lib/browser/chunk-IXJNRWJP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-JNWHUD6Z.mjs → chunk-XLM3CJXO.mjs} +2 -2
- package/dist/lib/browser/index.mjs +23 -7
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/bundler/index.cjs +20 -20
- package/dist/lib/node/bundler/index.cjs.map +3 -3
- package/dist/lib/node/{chunk-PGFJYL6Q.cjs → chunk-MGCKR53Q.cjs} +41 -13
- package/dist/lib/node/chunk-MGCKR53Q.cjs.map +7 -0
- package/dist/lib/node/{chunk-2ASAZ4AS.cjs → chunk-TLSUCABH.cjs} +15 -15
- package/dist/lib/node/index.cjs +36 -19
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +7 -7
- package/dist/lib/node/types/index.cjs +10 -10
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/bundler/index.mjs +20 -20
- package/dist/lib/node-esm/bundler/index.mjs.map +3 -3
- package/dist/lib/node-esm/{chunk-LNBGGB6Z.mjs → chunk-CKTHJQ7M.mjs} +2 -2
- package/dist/lib/node-esm/{chunk-IOAKDIT3.mjs → chunk-FCZGNRNF.mjs} +40 -10
- package/dist/lib/node-esm/chunk-FCZGNRNF.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +23 -7
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +2 -2
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/bundler/bundler.d.ts +15 -3
- package/dist/types/src/bundler/bundler.d.ts.map +1 -1
- package/dist/types/src/handler.d.ts +30 -4
- package/dist/types/src/handler.d.ts.map +1 -1
- package/dist/types/src/testing/types.d.ts +2 -2
- package/dist/types/src/types/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +16 -16
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/types/trace.d.ts +103 -0
- package/dist/types/src/types/trace.d.ts.map +1 -0
- package/dist/types/src/types/types.d.ts +8 -8
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/package.json +21 -20
- package/src/bundler/bundler.test.ts +10 -6
- package/src/bundler/bundler.ts +21 -7
- package/src/handler.ts +58 -9
- package/src/types/index.ts +1 -0
- package/src/types/schema.ts +0 -1
- package/src/types/trace.ts +49 -0
- package/src/types/types.ts +1 -1
- package/dist/lib/browser/chunk-PI2DP37S.mjs.map +0 -7
- package/dist/lib/node/chunk-PGFJYL6Q.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-IOAKDIT3.mjs.map +0 -7
- /package/dist/lib/browser/{chunk-JNWHUD6Z.mjs.map → chunk-XLM3CJXO.mjs.map} +0 -0
- /package/dist/lib/node/{chunk-2ASAZ4AS.cjs.map → chunk-TLSUCABH.cjs.map} +0 -0
- /package/dist/lib/node-esm/{chunk-LNBGGB6Z.mjs.map → chunk-CKTHJQ7M.mjs.map} +0 -0
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Schema as S } from '@effect/schema';
|
|
2
|
+
import { type Effect } from 'effect';
|
|
2
3
|
import { type Client } from '@dxos/client';
|
|
3
4
|
import { type Space, type SpaceId } from '@dxos/client/echo';
|
|
4
|
-
import type { CoreDatabase, ReactiveEchoObject } from '@dxos/echo-db';
|
|
5
|
+
import type { CoreDatabase, EchoDatabase, ReactiveEchoObject } from '@dxos/echo-db';
|
|
6
|
+
import { type HasId } from '@dxos/echo-schema';
|
|
7
|
+
import { type DXN } from '@dxos/keys';
|
|
8
|
+
import { type QueryResult } from '@dxos/protocols';
|
|
5
9
|
/**
|
|
6
10
|
* Function handler.
|
|
7
11
|
*/
|
|
8
|
-
export type FunctionHandler<TData = {}, TMeta = {}> = (params: {
|
|
12
|
+
export type FunctionHandler<TData = {}, TMeta = {}, TOutput = any> = (params: {
|
|
9
13
|
context: FunctionContext;
|
|
10
14
|
event: FunctionEvent<TData, TMeta>;
|
|
11
15
|
/**
|
|
12
16
|
* @deprecated
|
|
13
17
|
*/
|
|
14
18
|
response: FunctionResponse;
|
|
15
|
-
}) => Promise<
|
|
19
|
+
}) => TOutput | Promise<TOutput> | Effect.Effect<TOutput, any>;
|
|
16
20
|
/**
|
|
17
21
|
* Function context.
|
|
18
22
|
*/
|
|
@@ -53,13 +57,35 @@ export type FunctionEventMeta<TMeta = {}> = {
|
|
|
53
57
|
export type FunctionResponse = {
|
|
54
58
|
status(code: number): FunctionResponse;
|
|
55
59
|
};
|
|
60
|
+
export interface QueuesAPI {
|
|
61
|
+
queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;
|
|
62
|
+
insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;
|
|
63
|
+
}
|
|
56
64
|
/**
|
|
57
65
|
* Space interface available to functions.
|
|
58
66
|
*/
|
|
59
67
|
export interface SpaceAPI {
|
|
60
68
|
get id(): SpaceId;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated
|
|
71
|
+
*/
|
|
61
72
|
get crud(): CoreDatabase;
|
|
73
|
+
get db(): EchoDatabase;
|
|
74
|
+
get queues(): QueuesAPI;
|
|
62
75
|
}
|
|
76
|
+
export type FunctionDefinition = {
|
|
77
|
+
description?: string;
|
|
78
|
+
inputSchema: S.Schema.AnyNoContext;
|
|
79
|
+
outputSchema?: S.Schema.AnyNoContext;
|
|
80
|
+
handler: FunctionHandler<any>;
|
|
81
|
+
};
|
|
82
|
+
export type DefineFunctionParams<T, O = any> = {
|
|
83
|
+
description?: string;
|
|
84
|
+
inputSchema: S.Schema<T, any>;
|
|
85
|
+
outputSchema?: S.Schema<O, any>;
|
|
86
|
+
handler: FunctionHandler<T, any, O>;
|
|
87
|
+
};
|
|
88
|
+
export declare const defineFunction: <T, O>(params: DefineFunctionParams<T, O>) => FunctionDefinition;
|
|
63
89
|
export type RawSubscriptionData = {
|
|
64
90
|
spaceKey?: string;
|
|
65
91
|
objects?: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,KAAK,MAAM,EAAa,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACpF,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAQnD;;GAEG;AACH,MAAM,MAAM,eAAe,CAAC,KAAK,GAAG,EAAE,EAAE,KAAK,GAAG,EAAE,EAAE,OAAO,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE;IAC5E,OAAO,EAAE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EAAE,CAAC;CACrC,CAAC;AAEF;;;;;;;;;GASG;AAEH,eAAO,MAAM,mBAAmB,GAAI,KAAK,WAC9B,eAAe,CAAC,gBAAgB,EAAE,KAAK,CAAC,UACzC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,KACtB,eAAe,CAAC,mBAAmB,EAAE,KAAK,CAwB5C,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { S } from '@dxos/echo-schema';
|
|
2
|
-
declare const TestType_base: import("@dxos/echo-schema").TypedObjectPrototype<import("
|
|
2
|
+
declare const TestType_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
|
|
3
3
|
title: typeof S.String;
|
|
4
|
-
}, import("
|
|
4
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
|
|
5
5
|
title: typeof S.String;
|
|
6
6
|
}>>;
|
|
7
7
|
export declare class TestType extends TestType_base {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
import { JsonSchemaType, S } from '@dxos/echo-schema';
|
|
2
|
-
declare const ScriptType_base: import("@dxos/echo-schema").TypedObjectPrototype<import("
|
|
2
|
+
declare const ScriptType_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
|
|
3
3
|
name: S.optional<typeof S.String>;
|
|
4
4
|
description: S.optional<typeof S.String>;
|
|
5
5
|
changed: S.optional<typeof S.Boolean>;
|
|
6
|
-
source: import("@dxos/echo-schema").Ref$<import("
|
|
6
|
+
source: import("@dxos/echo-schema").Ref$<import("@dxos/echo-schema").TypedObjectFields<{
|
|
7
7
|
content: typeof S.String;
|
|
8
|
-
}, import("
|
|
9
|
-
}, import("
|
|
8
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>>;
|
|
9
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
|
|
10
10
|
name: S.optional<typeof S.String>;
|
|
11
11
|
description: S.optional<typeof S.String>;
|
|
12
12
|
changed: S.optional<typeof S.Boolean>;
|
|
13
|
-
source: import("@dxos/echo-schema").Ref$<import("
|
|
13
|
+
source: import("@dxos/echo-schema").Ref$<import("@dxos/echo-schema").TypedObjectFields<{
|
|
14
14
|
content: typeof S.String;
|
|
15
|
-
}, import("
|
|
15
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>>;
|
|
16
16
|
}>>;
|
|
17
17
|
/**
|
|
18
18
|
* Source script.
|
|
19
19
|
*/
|
|
20
20
|
export declare class ScriptType extends ScriptType_base {
|
|
21
21
|
}
|
|
22
|
-
declare const FunctionType_base: import("@dxos/echo-schema").TypedObjectPrototype<import("
|
|
22
|
+
declare const FunctionType_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
|
|
23
23
|
name: typeof S.NonEmptyString;
|
|
24
24
|
version: typeof S.String;
|
|
25
25
|
description: S.optional<typeof S.String>;
|
|
26
|
-
source: S.optional<import("@dxos/echo-schema").Ref$<import("
|
|
26
|
+
source: S.optional<import("@dxos/echo-schema").Ref$<import("@dxos/echo-schema").TypedObjectFields<{
|
|
27
27
|
name: S.optional<typeof S.String>;
|
|
28
28
|
description: S.optional<typeof S.String>;
|
|
29
29
|
changed: S.optional<typeof S.Boolean>;
|
|
30
|
-
source: import("@dxos/echo-schema").Ref$<import("
|
|
30
|
+
source: import("@dxos/echo-schema").Ref$<import("@dxos/echo-schema").TypedObjectFields<{
|
|
31
31
|
content: typeof S.String;
|
|
32
|
-
}, import("
|
|
33
|
-
}, import("
|
|
32
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>>;
|
|
33
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>>>;
|
|
34
34
|
inputSchema: S.optional<S.Schema<JsonSchemaType, JsonSchemaType, never>>;
|
|
35
35
|
outputSchema: S.optional<S.Schema<JsonSchemaType, JsonSchemaType, never>>;
|
|
36
36
|
binding: S.optional<typeof S.String>;
|
|
37
|
-
}, import("
|
|
37
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
|
|
38
38
|
name: typeof S.NonEmptyString;
|
|
39
39
|
version: typeof S.String;
|
|
40
40
|
description: S.optional<typeof S.String>;
|
|
41
|
-
source: S.optional<import("@dxos/echo-schema").Ref$<import("
|
|
41
|
+
source: S.optional<import("@dxos/echo-schema").Ref$<import("@dxos/echo-schema").TypedObjectFields<{
|
|
42
42
|
name: S.optional<typeof S.String>;
|
|
43
43
|
description: S.optional<typeof S.String>;
|
|
44
44
|
changed: S.optional<typeof S.Boolean>;
|
|
45
|
-
source: import("@dxos/echo-schema").Ref$<import("
|
|
45
|
+
source: import("@dxos/echo-schema").Ref$<import("@dxos/echo-schema").TypedObjectFields<{
|
|
46
46
|
content: typeof S.String;
|
|
47
|
-
}, import("
|
|
48
|
-
}, import("
|
|
47
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>>;
|
|
48
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>>>;
|
|
49
49
|
inputSchema: S.optional<S.Schema<JsonSchemaType, JsonSchemaType, never>>;
|
|
50
50
|
outputSchema: S.optional<S.Schema<JsonSchemaType, JsonSchemaType, never>>;
|
|
51
51
|
binding: S.optional<typeof S.String>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/types/schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAO,CAAC,EAAe,MAAM,mBAAmB,CAAC;;;;;;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/types/schema.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAO,CAAC,EAAe,MAAM,mBAAmB,CAAC;;;;;;wBAM/D,EAAI,MAAK;;;;;;;wBAAT,EAAI,MAAK;;;AAHlB;;GAEG;AACH,qBAAa,UAAW,SAAQ,eAU9B;CAAG;;;;;;;;;;4BAVI,EAAI,MAAK;;;;;;;;;;;;;;;4BAAT,EAAI,MAAK;;;;;;;AAYlB;;GAEG;AAEH,qBAAa,YAAa,SAAQ,iBAmBhC;CAAG"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Expando, Ref, S } from '@dxos/echo-schema';
|
|
2
|
+
declare const InvocationTrace: S.Schema<{
|
|
3
|
+
readonly id: string;
|
|
4
|
+
invocationTraceQueue: Ref<Expando>;
|
|
5
|
+
invocationTarget: Ref<Expando>;
|
|
6
|
+
trigger?: Ref<import("@dxos/echo-schema").TypedObjectFields<{
|
|
7
|
+
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
8
|
+
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
9
|
+
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
10
|
+
type: S.Literal<[import("./types").TriggerKind.Timer]>;
|
|
11
|
+
cron: S.SchemaClass<string, string, never>;
|
|
12
|
+
}>>, S.mutable<S.Struct<{
|
|
13
|
+
type: S.Literal<[import("./types").TriggerKind.Webhook]>;
|
|
14
|
+
method: S.optional<S.SchemaClass<string, string, never>>;
|
|
15
|
+
port: S.optional<S.SchemaClass<number, number, never>>;
|
|
16
|
+
}>>, S.mutable<S.Struct<{
|
|
17
|
+
type: S.Literal<[import("./types").TriggerKind.Subscription]>;
|
|
18
|
+
filter: S.Struct<{
|
|
19
|
+
type: S.optional<S.SchemaClass<string, string, never>>;
|
|
20
|
+
props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
21
|
+
}>;
|
|
22
|
+
options: S.optional<S.Struct<{
|
|
23
|
+
deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
24
|
+
delay: S.optional<S.SchemaClass<number, number, never>>;
|
|
25
|
+
}>>;
|
|
26
|
+
}>>, S.mutable<S.Struct<{
|
|
27
|
+
type: S.Literal<[import("./types").TriggerKind.Email]>;
|
|
28
|
+
}>>, S.mutable<S.Struct<{
|
|
29
|
+
type: S.Literal<[import("./types").TriggerKind.Queue]>;
|
|
30
|
+
queue: S.refine<string, S.Schema<string, string, never>>;
|
|
31
|
+
}>>]>>;
|
|
32
|
+
readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
33
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>> | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
readonly id: string;
|
|
36
|
+
invocationTraceQueue: Ref<Expando>;
|
|
37
|
+
invocationTarget: Ref<Expando>;
|
|
38
|
+
trigger?: Ref<import("@dxos/echo-schema").TypedObjectFields<{
|
|
39
|
+
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
40
|
+
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
41
|
+
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
42
|
+
type: S.Literal<[import("./types").TriggerKind.Timer]>;
|
|
43
|
+
cron: S.SchemaClass<string, string, never>;
|
|
44
|
+
}>>, S.mutable<S.Struct<{
|
|
45
|
+
type: S.Literal<[import("./types").TriggerKind.Webhook]>;
|
|
46
|
+
method: S.optional<S.SchemaClass<string, string, never>>;
|
|
47
|
+
port: S.optional<S.SchemaClass<number, number, never>>;
|
|
48
|
+
}>>, S.mutable<S.Struct<{
|
|
49
|
+
type: S.Literal<[import("./types").TriggerKind.Subscription]>;
|
|
50
|
+
filter: S.Struct<{
|
|
51
|
+
type: S.optional<S.SchemaClass<string, string, never>>;
|
|
52
|
+
props: S.optional<S.Record$<typeof S.String, typeof S.Any>>;
|
|
53
|
+
}>;
|
|
54
|
+
options: S.optional<S.Struct<{
|
|
55
|
+
deep: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
56
|
+
delay: S.optional<S.SchemaClass<number, number, never>>;
|
|
57
|
+
}>>;
|
|
58
|
+
}>>, S.mutable<S.Struct<{
|
|
59
|
+
type: S.Literal<[import("./types").TriggerKind.Email]>;
|
|
60
|
+
}>>, S.mutable<S.Struct<{
|
|
61
|
+
type: S.Literal<[import("./types").TriggerKind.Queue]>;
|
|
62
|
+
queue: S.refine<string, S.Schema<string, string, never>>;
|
|
63
|
+
}>>]>>;
|
|
64
|
+
readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
65
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>> | undefined;
|
|
66
|
+
}, never>;
|
|
67
|
+
export type InvocationTraceEvent = S.Schema.Type<typeof InvocationTrace>;
|
|
68
|
+
declare const TraceEvent: S.Schema<{
|
|
69
|
+
readonly id: string;
|
|
70
|
+
outcome: string;
|
|
71
|
+
truncated: boolean;
|
|
72
|
+
logs: {
|
|
73
|
+
readonly context?: object | undefined;
|
|
74
|
+
readonly timestampMs: number;
|
|
75
|
+
readonly level: string;
|
|
76
|
+
readonly message: string;
|
|
77
|
+
}[];
|
|
78
|
+
exceptions: {
|
|
79
|
+
readonly name: string;
|
|
80
|
+
readonly timestampMs: number;
|
|
81
|
+
readonly message: string;
|
|
82
|
+
readonly stack?: string | undefined;
|
|
83
|
+
}[];
|
|
84
|
+
}, {
|
|
85
|
+
readonly id: string;
|
|
86
|
+
outcome: string;
|
|
87
|
+
truncated: boolean;
|
|
88
|
+
logs: {
|
|
89
|
+
readonly context?: object | undefined;
|
|
90
|
+
readonly timestampMs: number;
|
|
91
|
+
readonly level: string;
|
|
92
|
+
readonly message: string;
|
|
93
|
+
}[];
|
|
94
|
+
exceptions: {
|
|
95
|
+
readonly name: string;
|
|
96
|
+
readonly timestampMs: number;
|
|
97
|
+
readonly message: string;
|
|
98
|
+
readonly stack?: string | undefined;
|
|
99
|
+
}[];
|
|
100
|
+
}, never>;
|
|
101
|
+
export type TraceEvent = S.Schema.Type<typeof TraceEvent>;
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../../../src/types/trace.ts"],"names":[],"mappings":"AAIA,OAAO,EAAc,OAAO,EAAY,GAAG,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAI1E,QAAA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAcwC,CAAC;AAE9D,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,eAAe,CAAC,CAAC;AAgBzE,QAAA,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAMwC,CAAC;AAEzD,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAC"}
|
|
@@ -111,7 +111,7 @@ export declare const FunctionTriggerSchema: S.Struct<{
|
|
|
111
111
|
meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
112
112
|
}>;
|
|
113
113
|
export type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;
|
|
114
|
-
declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectPrototype<import("
|
|
114
|
+
declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
|
|
115
115
|
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
116
116
|
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
117
117
|
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
@@ -138,7 +138,7 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
|
|
|
138
138
|
queue: S.refine<string, S.Schema<string, string, never>>;
|
|
139
139
|
}>>]>>;
|
|
140
140
|
readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
141
|
-
}, import("
|
|
141
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
|
|
142
142
|
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
143
143
|
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
144
144
|
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
@@ -171,12 +171,12 @@ declare const FunctionTrigger_base: import("@dxos/echo-schema").TypedObjectProto
|
|
|
171
171
|
*/
|
|
172
172
|
export declare class FunctionTrigger extends FunctionTrigger_base {
|
|
173
173
|
}
|
|
174
|
-
declare const FunctionDef_base: import("@dxos/echo-schema").TypedObjectPrototype<import("
|
|
174
|
+
declare const FunctionDef_base: import("@dxos/echo-schema").TypedObjectPrototype<import("@dxos/echo-schema").TypedObjectFields<{
|
|
175
175
|
uri: typeof S.String;
|
|
176
176
|
description: S.optional<typeof S.String>;
|
|
177
177
|
route: typeof S.String;
|
|
178
178
|
handler: typeof S.String;
|
|
179
|
-
}, import("
|
|
179
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>, S.Struct.Encoded<{
|
|
180
180
|
uri: typeof S.String;
|
|
181
181
|
description: S.optional<typeof S.String>;
|
|
182
182
|
route: typeof S.String;
|
|
@@ -192,18 +192,18 @@ export declare class FunctionDef extends FunctionDef_base {
|
|
|
192
192
|
* Function manifest file.
|
|
193
193
|
*/
|
|
194
194
|
export declare const FunctionManifestSchema: S.Struct<{
|
|
195
|
-
functions: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("
|
|
195
|
+
functions: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("@dxos/echo-schema").TypedObjectFields<{
|
|
196
196
|
uri: typeof S.String;
|
|
197
197
|
description: S.optional<typeof S.String>;
|
|
198
198
|
route: typeof S.String;
|
|
199
199
|
handler: typeof S.String;
|
|
200
|
-
}, import("
|
|
200
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
|
|
201
201
|
uri: typeof S.String;
|
|
202
202
|
description: S.optional<typeof S.String>;
|
|
203
203
|
route: typeof S.String;
|
|
204
204
|
handler: typeof S.String;
|
|
205
205
|
}>, never>>>>;
|
|
206
|
-
triggers: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("
|
|
206
|
+
triggers: S.optional<S.mutable<S.Array$<S.Schema<import("@dxos/echo-schema").ExcludeId<import("@dxos/echo-schema").TypedObjectFields<{
|
|
207
207
|
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
208
208
|
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
209
209
|
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
@@ -230,7 +230,7 @@ export declare const FunctionManifestSchema: S.Struct<{
|
|
|
230
230
|
queue: S.refine<string, S.Schema<string, string, never>>;
|
|
231
231
|
}>>]>>;
|
|
232
232
|
readonly meta: S.optional<S.mutable<S.Record$<typeof S.String, typeof S.Any>>>;
|
|
233
|
-
}, import("
|
|
233
|
+
}, import("@dxos/echo-schema").TypedObjectOptions>> & import("@dxos/echo-schema").WithMeta, S.Struct.Encoded<{
|
|
234
234
|
readonly function: S.optional<S.SchemaClass<string, string, never>>;
|
|
235
235
|
readonly enabled: S.optional<S.SchemaClass<boolean, boolean, never>>;
|
|
236
236
|
readonly spec: S.optional<S.Union<[S.mutable<S.Struct<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/types/types.ts"],"names":[],"mappings":"AAIA,OAAO,EA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,gBAQ/B;CAAG;AAEL;;GAEG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE5E,eAAO,MAAM,cAAc,iDAAiC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/functions",
|
|
3
|
-
"version": "0.7.5-labs.
|
|
3
|
+
"version": "0.7.5-labs.f400bbc",
|
|
4
4
|
"description": "Functions API and runtime.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"author": "info@dxos.org",
|
|
9
9
|
"sideEffects": true,
|
|
10
|
+
"type": "module",
|
|
10
11
|
"exports": {
|
|
11
12
|
".": {
|
|
12
13
|
"types": "./dist/types/src/index.d.ts",
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
"dist/types/src/testing/index.d.ts"
|
|
48
49
|
],
|
|
49
50
|
"types": [
|
|
50
|
-
"dist/types/src/types.d.ts"
|
|
51
|
+
"dist/types/src/types/index.d.ts"
|
|
51
52
|
]
|
|
52
53
|
}
|
|
53
54
|
},
|
|
@@ -61,32 +62,32 @@
|
|
|
61
62
|
"@preact/signals-core": "^1.6.0",
|
|
62
63
|
"cron": "^3.1.6",
|
|
63
64
|
"effect": "^3.12.3",
|
|
64
|
-
"esbuild-wasm": "0.16.14",
|
|
65
|
+
"esbuild-wasm": "^0.16.14",
|
|
65
66
|
"express": "^4.19.2",
|
|
66
67
|
"get-port-please": "^3.1.1",
|
|
67
68
|
"iso-did": "^1.6.0",
|
|
68
69
|
"ws": "^8.14.2",
|
|
69
|
-
"@dxos/async": "0.7.5-labs.
|
|
70
|
-
"@dxos/context": "0.7.5-labs.
|
|
71
|
-
"@dxos/client": "0.7.5-labs.
|
|
72
|
-
"@dxos/echo-db": "0.7.5-labs.
|
|
73
|
-
"@dxos/echo-protocol": "0.7.5-labs.
|
|
74
|
-
"@dxos/echo-schema": "0.7.5-labs.
|
|
75
|
-
"@dxos/crypto": "0.7.5-labs.
|
|
76
|
-
"@dxos/edge-client": "0.7.5-labs.
|
|
77
|
-
"@dxos/invariant": "0.7.5-labs.
|
|
78
|
-
"@dxos/keys": "0.7.5-labs.
|
|
79
|
-
"@dxos/live-object": "0.7.5-labs.
|
|
80
|
-
"@dxos/
|
|
81
|
-
"@dxos/
|
|
82
|
-
"@dxos/
|
|
83
|
-
"@dxos/
|
|
84
|
-
"@dxos/util": "0.7.5-labs.
|
|
70
|
+
"@dxos/async": "0.7.5-labs.f400bbc",
|
|
71
|
+
"@dxos/context": "0.7.5-labs.f400bbc",
|
|
72
|
+
"@dxos/client": "0.7.5-labs.f400bbc",
|
|
73
|
+
"@dxos/echo-db": "0.7.5-labs.f400bbc",
|
|
74
|
+
"@dxos/echo-protocol": "0.7.5-labs.f400bbc",
|
|
75
|
+
"@dxos/echo-schema": "0.7.5-labs.f400bbc",
|
|
76
|
+
"@dxos/crypto": "0.7.5-labs.f400bbc",
|
|
77
|
+
"@dxos/edge-client": "0.7.5-labs.f400bbc",
|
|
78
|
+
"@dxos/invariant": "0.7.5-labs.f400bbc",
|
|
79
|
+
"@dxos/keys": "0.7.5-labs.f400bbc",
|
|
80
|
+
"@dxos/live-object": "0.7.5-labs.f400bbc",
|
|
81
|
+
"@dxos/log": "0.7.5-labs.f400bbc",
|
|
82
|
+
"@dxos/node-std": "0.7.5-labs.f400bbc",
|
|
83
|
+
"@dxos/schema": "0.7.5-labs.f400bbc",
|
|
84
|
+
"@dxos/protocols": "0.7.5-labs.f400bbc",
|
|
85
|
+
"@dxos/util": "0.7.5-labs.f400bbc"
|
|
85
86
|
},
|
|
86
87
|
"devDependencies": {
|
|
87
88
|
"@types/express": "^4.17.17",
|
|
88
89
|
"@types/ws": "^7.4.0",
|
|
89
|
-
"@dxos/agent": "0.7.5-labs.
|
|
90
|
+
"@dxos/agent": "0.7.5-labs.f400bbc"
|
|
90
91
|
},
|
|
91
92
|
"publishConfig": {
|
|
92
93
|
"access": "public"
|
|
@@ -19,18 +19,20 @@ describe('Bundler', () => {
|
|
|
19
19
|
|
|
20
20
|
test('Basic', async () => {
|
|
21
21
|
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
22
|
-
const result = await bundler.bundle('const x = 100'); // TODO(burdon): Test import.
|
|
22
|
+
const result = await bundler.bundle({ source: 'const x = 100' }); // TODO(burdon): Test import.
|
|
23
23
|
expect(result.bundle).to.exist;
|
|
24
24
|
expect(result.error).to.not.exist;
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
test('Import', async () => {
|
|
28
28
|
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
29
|
-
const result = await bundler.bundle(
|
|
29
|
+
const result = await bundler.bundle({
|
|
30
|
+
source: `
|
|
30
31
|
import { Filter } from './runtime.js';
|
|
31
32
|
|
|
32
33
|
const query = Filter.typename('dxos.org/type/Example');
|
|
33
|
-
|
|
34
|
+
`,
|
|
35
|
+
});
|
|
34
36
|
expect(result.bundle).to.exist;
|
|
35
37
|
expect(result.error).to.not.exist;
|
|
36
38
|
});
|
|
@@ -38,17 +40,19 @@ describe('Bundler', () => {
|
|
|
38
40
|
// TODO(dmaretskyi): Flaky on CI: https://cloud.nx.app/runs/Hjcifa8Ccq/task/plugin-script%3Atest
|
|
39
41
|
test.skip('HTTPS Import', async () => {
|
|
40
42
|
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
41
|
-
const result = await bundler.bundle(
|
|
43
|
+
const result = await bundler.bundle({
|
|
44
|
+
source: `
|
|
42
45
|
import { invariant } from 'https://esm.sh/@dxos/invariant';
|
|
43
46
|
invariant(true);
|
|
44
|
-
|
|
47
|
+
`,
|
|
48
|
+
});
|
|
45
49
|
expect(result.bundle).to.exist;
|
|
46
50
|
expect(result.error).to.not.exist;
|
|
47
51
|
});
|
|
48
52
|
|
|
49
53
|
test('Error', async () => {
|
|
50
54
|
const bundler = new Bundler({ platform: 'node', sandboxedModules: [], remoteModules: {} });
|
|
51
|
-
const result = await bundler.bundle("import missing from './module'; missing();");
|
|
55
|
+
const result = await bundler.bundle({ source: "import missing from './module'; missing();" });
|
|
52
56
|
expect(result.bundle).to.not.exist;
|
|
53
57
|
expect(result.error).to.exist;
|
|
54
58
|
});
|
package/src/bundler/bundler.ts
CHANGED
|
@@ -15,9 +15,23 @@ export type Import = {
|
|
|
15
15
|
namedImports: string[];
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export type
|
|
18
|
+
export type BundleOptions = {
|
|
19
|
+
/**
|
|
20
|
+
* Path to the source file on the local file system.
|
|
21
|
+
* If provided, the path will be used instead of the `source` code.
|
|
22
|
+
*/
|
|
23
|
+
path?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Source code to bundle.
|
|
27
|
+
* Required if `path` is not provided.
|
|
28
|
+
*/
|
|
29
|
+
source?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type BundleResult = {
|
|
19
33
|
timestamp: number;
|
|
20
|
-
sourceHash
|
|
34
|
+
sourceHash?: Buffer;
|
|
21
35
|
imports?: Import[];
|
|
22
36
|
bundle?: string;
|
|
23
37
|
error?: any;
|
|
@@ -42,13 +56,13 @@ export const initializeBundler = async (options: { wasmUrl: string }) => {
|
|
|
42
56
|
export class Bundler {
|
|
43
57
|
constructor(private readonly _options: BundlerOptions) {}
|
|
44
58
|
|
|
45
|
-
async bundle(source:
|
|
59
|
+
async bundle({ path, source }: BundleOptions): Promise<BundleResult> {
|
|
46
60
|
const { sandboxedModules: providedModules, ...options } = this._options;
|
|
47
61
|
|
|
48
|
-
const createResult = async (result?: Partial<
|
|
62
|
+
const createResult = async (result?: Partial<BundleResult>) => {
|
|
49
63
|
return {
|
|
50
64
|
timestamp: Date.now(),
|
|
51
|
-
sourceHash: Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))),
|
|
65
|
+
sourceHash: source ? Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))) : undefined,
|
|
52
66
|
...result,
|
|
53
67
|
};
|
|
54
68
|
};
|
|
@@ -58,7 +72,7 @@ export class Bundler {
|
|
|
58
72
|
await initialized;
|
|
59
73
|
}
|
|
60
74
|
|
|
61
|
-
const imports = analyzeSourceFileImports(source);
|
|
75
|
+
const imports = source ? analyzeSourceFileImports(source) : [];
|
|
62
76
|
|
|
63
77
|
// https://esbuild.github.io/api/#build
|
|
64
78
|
try {
|
|
@@ -67,7 +81,7 @@ export class Bundler {
|
|
|
67
81
|
conditions: ['workerd', 'browser'],
|
|
68
82
|
metafile: true,
|
|
69
83
|
write: false,
|
|
70
|
-
entryPoints: ['memory:main.tsx'],
|
|
84
|
+
entryPoints: [path ?? 'memory:main.tsx'],
|
|
71
85
|
bundle: true,
|
|
72
86
|
format: 'esm',
|
|
73
87
|
plugins: [
|