@dxos/functions 0.8.4-main.ae835ea → 0.8.4-main.bc674ce
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/index.mjs +767 -884
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +767 -884
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/errors.d.ts +44 -60
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/example/fib.d.ts +1 -1
- package/dist/types/src/example/index.d.ts +3 -3
- package/dist/types/src/example/index.d.ts.map +1 -1
- package/dist/types/src/example/reply.d.ts +1 -1
- package/dist/types/src/example/sleep.d.ts +1 -1
- package/dist/types/src/index.d.ts +2 -5
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/operation-compatibility.test.d.ts +2 -0
- package/dist/types/src/operation-compatibility.test.d.ts.map +1 -0
- 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/index.d.ts +2 -0
- package/dist/types/src/protocol/index.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +7 -0
- package/dist/types/src/protocol/protocol.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.test.d.ts +2 -0
- package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
- package/dist/types/src/sdk.d.ts +114 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +6 -4
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +33 -27
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +7 -19
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
- package/dist/types/src/services/index.d.ts +2 -4
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +4 -4
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +41 -12
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Function.d.ts +40 -35
- package/dist/types/src/types/Function.d.ts.map +1 -1
- package/dist/types/src/types/Script.d.ts +9 -16
- package/dist/types/src/types/Script.d.ts.map +1 -1
- package/dist/types/src/types/Trigger.d.ts +58 -76
- package/dist/types/src/types/Trigger.d.ts.map +1 -1
- package/dist/types/src/types/TriggerEvent.d.ts +43 -13
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
- 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/url.d.ts +13 -0
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -58
- package/src/errors.ts +4 -4
- package/src/example/fib.ts +1 -1
- package/src/example/reply.ts +1 -1
- package/src/example/sleep.ts +1 -1
- package/src/index.ts +2 -5
- package/src/operation-compatibility.test.ts +185 -0
- package/src/protocol/functions-ai-http-client.ts +67 -0
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +59 -0
- package/src/protocol/protocol.ts +262 -0
- package/src/{handler.ts → sdk.ts} +129 -66
- package/src/services/credentials.ts +32 -17
- package/src/services/event-logger.ts +10 -4
- package/src/services/function-invocation-service.ts +23 -70
- package/src/services/index.ts +2 -4
- package/src/services/queues.ts +5 -7
- package/src/services/tracing.ts +68 -44
- package/src/types/Function.ts +39 -8
- package/src/types/Script.ts +10 -9
- package/src/types/Trigger.ts +18 -14
- package/src/types/TriggerEvent.ts +29 -29
- package/src/types/index.ts +1 -0
- package/src/types/url.ts +32 -0
- package/dist/lib/browser/bundler/index.mjs +0 -256
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +0 -10
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +0 -7
- package/dist/lib/browser/chunk-M6EXIREF.mjs +0 -610
- package/dist/lib/browser/chunk-M6EXIREF.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -83
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -131
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -257
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-P3IATZMZ.mjs +0 -612
- package/dist/lib/node-esm/chunk-P3IATZMZ.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -84
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -132
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -49
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/e2e/deploy.test.d.ts +0 -2
- package/dist/types/src/e2e/deploy.test.d.ts.map +0 -1
- package/dist/types/src/edge/functions.d.ts +0 -17
- package/dist/types/src/edge/functions.d.ts.map +0 -1
- package/dist/types/src/edge/index.d.ts +0 -2
- package/dist/types/src/edge/index.d.ts.map +0 -1
- package/dist/types/src/executor/executor.d.ts +0 -14
- package/dist/types/src/executor/executor.d.ts.map +0 -1
- package/dist/types/src/executor/index.d.ts +0 -2
- package/dist/types/src/executor/index.d.ts.map +0 -1
- package/dist/types/src/handler.d.ts +0 -102
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -67
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/function-invocation-service.test.d.ts +0 -2
- package/dist/types/src/services/function-invocation-service.test.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -34
- package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
- package/dist/types/src/services/remote-function-execution-service.d.ts +0 -22
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -57
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.d.ts +0 -31
- package/dist/types/src/services/service-registry.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.test.d.ts +0 -2
- package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -18
- package/dist/types/src/testing/layer.d.ts.map +0 -1
- package/dist/types/src/testing/logger.d.ts +0 -5
- package/dist/types/src/testing/logger.d.ts.map +0 -1
- package/dist/types/src/testing/persist-database.test.d.ts +0 -2
- package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
- package/dist/types/src/testing/services.d.ts +0 -59
- package/dist/types/src/testing/services.d.ts.map +0 -1
- package/dist/types/src/trace.d.ts +0 -122
- package/dist/types/src/trace.d.ts.map +0 -1
- package/dist/types/src/translations.d.ts +0 -12
- package/dist/types/src/translations.d.ts.map +0 -1
- package/dist/types/src/triggers/index.d.ts +0 -4
- package/dist/types/src/triggers/index.d.ts.map +0 -1
- package/dist/types/src/triggers/input-builder.d.ts +0 -3
- package/dist/types/src/triggers/input-builder.d.ts.map +0 -1
- package/dist/types/src/triggers/invocation-tracer.d.ts +0 -37
- package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -78
- package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +0 -2
- package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +0 -1
- package/dist/types/src/triggers/trigger-state-store.d.ts +0 -28
- package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
- package/dist/types/src/url.d.ts +0 -21
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -58
- package/src/bundler/bundler.ts +0 -295
- package/src/bundler/index.ts +0 -5
- package/src/e2e/deploy.test.ts +0 -69
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/executor/executor.ts +0 -58
- package/src/services/database.ts +0 -175
- package/src/services/function-invocation-service.test.ts +0 -81
- package/src/services/local-function-execution.ts +0 -153
- package/src/services/remote-function-execution-service.ts +0 -63
- package/src/services/service-container.ts +0 -115
- package/src/services/service-registry.test.ts +0 -45
- package/src/services/service-registry.ts +0 -63
- package/src/testing/index.ts +0 -6
- package/src/testing/layer.ts +0 -114
- package/src/testing/logger.ts +0 -17
- package/src/testing/persist-database.test.ts +0 -87
- package/src/testing/services.ts +0 -115
- package/src/trace.ts +0 -178
- package/src/translations.ts +0 -20
- package/src/triggers/index.ts +0 -7
- package/src/triggers/input-builder.ts +0 -35
- package/src/triggers/invocation-tracer.ts +0 -101
- package/src/triggers/trigger-dispatcher.test.ts +0 -664
- package/src/triggers/trigger-dispatcher.ts +0 -521
- package/src/triggers/trigger-state-store.ts +0 -61
- package/src/url.ts +0 -55
|
@@ -1,63 +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 Function from 'effect/Function';
|
|
8
|
-
import type * as Option from 'effect/Option';
|
|
9
|
-
|
|
10
|
-
import { ServiceNotAvailableError } from '../errors';
|
|
11
|
-
|
|
12
|
-
export namespace ServiceRegistry {
|
|
13
|
-
export interface Service {
|
|
14
|
-
resolve: <T extends Context.Tag<any, any>>(tag: T) => Option.Option<Context.Tag.Service<T>>;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export class ServiceRegistry extends Context.Tag('@dxos/functions/ServiceRegistry')<
|
|
19
|
-
ServiceRegistry,
|
|
20
|
-
ServiceRegistry.Service
|
|
21
|
-
>() {
|
|
22
|
-
/**
|
|
23
|
-
* Resolves the service from the registry.
|
|
24
|
-
* @param tag Service tag to resolve.
|
|
25
|
-
* @throws {@link ServiceNotAvailableError} if the service is not found.
|
|
26
|
-
* @returns Effect that resolve to the service.
|
|
27
|
-
*/
|
|
28
|
-
static resolve: <T extends Context.Tag<any, any>>(
|
|
29
|
-
tag: T,
|
|
30
|
-
) => Effect.Effect<T, ServiceNotAvailableError, ServiceRegistry> = (tag) =>
|
|
31
|
-
ServiceRegistry.pipe(
|
|
32
|
-
Effect.flatMap((_) => _.resolve(tag)),
|
|
33
|
-
Effect.mapError(() => new ServiceNotAvailableError(tag.key)),
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
static provide: {
|
|
37
|
-
<Tags extends [Context.Tag<any, any>, ...Context.Tag<any, any>[]]>(
|
|
38
|
-
...tags: Tags
|
|
39
|
-
): <A, E, R>(
|
|
40
|
-
effect: Effect.Effect<A, E, R>,
|
|
41
|
-
) => Effect.Effect<
|
|
42
|
-
A,
|
|
43
|
-
E | ServiceNotAvailableError,
|
|
44
|
-
Exclude<R, { [K in keyof Tags]: Context.Tag.Identifier<Tags[K]> }[number]> | ServiceRegistry
|
|
45
|
-
>;
|
|
46
|
-
} = (...tags) =>
|
|
47
|
-
(Function.flow as any)(...tags.map((tag) => Effect.provideServiceEffect(tag, ServiceRegistry.resolve(tag))));
|
|
48
|
-
|
|
49
|
-
static provideOrDie: {
|
|
50
|
-
<Tags extends [Context.Tag<any, any>, ...Context.Tag<any, any>[]]>(
|
|
51
|
-
...tags: Tags
|
|
52
|
-
): <A, E, R>(
|
|
53
|
-
effect: Effect.Effect<A, E, R>,
|
|
54
|
-
) => Effect.Effect<
|
|
55
|
-
A,
|
|
56
|
-
E,
|
|
57
|
-
Exclude<R, { [K in keyof Tags]: Context.Tag.Identifier<Tags[K]> }[number]> | ServiceRegistry
|
|
58
|
-
>;
|
|
59
|
-
} = (...tags) =>
|
|
60
|
-
(Function.flow as any)(
|
|
61
|
-
...tags.map((tag) => Effect.provideServiceEffect(tag, ServiceRegistry.resolve(tag).pipe(Effect.orDie))),
|
|
62
|
-
);
|
|
63
|
-
}
|
package/src/testing/index.ts
DELETED
package/src/testing/layer.ts
DELETED
|
@@ -1,114 +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 type * as Schema from 'effect/Schema';
|
|
9
|
-
|
|
10
|
-
import type { EchoDatabaseImpl, QueueFactory } from '@dxos/echo-db';
|
|
11
|
-
import { EchoTestBuilder } from '@dxos/echo-db/testing';
|
|
12
|
-
import type { EchoHostIndexingConfig } from '@dxos/echo-pipeline';
|
|
13
|
-
import { acquireReleaseResource } from '@dxos/effect';
|
|
14
|
-
import { PublicKey } from '@dxos/keys';
|
|
15
|
-
import type { LevelDB } from '@dxos/kv-store';
|
|
16
|
-
import { createTestLevel } from '@dxos/kv-store/testing';
|
|
17
|
-
import { log } from '@dxos/log';
|
|
18
|
-
|
|
19
|
-
import { DatabaseService, QueueService } from '../services';
|
|
20
|
-
|
|
21
|
-
const testBuilder = acquireReleaseResource(() => new EchoTestBuilder());
|
|
22
|
-
|
|
23
|
-
export const testStoragePath = ({ name = PublicKey.random().toHex() }: { name?: string }) => {
|
|
24
|
-
return `/tmp/dxos-${name}`;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export type TestDatabaseOptions = {
|
|
28
|
-
indexing?: Partial<EchoHostIndexingConfig>;
|
|
29
|
-
types?: Schema.Schema.AnyNoContext[];
|
|
30
|
-
spaceKey?: PublicKey;
|
|
31
|
-
storagePath?: string;
|
|
32
|
-
onInit?: () => Effect.Effect<void, never, DatabaseService | QueueService>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const TestDatabaseLayer = ({ indexing, types, spaceKey, storagePath, onInit }: TestDatabaseOptions = {}) =>
|
|
36
|
-
Layer.scopedContext(
|
|
37
|
-
Effect.gen(function* () {
|
|
38
|
-
const builder = yield* testBuilder;
|
|
39
|
-
|
|
40
|
-
let kv: LevelDB | undefined;
|
|
41
|
-
if (storagePath) {
|
|
42
|
-
kv = createTestLevel(storagePath);
|
|
43
|
-
yield* Effect.promise(() => kv!.open());
|
|
44
|
-
// const keyCount = yield* Effect.promise(async () => (await kv!.iterator({ values: false }).all()).length);
|
|
45
|
-
// log.info('opened test db', { storagePath, keyCount });
|
|
46
|
-
}
|
|
47
|
-
const peer = yield* Effect.promise(() => builder.createPeer({ indexing, types, kv }));
|
|
48
|
-
|
|
49
|
-
let db: EchoDatabaseImpl | undefined;
|
|
50
|
-
let queues: QueueFactory | undefined;
|
|
51
|
-
|
|
52
|
-
if (storagePath) {
|
|
53
|
-
const testMetadata = yield* Effect.promise(async () => {
|
|
54
|
-
try {
|
|
55
|
-
return await kv!.get('test-metadata', { valueEncoding: 'json' });
|
|
56
|
-
} catch (e) {
|
|
57
|
-
if ((e as any).code === 'LEVEL_NOT_FOUND') {
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
throw e;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
log('starting persistant test db', { storagePath, testMetadata });
|
|
64
|
-
if (!testMetadata) {
|
|
65
|
-
const key = spaceKey ?? PublicKey.random();
|
|
66
|
-
db = yield* Effect.promise(() => peer.createDatabase(key));
|
|
67
|
-
queues = peer.client.constructQueueFactory(db.spaceId);
|
|
68
|
-
|
|
69
|
-
yield* Effect.promise(() =>
|
|
70
|
-
kv!.put('test-metadata', { key: key.toHex(), rootUrl: db!.rootUrl }, { valueEncoding: 'json' }),
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
if (onInit) {
|
|
74
|
-
yield* onInit().pipe(
|
|
75
|
-
Effect.provideService(DatabaseService, DatabaseService.make(db)),
|
|
76
|
-
Effect.provideService(QueueService, QueueService.make(queues, undefined)),
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
const key = PublicKey.from((testMetadata as any).key);
|
|
81
|
-
const rootUrl = (testMetadata as any).rootUrl;
|
|
82
|
-
db = yield* Effect.promise(() => peer.openDatabase(key, rootUrl));
|
|
83
|
-
queues = peer.client.constructQueueFactory(db.spaceId);
|
|
84
|
-
}
|
|
85
|
-
} else {
|
|
86
|
-
db = yield* Effect.promise(() => peer.createDatabase(spaceKey));
|
|
87
|
-
queues = peer.client.constructQueueFactory(db.spaceId);
|
|
88
|
-
if (onInit) {
|
|
89
|
-
yield* onInit().pipe(
|
|
90
|
-
Effect.provideService(DatabaseService, DatabaseService.make(db)),
|
|
91
|
-
Effect.provideService(QueueService, QueueService.make(queues, undefined)),
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
yield* Effect.addFinalizer(() =>
|
|
97
|
-
Effect.promise(async () => {
|
|
98
|
-
if (kv) {
|
|
99
|
-
// {
|
|
100
|
-
// const keyCount = (await kv.iterator({ values: false }).all()).length;
|
|
101
|
-
// log.info('closing persistant test db', { storagePath, keyCount });
|
|
102
|
-
// }
|
|
103
|
-
|
|
104
|
-
await kv.close();
|
|
105
|
-
}
|
|
106
|
-
}),
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
return Context.mergeAll(
|
|
110
|
-
Context.make(DatabaseService, DatabaseService.make(db)),
|
|
111
|
-
Context.make(QueueService, QueueService.make(queues, undefined)),
|
|
112
|
-
);
|
|
113
|
-
}),
|
|
114
|
-
);
|
package/src/testing/logger.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as Context from 'effect/Context';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
|
|
8
|
-
import { LogLevel } from '@dxos/log';
|
|
9
|
-
|
|
10
|
-
import { type ComputeEventLogger, createEventLogger } from '../services';
|
|
11
|
-
|
|
12
|
-
export const noopLogger: Context.Tag.Service<ComputeEventLogger> = {
|
|
13
|
-
log: () => Effect.succeed(undefined),
|
|
14
|
-
nodeId: undefined,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const consoleLogger: Context.Tag.Service<ComputeEventLogger> = createEventLogger(LogLevel.INFO);
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it } from '@effect/vitest';
|
|
6
|
-
import * as Effect from 'effect/Effect';
|
|
7
|
-
|
|
8
|
-
import { Filter, Obj, Query, Type } from '@dxos/echo';
|
|
9
|
-
import { DataType } from '@dxos/schema';
|
|
10
|
-
|
|
11
|
-
import { DatabaseService } from '../services';
|
|
12
|
-
|
|
13
|
-
import { TestDatabaseLayer, testStoragePath } from './layer';
|
|
14
|
-
|
|
15
|
-
describe('TestDatabaseLayer', { timeout: 600_000 }, () => {
|
|
16
|
-
it.effect(
|
|
17
|
-
'persist database to disk',
|
|
18
|
-
Effect.fnUntraced(function* (_) {
|
|
19
|
-
const DbLayer = TestDatabaseLayer({
|
|
20
|
-
storagePath: testStoragePath({ name: `feed-test-${Date.now()}` }),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
yield* Effect.gen(function* () {
|
|
24
|
-
yield* DatabaseService.add(Obj.make(Type.Expando, { label: 'test' }));
|
|
25
|
-
yield* DatabaseService.flush({ indexes: true });
|
|
26
|
-
}).pipe(Effect.provide(DbLayer));
|
|
27
|
-
|
|
28
|
-
yield* Effect.gen(function* () {
|
|
29
|
-
const { objects } = yield* DatabaseService.runQuery(Query.select(Filter.everything()));
|
|
30
|
-
expect(objects[0]?.label).toEqual('test');
|
|
31
|
-
}).pipe(Effect.provide(DbLayer));
|
|
32
|
-
}),
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
it.effect(
|
|
36
|
-
'reload database -- save index before restart',
|
|
37
|
-
Effect.fnUntraced(function* (_) {
|
|
38
|
-
const NUM_OBJECTS = 500;
|
|
39
|
-
const DbLayer = TestDatabaseLayer({
|
|
40
|
-
types: [DataType.Person],
|
|
41
|
-
storagePath: testStoragePath({ name: `reload-test-${Date.now()}` }),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
yield* Effect.gen(function* () {
|
|
45
|
-
for (let i = 0; i < NUM_OBJECTS; i++) {
|
|
46
|
-
yield* DatabaseService.add(Obj.make(DataType.Person, { nickname: `Person ${i}` }));
|
|
47
|
-
}
|
|
48
|
-
yield* DatabaseService.flush({ indexes: true });
|
|
49
|
-
}).pipe(Effect.provide(DbLayer));
|
|
50
|
-
|
|
51
|
-
yield* Effect.gen(function* () {
|
|
52
|
-
const { objects } = yield* DatabaseService.runQuery(Query.select(Filter.type(DataType.Person)));
|
|
53
|
-
expect(objects.length).toEqual(NUM_OBJECTS);
|
|
54
|
-
}).pipe(Effect.provide(DbLayer));
|
|
55
|
-
}),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
it.effect.skip(
|
|
59
|
-
'reload database -- save index before restart [manual]',
|
|
60
|
-
Effect.fnUntraced(
|
|
61
|
-
function* (_) {
|
|
62
|
-
const NUM_OBJECTS = 500;
|
|
63
|
-
|
|
64
|
-
{
|
|
65
|
-
const { objects } = yield* DatabaseService.runQuery(Query.select(Filter.type(DataType.Person)));
|
|
66
|
-
console.log({ count: objects.length });
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < NUM_OBJECTS; i++) {
|
|
70
|
-
yield* DatabaseService.add(Obj.make(DataType.Person, { nickname: `Person ${i}` }));
|
|
71
|
-
}
|
|
72
|
-
yield* DatabaseService.flush({ indexes: true });
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
const { objects } = yield* DatabaseService.runQuery(Query.select(Filter.type(DataType.Person)));
|
|
76
|
-
console.log({ count: objects.length });
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
Effect.provide(
|
|
80
|
-
TestDatabaseLayer({
|
|
81
|
-
types: [DataType.Person],
|
|
82
|
-
storagePath: testStoragePath({ name: `reload-test` }),
|
|
83
|
-
}),
|
|
84
|
-
),
|
|
85
|
-
),
|
|
86
|
-
);
|
|
87
|
-
});
|
package/src/testing/services.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as Context from 'effect/Context';
|
|
6
|
-
|
|
7
|
-
import type { Space } from '@dxos/client/echo';
|
|
8
|
-
import type { EchoDatabase, QueueFactory } from '@dxos/echo-db';
|
|
9
|
-
import { assertArgument } from '@dxos/invariant';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
type ComputeEventLogger,
|
|
13
|
-
ConfiguredCredentialsService,
|
|
14
|
-
type CredentialsService,
|
|
15
|
-
DatabaseService,
|
|
16
|
-
QueueService,
|
|
17
|
-
ServiceContainer,
|
|
18
|
-
type ServiceCredential,
|
|
19
|
-
type TracingService,
|
|
20
|
-
} from '../services';
|
|
21
|
-
|
|
22
|
-
import { consoleLogger, noopLogger } from './logger';
|
|
23
|
-
|
|
24
|
-
// TODO(burdon): Factor out.
|
|
25
|
-
export type OneOf<T> = {
|
|
26
|
-
[K in keyof T]: { [P in K]: T[P] } & { [P in Exclude<keyof T, K>]?: never };
|
|
27
|
-
}[keyof T];
|
|
28
|
-
|
|
29
|
-
export type AiServiceProvider = 'dev' | 'edge' | 'ollama' | 'lmstudio';
|
|
30
|
-
|
|
31
|
-
export type TestServiceOptions = {
|
|
32
|
-
/**
|
|
33
|
-
* AI service configuration.
|
|
34
|
-
*/
|
|
35
|
-
ai?: any;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Credentials service configuration.
|
|
39
|
-
*/
|
|
40
|
-
credentials?: OneOf<{
|
|
41
|
-
/**
|
|
42
|
-
* Predefined credentials list.
|
|
43
|
-
*/
|
|
44
|
-
services?: ServiceCredential[];
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Custom credentials service.
|
|
48
|
-
*/
|
|
49
|
-
service?: Context.Tag.Service<CredentialsService>;
|
|
50
|
-
}>;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Database configuration.
|
|
54
|
-
*/
|
|
55
|
-
db?: EchoDatabase;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Gets database and queue services from the space.
|
|
59
|
-
* Exclusive with: `db`, `queues`
|
|
60
|
-
*/
|
|
61
|
-
space?: Space;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Logging configuration.
|
|
65
|
-
*/
|
|
66
|
-
logging?: {
|
|
67
|
-
enabled?: boolean;
|
|
68
|
-
logger?: Context.Tag.Service<ComputeEventLogger>;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Queue service configuration.
|
|
73
|
-
*/
|
|
74
|
-
queues?: QueueFactory;
|
|
75
|
-
|
|
76
|
-
tracing?: {
|
|
77
|
-
service?: Context.Tag.Service<TracingService>;
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @deprecated
|
|
83
|
-
*/
|
|
84
|
-
export const createTestServices = ({
|
|
85
|
-
ai,
|
|
86
|
-
credentials,
|
|
87
|
-
db,
|
|
88
|
-
logging,
|
|
89
|
-
queues,
|
|
90
|
-
space,
|
|
91
|
-
tracing,
|
|
92
|
-
}: TestServiceOptions = {}): ServiceContainer => {
|
|
93
|
-
assertArgument(!(!!space && (!!db || !!queues)), 'space', 'space can be provided only if db and queues are not');
|
|
94
|
-
|
|
95
|
-
return new ServiceContainer().setServices({
|
|
96
|
-
// ai: createAiService(ai),
|
|
97
|
-
credentials: createCredentialsService(credentials),
|
|
98
|
-
database: space || db ? DatabaseService.make(space?.db || db!) : undefined,
|
|
99
|
-
eventLogger: (logging?.logger ?? logging?.enabled) ? consoleLogger : noopLogger,
|
|
100
|
-
queues: space || queues ? QueueService.make(space?.queues || queues!, undefined) : undefined,
|
|
101
|
-
tracing: tracing?.service,
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const createCredentialsService = (
|
|
106
|
-
credentials: TestServiceOptions['credentials'] | undefined,
|
|
107
|
-
): Context.Tag.Service<CredentialsService> | undefined => {
|
|
108
|
-
if (credentials?.services) {
|
|
109
|
-
return new ConfiguredCredentialsService(credentials.services);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (credentials?.service) {
|
|
113
|
-
return credentials.service;
|
|
114
|
-
}
|
|
115
|
-
};
|
package/src/trace.ts
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as Schema from 'effect/Schema';
|
|
6
|
-
|
|
7
|
-
import { type Ref, Type } from '@dxos/echo';
|
|
8
|
-
import { ObjectId } from '@dxos/echo/internal';
|
|
9
|
-
import { Queue } from '@dxos/echo-db';
|
|
10
|
-
import { log } from '@dxos/log';
|
|
11
|
-
|
|
12
|
-
import { Trigger } from './types';
|
|
13
|
-
|
|
14
|
-
export enum InvocationOutcome {
|
|
15
|
-
SUCCESS = 'success',
|
|
16
|
-
FAILURE = 'failure',
|
|
17
|
-
PENDING = 'pending',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// TODO(burdon): Convert to extensible discriminated union of EDGE events.
|
|
21
|
-
export enum InvocationTraceEventType {
|
|
22
|
-
START = 'start',
|
|
23
|
-
END = 'end',
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const TraceEventException = Schema.Struct({
|
|
27
|
-
timestamp: Schema.Number,
|
|
28
|
-
message: Schema.String,
|
|
29
|
-
name: Schema.String,
|
|
30
|
-
stack: Schema.optional(Schema.String),
|
|
31
|
-
});
|
|
32
|
-
export type TraceEventException = Schema.Schema.Type<typeof TraceEventException>;
|
|
33
|
-
|
|
34
|
-
export const InvocationTraceStartEvent = Schema.Struct({
|
|
35
|
-
/**
|
|
36
|
-
* Queue message id.
|
|
37
|
-
*/
|
|
38
|
-
id: ObjectId,
|
|
39
|
-
type: Schema.Literal(InvocationTraceEventType.START),
|
|
40
|
-
/**
|
|
41
|
-
* Invocation id, the same for invocation start and end events.
|
|
42
|
-
*/
|
|
43
|
-
invocationId: ObjectId,
|
|
44
|
-
/**
|
|
45
|
-
* Event generation time.
|
|
46
|
-
*/
|
|
47
|
-
timestamp: Schema.Number,
|
|
48
|
-
/**
|
|
49
|
-
* Data passed to function / workflow as an argument.
|
|
50
|
-
*/
|
|
51
|
-
// TODO(burdon): Input schema?
|
|
52
|
-
input: Schema.Object,
|
|
53
|
-
/**
|
|
54
|
-
* Queue for function/workflow invocation events.
|
|
55
|
-
*/
|
|
56
|
-
invocationTraceQueue: Schema.optional(Type.Ref(Queue)),
|
|
57
|
-
/**
|
|
58
|
-
* DXN of the invoked function/workflow.
|
|
59
|
-
*/
|
|
60
|
-
invocationTarget: Schema.optional(Type.Ref(Type.Expando)),
|
|
61
|
-
/**
|
|
62
|
-
* Present for automatic invocations.
|
|
63
|
-
*/
|
|
64
|
-
trigger: Schema.optional(Type.Ref(Trigger.Trigger)),
|
|
65
|
-
}).pipe(Type.Obj({ typename: 'dxos.org/type/InvocationTraceStart', version: '0.1.0' }));
|
|
66
|
-
|
|
67
|
-
export type InvocationTraceStartEvent = Schema.Schema.Type<typeof InvocationTraceStartEvent>;
|
|
68
|
-
|
|
69
|
-
export const InvocationTraceEndEvent = Schema.Struct({
|
|
70
|
-
/**
|
|
71
|
-
* Trace event id.
|
|
72
|
-
*/
|
|
73
|
-
id: ObjectId,
|
|
74
|
-
type: Schema.Literal(InvocationTraceEventType.END),
|
|
75
|
-
/**
|
|
76
|
-
* Invocation id, will be the same for invocation start and end.
|
|
77
|
-
*/
|
|
78
|
-
invocationId: ObjectId,
|
|
79
|
-
/**
|
|
80
|
-
* Event generation time.
|
|
81
|
-
*/
|
|
82
|
-
// TODO(burdon): Remove ms suffix.
|
|
83
|
-
timestamp: Schema.Number,
|
|
84
|
-
outcome: Schema.Enums(InvocationOutcome),
|
|
85
|
-
exception: Schema.optional(TraceEventException),
|
|
86
|
-
}).pipe(Type.Obj({ typename: 'dxos.org/type/InvocationTraceEnd', version: '0.1.0' }));
|
|
87
|
-
|
|
88
|
-
export type InvocationTraceEndEvent = Schema.Schema.Type<typeof InvocationTraceEndEvent>;
|
|
89
|
-
|
|
90
|
-
export type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;
|
|
91
|
-
|
|
92
|
-
export const TraceEventLog = Schema.Struct({
|
|
93
|
-
timestamp: Schema.Number,
|
|
94
|
-
level: Schema.String,
|
|
95
|
-
message: Schema.String,
|
|
96
|
-
context: Schema.optional(Schema.Object),
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
export const TraceEvent = Schema.Struct({
|
|
100
|
-
id: ObjectId,
|
|
101
|
-
// TODO(burdon): Need enum/numeric result (not string).
|
|
102
|
-
outcome: Schema.String,
|
|
103
|
-
truncated: Schema.Boolean,
|
|
104
|
-
/** Time when the event was persisted. */
|
|
105
|
-
ingestionTimestamp: Schema.Number,
|
|
106
|
-
logs: Schema.Array(TraceEventLog),
|
|
107
|
-
exceptions: Schema.Array(TraceEventException),
|
|
108
|
-
}).pipe(Type.Obj({ typename: 'dxos.org/type/TraceEvent', version: '0.1.0' }));
|
|
109
|
-
|
|
110
|
-
export type TraceEvent = Schema.Schema.Type<typeof TraceEvent>;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* InvocationTrace event format.
|
|
114
|
-
* This is the combined format of InvocationTraceStartEvent and InvocationTraceEndEvents for UI consumption.
|
|
115
|
-
*/
|
|
116
|
-
export type InvocationSpan = {
|
|
117
|
-
id: string;
|
|
118
|
-
timestamp: number;
|
|
119
|
-
duration: number;
|
|
120
|
-
outcome: InvocationOutcome;
|
|
121
|
-
input: object;
|
|
122
|
-
invocationTraceQueue?: Ref.Ref<Queue>;
|
|
123
|
-
invocationTarget?: Ref.Ref<Type.Expando>;
|
|
124
|
-
trigger?: Ref.Ref<Trigger.Trigger>;
|
|
125
|
-
exception?: TraceEventException;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {
|
|
129
|
-
if (!items) {
|
|
130
|
-
return [];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const eventsByInvocationId = new Map<string, { start?: InvocationTraceStartEvent; end?: InvocationTraceEndEvent }>();
|
|
134
|
-
for (const event of items) {
|
|
135
|
-
if (!('invocationId' in event)) {
|
|
136
|
-
// Skip legacy format entries.
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const invocationId = event.invocationId;
|
|
141
|
-
const entry = eventsByInvocationId.get(invocationId) || { start: undefined, end: undefined };
|
|
142
|
-
if (event.type === InvocationTraceEventType.START) {
|
|
143
|
-
entry.start = event as InvocationTraceStartEvent;
|
|
144
|
-
} else if (event.type === InvocationTraceEventType.END) {
|
|
145
|
-
entry.end = event as InvocationTraceEndEvent;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
eventsByInvocationId.set(invocationId, entry);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const now = Date.now();
|
|
152
|
-
const result: InvocationSpan[] = [];
|
|
153
|
-
|
|
154
|
-
// Create spans for each invocation
|
|
155
|
-
for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
|
|
156
|
-
if (!start) {
|
|
157
|
-
// No start event, can't create a meaningful span
|
|
158
|
-
log.warn('found end event without matching start', { invocationId });
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const isInProgress = end === undefined;
|
|
163
|
-
|
|
164
|
-
result.push({
|
|
165
|
-
id: invocationId,
|
|
166
|
-
timestamp: start.timestamp,
|
|
167
|
-
duration: isInProgress ? now - start.timestamp : end!.timestamp - start.timestamp,
|
|
168
|
-
outcome: end?.outcome ?? InvocationOutcome.PENDING,
|
|
169
|
-
exception: end?.exception,
|
|
170
|
-
input: start.input,
|
|
171
|
-
invocationTraceQueue: start.invocationTraceQueue,
|
|
172
|
-
invocationTarget: start.invocationTarget,
|
|
173
|
-
trigger: start.trigger,
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return result;
|
|
178
|
-
};
|
package/src/translations.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Resource } from 'i18next';
|
|
6
|
-
|
|
7
|
-
import { Script } from './types';
|
|
8
|
-
|
|
9
|
-
export const translations = [
|
|
10
|
-
{
|
|
11
|
-
'en-US': {
|
|
12
|
-
[Script.Script.typename]: {
|
|
13
|
-
'typename label': 'Script',
|
|
14
|
-
'typename label_zero': 'Scripts',
|
|
15
|
-
'typename label_one': 'Script',
|
|
16
|
-
'typename label_other': 'Scripts',
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
] as const satisfies Resource[];
|
package/src/triggers/index.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Trigger, type TriggerEvent } from '../types';
|
|
6
|
-
|
|
7
|
-
export const createInvocationPayload = (trigger: Trigger.Trigger, event: TriggerEvent.TriggerEvent): any => {
|
|
8
|
-
if (!trigger.input) {
|
|
9
|
-
return event;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const payload: any = {};
|
|
13
|
-
for (const [key, value] of Object.entries(trigger.input)) {
|
|
14
|
-
if (typeof value !== 'string' || !(value.startsWith('{{') && value.endsWith('}}'))) {
|
|
15
|
-
payload[key] = value;
|
|
16
|
-
continue;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const propertyPath = value.slice(2, -2);
|
|
20
|
-
let valueSubstitution: any = propertyPath.startsWith('trigger.')
|
|
21
|
-
? trigger
|
|
22
|
-
: propertyPath.startsWith('event.')
|
|
23
|
-
? event
|
|
24
|
-
: undefined;
|
|
25
|
-
|
|
26
|
-
for (const pathSegment of propertyPath.split('.').slice(1)) {
|
|
27
|
-
if (valueSubstitution && typeof valueSubstitution === 'object') {
|
|
28
|
-
valueSubstitution = valueSubstitution[pathSegment];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
payload[key] = valueSubstitution;
|
|
33
|
-
}
|
|
34
|
-
return payload;
|
|
35
|
-
};
|