@dxos/functions 0.8.4-main.ead640a → 0.8.4-main.ef1bc66f44
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/neutral/index.mjs +1229 -0
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/errors.d.ts +44 -60
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/{examples → example}/fib.d.ts +1 -1
- package/dist/types/src/example/fib.d.ts.map +1 -0
- package/dist/types/src/example/forex-effect.d.ts +3 -0
- package/dist/types/src/example/forex-effect.d.ts.map +1 -0
- package/dist/types/src/example/index.d.ts +12 -0
- package/dist/types/src/example/index.d.ts.map +1 -0
- package/dist/types/src/{examples → example}/reply.d.ts +1 -1
- package/dist/types/src/example/reply.d.ts.map +1 -0
- package/dist/types/src/{examples → example}/sleep.d.ts +1 -1
- package/dist/types/src/example/sleep.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -8
- 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 +52 -0
- package/dist/types/src/types/Function.d.ts.map +1 -0
- package/dist/types/src/types/Script.d.ts +21 -0
- package/dist/types/src/types/Script.d.ts.map +1 -0
- package/dist/types/src/types/Trigger.d.ts +121 -0
- package/dist/types/src/types/Trigger.d.ts.map +1 -0
- package/dist/types/src/types/TriggerEvent.d.ts +74 -0
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +6 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- 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 +24 -63
- package/src/errors.ts +4 -4
- package/src/{examples → example}/fib.ts +1 -1
- package/src/example/forex-effect.ts +40 -0
- package/src/example/index.ts +13 -0
- package/src/{examples → example}/reply.ts +1 -1
- package/src/{examples → example}/sleep.ts +1 -1
- package/src/index.ts +4 -8
- 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/sdk.ts +289 -0
- 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 +82 -0
- package/src/types/Script.ts +34 -0
- package/src/types/Trigger.ts +143 -0
- package/src/types/TriggerEvent.ts +62 -0
- package/src/types/index.ts +9 -0
- package/src/types/url.ts +32 -0
- package/dist/lib/browser/bundler/index.mjs +0 -269
- 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-LKYT2SAL.mjs +0 -665
- package/dist/lib/browser/chunk-LKYT2SAL.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/index.mjs +0 -1395
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- 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 -270
- 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-NAQIKLZB.mjs +0 -667
- package/dist/lib/node-esm/chunk-NAQIKLZB.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/index.mjs +0 -1396
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- 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/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/examples/fib.d.ts.map +0 -1
- package/dist/types/src/examples/index.d.ts +0 -4
- package/dist/types/src/examples/index.d.ts.map +0 -1
- package/dist/types/src/examples/reply.d.ts.map +0 -1
- package/dist/types/src/examples/sleep.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 -109
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/schema.d.ts +0 -43
- package/dist/types/src/schema.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/types.d.ts +0 -230
- package/dist/types/src/types.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/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/examples/index.ts +0 -7
- package/src/executor/executor.ts +0 -58
- package/src/handler.ts +0 -225
- package/src/schema.ts +0 -71
- 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 -665
- package/src/triggers/trigger-dispatcher.ts +0 -533
- package/src/triggers/trigger-state-store.ts +0 -61
- package/src/types.ts +0 -218
- package/src/url.ts +0 -55
|
@@ -1,153 +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 { AiService } from '@dxos/ai';
|
|
11
|
-
import { todo } from '@dxos/debug';
|
|
12
|
-
import { log } from '@dxos/log';
|
|
13
|
-
|
|
14
|
-
import { FunctionError, FunctionNotFoundError } from '../errors';
|
|
15
|
-
import type { FunctionContext, FunctionDefinition } from '../handler';
|
|
16
|
-
|
|
17
|
-
import { CredentialsService } from './credentials';
|
|
18
|
-
import { DatabaseService } from './database';
|
|
19
|
-
import { type ComputeEventLogger } from './event-logger';
|
|
20
|
-
import { QueueService } from './queues';
|
|
21
|
-
import { RemoteFunctionExecutionService } from './remote-function-execution-service';
|
|
22
|
-
import { type Services } from './service-container';
|
|
23
|
-
import { type TracingService } from './tracing';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Services that are provided at the function call site.
|
|
27
|
-
*/
|
|
28
|
-
export type InvocationServices = TracingService | ComputeEventLogger;
|
|
29
|
-
|
|
30
|
-
export class LocalFunctionExecutionService extends Context.Tag('@dxos/functions/LocalFunctionExecutionService')<
|
|
31
|
-
LocalFunctionExecutionService,
|
|
32
|
-
{
|
|
33
|
-
// TODO(dmaretskyi): This should take function id instead of the definition object.
|
|
34
|
-
// TODO(dmaretskyi): Services should be satisfied from environment rather then bubbled up.
|
|
35
|
-
invokeFunction<I, O>(functionDef: FunctionDefinition<I, O>, input: I): Effect.Effect<O, never, InvocationServices>;
|
|
36
|
-
}
|
|
37
|
-
>() {
|
|
38
|
-
static layerLive = Layer.effect(
|
|
39
|
-
LocalFunctionExecutionService,
|
|
40
|
-
Effect.gen(function* () {
|
|
41
|
-
// TODO(dmaretskyi): Use `yield* Effect.context()`;
|
|
42
|
-
const resolver = yield* FunctionImplementationResolver;
|
|
43
|
-
const ai = yield* AiService.AiService;
|
|
44
|
-
const credentials = yield* CredentialsService;
|
|
45
|
-
const database = yield* DatabaseService;
|
|
46
|
-
const queues = yield* QueueService;
|
|
47
|
-
// TODO(mykola): Delete, should not be required for local execution.
|
|
48
|
-
const functionCallService = yield* RemoteFunctionExecutionService;
|
|
49
|
-
return {
|
|
50
|
-
// TODO(dmaretskyi): Better error types.
|
|
51
|
-
invokeFunction: <I, O>(
|
|
52
|
-
functionDef: FunctionDefinition<I, O>,
|
|
53
|
-
input: I,
|
|
54
|
-
): Effect.Effect<O, never, InvocationServices> =>
|
|
55
|
-
Effect.gen(function* () {
|
|
56
|
-
const resolved = yield* resolver.resolveFunctionImplementation(functionDef).pipe(Effect.orDie);
|
|
57
|
-
const output = yield* invokeFunction(resolved, input);
|
|
58
|
-
return output as O;
|
|
59
|
-
}).pipe(
|
|
60
|
-
Effect.provideService(AiService.AiService, ai),
|
|
61
|
-
Effect.provideService(CredentialsService, credentials),
|
|
62
|
-
Effect.provideService(DatabaseService, database),
|
|
63
|
-
Effect.provideService(QueueService, queues),
|
|
64
|
-
Effect.provideService(RemoteFunctionExecutionService, functionCallService),
|
|
65
|
-
),
|
|
66
|
-
};
|
|
67
|
-
}),
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
static invokeFunction: <F extends FunctionDefinition.Any>(
|
|
71
|
-
functionDef: F,
|
|
72
|
-
input: FunctionDefinition.Input<F>,
|
|
73
|
-
) => Effect.Effect<FunctionDefinition.Output<F>, never, Services | LocalFunctionExecutionService> =
|
|
74
|
-
Effect.serviceFunctionEffect(LocalFunctionExecutionService, (_) => _.invokeFunction as any);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const invokeFunction = (
|
|
78
|
-
functionDef: FunctionDefinition<any, any>,
|
|
79
|
-
input: any,
|
|
80
|
-
): Effect.Effect<unknown, never, Services> =>
|
|
81
|
-
Effect.gen(function* () {
|
|
82
|
-
// Assert input matches schema.
|
|
83
|
-
try {
|
|
84
|
-
const assertInput = functionDef.inputSchema.pipe(Schema.asserts);
|
|
85
|
-
(assertInput as any)(input);
|
|
86
|
-
} catch (e) {
|
|
87
|
-
throw new FunctionError({ message: 'Invalid function input', context: { name: functionDef.name }, cause: e });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const context: FunctionContext = {
|
|
91
|
-
space: undefined,
|
|
92
|
-
getService: () => todo(),
|
|
93
|
-
getSpace: async (_spaceId: any) => {
|
|
94
|
-
throw new Error('Not available. Use the database service instead.');
|
|
95
|
-
},
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
log.info('invoking function', { name: functionDef.name, input });
|
|
99
|
-
|
|
100
|
-
// TODO(dmaretskyi): This should be delegated to a function invoker service.
|
|
101
|
-
const data = yield* Effect.gen(function* () {
|
|
102
|
-
const result = functionDef.handler({ context, data: input });
|
|
103
|
-
if (Effect.isEffect(result)) {
|
|
104
|
-
return yield* (result as Effect.Effect<unknown, unknown, Services>).pipe(Effect.orDie);
|
|
105
|
-
} else if (
|
|
106
|
-
typeof result === 'object' &&
|
|
107
|
-
result !== null &&
|
|
108
|
-
'then' in result &&
|
|
109
|
-
typeof result.then === 'function'
|
|
110
|
-
) {
|
|
111
|
-
return yield* Effect.promise(() => result);
|
|
112
|
-
} else {
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
115
|
-
}).pipe(
|
|
116
|
-
Effect.orDie,
|
|
117
|
-
Effect.catchAllDefect((defect) =>
|
|
118
|
-
Effect.die(new FunctionError({ context: { name: functionDef.name }, cause: defect })),
|
|
119
|
-
),
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
log.info('completed', { function: functionDef.name, input, data });
|
|
123
|
-
|
|
124
|
-
// Assert output matches schema.
|
|
125
|
-
try {
|
|
126
|
-
const assertOutput = functionDef.outputSchema?.pipe(Schema.asserts);
|
|
127
|
-
(assertOutput as any)(data);
|
|
128
|
-
} catch (e) {
|
|
129
|
-
throw new FunctionError({ message: 'Invalid function output', context: { name: functionDef.name }, cause: e });
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return data;
|
|
133
|
-
}).pipe(Effect.withSpan('invokeFunction', { attributes: { name: functionDef.name } }));
|
|
134
|
-
|
|
135
|
-
export class FunctionImplementationResolver extends Context.Tag('@dxos/functions/FunctionImplementationResolver')<
|
|
136
|
-
FunctionImplementationResolver,
|
|
137
|
-
{
|
|
138
|
-
resolveFunctionImplementation<I, O>(
|
|
139
|
-
functionDef: FunctionDefinition<I, O>,
|
|
140
|
-
): Effect.Effect<FunctionDefinition<I, O>, FunctionNotFoundError>;
|
|
141
|
-
}
|
|
142
|
-
>() {
|
|
143
|
-
static layerTest = ({ functions }: { functions: FunctionDefinition<any, any>[] }) =>
|
|
144
|
-
Layer.succeed(FunctionImplementationResolver, {
|
|
145
|
-
resolveFunctionImplementation: <I, O>(functionDef: FunctionDefinition<I, O>) => {
|
|
146
|
-
const resolved = functions.find((f) => f.key === functionDef.key);
|
|
147
|
-
if (!resolved) {
|
|
148
|
-
return Effect.fail(new FunctionNotFoundError(functionDef.name));
|
|
149
|
-
}
|
|
150
|
-
return Effect.succeed(resolved);
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
}
|
|
@@ -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 Layer from 'effect/Layer';
|
|
8
|
-
|
|
9
|
-
import type { SpaceId } from '@dxos/keys';
|
|
10
|
-
|
|
11
|
-
import { FunctionError } from '../errors';
|
|
12
|
-
import { getInvocationUrl } from '../url';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Allows calling into other functions.
|
|
16
|
-
*/
|
|
17
|
-
export class RemoteFunctionExecutionService extends Context.Tag('@dxos/functions/RemoteFunctionExecutionService')<
|
|
18
|
-
RemoteFunctionExecutionService,
|
|
19
|
-
{
|
|
20
|
-
callFunction<I, O>(deployedFunctionId: string, input: I): Effect.Effect<O>;
|
|
21
|
-
}
|
|
22
|
-
>() {
|
|
23
|
-
/**
|
|
24
|
-
* @param baseUrl URL of the EDGE server.
|
|
25
|
-
* @param spaceId - The space ID to invoke the function in. If not provided, the function will be without space context.
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
static fromClient(baseUrl: string, spaceId?: SpaceId): Layer.Layer<RemoteFunctionExecutionService> {
|
|
29
|
-
return Layer.succeed(RemoteFunctionExecutionService, {
|
|
30
|
-
callFunction: <I, O>(deployedFunctionId: string, input: I): Effect.Effect<O> =>
|
|
31
|
-
Effect.gen(function* () {
|
|
32
|
-
const url = getInvocationUrl(deployedFunctionId, baseUrl, { spaceId });
|
|
33
|
-
const result = yield* Effect.promise(() =>
|
|
34
|
-
fetch(url, {
|
|
35
|
-
method: 'POST',
|
|
36
|
-
headers: { 'Content-Type': 'application/json' },
|
|
37
|
-
body: JSON.stringify(input),
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
40
|
-
if (result.status >= 300 || result.status < 200) {
|
|
41
|
-
const text = yield* Effect.promise(() => result.text());
|
|
42
|
-
return yield* Effect.die(
|
|
43
|
-
new FunctionError({
|
|
44
|
-
message: 'Failed to invoke function',
|
|
45
|
-
cause: new Error(`HTTP error: ${text}`),
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
const data = (yield* Effect.promise(() => result.json())) as O;
|
|
50
|
-
return data;
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
static mock = (): Context.Tag.Service<RemoteFunctionExecutionService> => {
|
|
56
|
-
return {
|
|
57
|
-
callFunction: <I, O>(deployedFunctionId: string, input: I): Effect.Effect<O> =>
|
|
58
|
-
Effect.succeed(input as unknown as O),
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
static layerMock = Layer.succeed(RemoteFunctionExecutionService, RemoteFunctionExecutionService.mock());
|
|
63
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as Context from 'effect/Context';
|
|
6
|
-
import * as Layer from 'effect/Layer';
|
|
7
|
-
|
|
8
|
-
import { AiService } from '@dxos/ai';
|
|
9
|
-
import { entries } from '@dxos/util';
|
|
10
|
-
|
|
11
|
-
import { ConfiguredCredentialsService, CredentialsService } from './credentials';
|
|
12
|
-
import { DatabaseService } from './database';
|
|
13
|
-
import { ComputeEventLogger } from './event-logger';
|
|
14
|
-
import { QueueService } from './queues';
|
|
15
|
-
import { RemoteFunctionExecutionService } from './remote-function-execution-service';
|
|
16
|
-
import { TracingService } from './tracing';
|
|
17
|
-
|
|
18
|
-
// TODO(dmaretskyi): Refactor this module to only rely on tags and not the human-assigned names.
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* List of all services.
|
|
22
|
-
*/
|
|
23
|
-
const SERVICES = {
|
|
24
|
-
ai: AiService.AiService,
|
|
25
|
-
credentials: CredentialsService,
|
|
26
|
-
database: DatabaseService,
|
|
27
|
-
eventLogger: ComputeEventLogger,
|
|
28
|
-
functionCallService: RemoteFunctionExecutionService,
|
|
29
|
-
queues: QueueService,
|
|
30
|
-
tracing: TracingService,
|
|
31
|
-
} as const satisfies Record<string, Context.TagClass<any, string, any>>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Mapping of service names to their tags.
|
|
35
|
-
*/
|
|
36
|
-
export type ServiceTagRecord = {
|
|
37
|
-
[K in keyof typeof SERVICES]: (typeof SERVICES)[K] extends { new (_: never): infer T } ? T : never;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Mapping of service names to their runtime types.
|
|
42
|
-
*/
|
|
43
|
-
export type ServiceRecord = {
|
|
44
|
-
[K in keyof ServiceTagRecord]: Context.Tag.Service<ServiceTagRecord[K]>;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Union of all services tags.
|
|
49
|
-
*/
|
|
50
|
-
export type Services = ServiceTagRecord[keyof ServiceTagRecord];
|
|
51
|
-
|
|
52
|
-
const SERVICE_MAPPING: Record<string, keyof ServiceRecord> = Object.fromEntries(
|
|
53
|
-
entries(SERVICES).map(([name, tag]) => [tag.key, name]),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
export const SERVICE_TAGS: Context.Tag<any, any>[] = Object.values(SERVICES);
|
|
57
|
-
|
|
58
|
-
const DEFAULT_SERVICES: Partial<ServiceRecord> = {
|
|
59
|
-
tracing: TracingService.noop,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @deprecated
|
|
64
|
-
*/
|
|
65
|
-
export class ServiceContainer {
|
|
66
|
-
private _services: Partial<ServiceRecord> = { ...DEFAULT_SERVICES };
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Set services.
|
|
70
|
-
* @param services - Services to set.
|
|
71
|
-
* @returns The container instance.
|
|
72
|
-
*/
|
|
73
|
-
setServices(services: Partial<ServiceRecord>): this {
|
|
74
|
-
this._services = { ...this._services, ...services };
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
getService<Id, T>(tag: Context.Tag<Id, T>): T {
|
|
79
|
-
const serviceKey = SERVICE_MAPPING[tag.key];
|
|
80
|
-
const service = serviceKey != null ? this._services[serviceKey] : undefined;
|
|
81
|
-
if (!service) {
|
|
82
|
-
throw new Error(`Service not available: ${tag.key}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return service as T;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
clone(): ServiceContainer {
|
|
89
|
-
return new ServiceContainer().setServices({ ...this._services });
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// TODO(dmaretskyi): `getService` is designed to error at runtime if the service is not available, but Layer forces us to provide all services and makes stubs for the ones that are not available.
|
|
93
|
-
createLayer(): Layer.Layer<Services> {
|
|
94
|
-
const ai =
|
|
95
|
-
this._services.ai != null ? Layer.succeed(AiService.AiService, this._services.ai) : AiService.notAvailable;
|
|
96
|
-
const credentials = Layer.succeed(
|
|
97
|
-
CredentialsService,
|
|
98
|
-
this._services.credentials ?? new ConfiguredCredentialsService(),
|
|
99
|
-
);
|
|
100
|
-
const database =
|
|
101
|
-
this._services.database != null
|
|
102
|
-
? Layer.succeed(DatabaseService, this._services.database)
|
|
103
|
-
: DatabaseService.notAvailable;
|
|
104
|
-
const queues =
|
|
105
|
-
this._services.queues != null ? Layer.succeed(QueueService, this._services.queues) : QueueService.notAvailable;
|
|
106
|
-
const tracing = Layer.succeed(TracingService, this._services.tracing ?? TracingService.noop);
|
|
107
|
-
const eventLogger = Layer.succeed(ComputeEventLogger, this._services.eventLogger ?? ComputeEventLogger.noop);
|
|
108
|
-
const functionCallService = Layer.succeed(
|
|
109
|
-
RemoteFunctionExecutionService,
|
|
110
|
-
this._services.functionCallService ?? RemoteFunctionExecutionService.mock(),
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
return Layer.mergeAll(ai, credentials, database, queues, tracing, eventLogger, functionCallService);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { describe, it } from '@effect/vitest';
|
|
6
|
-
import * as Context from 'effect/Context';
|
|
7
|
-
import * as Effect from 'effect/Effect';
|
|
8
|
-
import * as Layer from 'effect/Layer';
|
|
9
|
-
import * as Option from 'effect/Option';
|
|
10
|
-
|
|
11
|
-
import { ServiceRegistry } from './service-registry';
|
|
12
|
-
|
|
13
|
-
class MyTag extends Context.Tag('MyTag')<MyTag, { value: string }>() {}
|
|
14
|
-
|
|
15
|
-
const mockRegistry = Layer.succeed(ServiceRegistry, {
|
|
16
|
-
resolve: (tag) => ((tag as any) === MyTag ? Option.some({ value: 'test' } as any) : Option.none()),
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe('ServiceRegistry', () => {
|
|
20
|
-
it.effect(
|
|
21
|
-
'provide',
|
|
22
|
-
Effect.fn(function* ({ expect }) {
|
|
23
|
-
const body = Effect.gen(function* () {
|
|
24
|
-
const { value } = yield* MyTag;
|
|
25
|
-
expect(value).toEqual('test');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
const eff = body.pipe(ServiceRegistry.provide(MyTag));
|
|
29
|
-
yield* eff;
|
|
30
|
-
}, Effect.provide(mockRegistry)),
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
it.effect(
|
|
34
|
-
'provide or die',
|
|
35
|
-
Effect.fn(function* ({ expect }) {
|
|
36
|
-
const body = Effect.gen(function* () {
|
|
37
|
-
const { value } = yield* MyTag;
|
|
38
|
-
expect(value).toEqual('test');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const eff = body.pipe(ServiceRegistry.provideOrDie(MyTag));
|
|
42
|
-
yield* eff;
|
|
43
|
-
}, Effect.provide(mockRegistry)),
|
|
44
|
-
);
|
|
45
|
-
});
|
|
@@ -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
|
-
});
|