@syncular/testkit 0.0.6-95 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/audit.d.ts +22 -0
- package/dist/audit.d.ts.map +1 -0
- package/dist/audit.js +40 -0
- package/dist/audit.js.map +1 -0
- package/dist/client-bridge.d.ts +77 -0
- package/dist/client-bridge.d.ts.map +1 -0
- package/dist/client-bridge.js +540 -0
- package/dist/client-bridge.js.map +1 -0
- package/dist/deterministic.js.map +1 -1
- package/dist/disposable.js.map +1 -1
- package/dist/faults.d.ts +14 -2
- package/dist/faults.d.ts.map +1 -1
- package/dist/faults.js +104 -42
- package/dist/faults.js.map +1 -1
- package/dist/hono-node-server.js +2 -2
- package/dist/hono-node-server.js.map +1 -1
- package/dist/http-fixtures.d.ts +1 -30
- package/dist/http-fixtures.d.ts.map +1 -1
- package/dist/http-fixtures.js +6 -66
- package/dist/http-fixtures.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -16
- package/dist/index.js.map +1 -1
- package/dist/project-scoped-tasks.d.ts.map +1 -1
- package/dist/project-scoped-tasks.js +6 -4
- package/dist/project-scoped-tasks.js.map +1 -1
- package/dist/realtime-ws.js +1 -1
- package/dist/realtime-ws.js.map +1 -1
- package/dist/runtime-process.js +1 -1
- package/dist/runtime-process.js.map +1 -1
- package/dist/sync-builders.d.ts +5 -3
- package/dist/sync-builders.d.ts.map +1 -1
- package/dist/sync-builders.js +9 -3
- package/dist/sync-builders.js.map +1 -1
- package/dist/sync-http.js +1 -1
- package/dist/sync-http.js.map +1 -1
- package/dist/sync-parse.js.map +1 -1
- package/dist/sync-response.d.ts +3 -4
- package/dist/sync-response.d.ts.map +1 -1
- package/dist/sync-response.js.map +1 -1
- package/package.json +15 -16
- package/src/audit.ts +74 -0
- package/src/client-bridge.ts +841 -0
- package/src/faults.ts +178 -55
- package/src/hono-node-server.ts +1 -1
- package/src/http-fixtures.ts +6 -127
- package/src/index.ts +2 -4
- package/src/project-scoped-tasks.ts +6 -4
- package/src/sync-builders.ts +14 -6
- package/src/sync-response.ts +3 -5
- package/dist/assertions.d.ts +0 -61
- package/dist/assertions.d.ts.map +0 -1
- package/dist/assertions.js +0 -239
- package/dist/assertions.js.map +0 -1
- package/dist/fixtures.d.ts +0 -104
- package/dist/fixtures.d.ts.map +0 -1
- package/dist/fixtures.js +0 -558
- package/dist/fixtures.js.map +0 -1
- package/dist/resources.d.ts +0 -25
- package/dist/resources.d.ts.map +0 -1
- package/dist/resources.js +0 -64
- package/dist/resources.js.map +0 -1
- package/dist/scenario-flow.d.ts +0 -39
- package/dist/scenario-flow.d.ts.map +0 -1
- package/dist/scenario-flow.js +0 -41
- package/dist/scenario-flow.js.map +0 -1
- package/src/assertions.ts +0 -432
- package/src/fixtures.ts +0 -867
- package/src/resources.ts +0 -186
- package/src/scenario-flow.ts +0 -143
package/src/resources.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import type { SyncClientDb } from '@syncular/client';
|
|
2
|
-
import type { SyncCoreDb } from '@syncular/server';
|
|
3
|
-
import {
|
|
4
|
-
type AsyncDisposableResource,
|
|
5
|
-
createAsyncDisposableResource,
|
|
6
|
-
type ResourceRunner,
|
|
7
|
-
withAsyncDisposableFactory,
|
|
8
|
-
} from './disposable';
|
|
9
|
-
import {
|
|
10
|
-
type CreateEngineTestClientOptions,
|
|
11
|
-
type CreateSyncFixtureOptions,
|
|
12
|
-
type CreateTestClientOptions,
|
|
13
|
-
createEngineTestClient,
|
|
14
|
-
createSyncFixture,
|
|
15
|
-
createTestClient,
|
|
16
|
-
createTestServer,
|
|
17
|
-
createTestSqliteServer,
|
|
18
|
-
type EngineTestClient,
|
|
19
|
-
type ServerDialect,
|
|
20
|
-
type SyncFixture,
|
|
21
|
-
type TestClient,
|
|
22
|
-
type TestClientDialect,
|
|
23
|
-
type TestServer,
|
|
24
|
-
type TestSqliteDbDialect,
|
|
25
|
-
} from './fixtures';
|
|
26
|
-
import {
|
|
27
|
-
type CreateHttpClientFixtureOptions,
|
|
28
|
-
type CreateHttpServerFixtureOptions,
|
|
29
|
-
createHttpClientFixture,
|
|
30
|
-
createHttpServerFixture,
|
|
31
|
-
type HttpClientFixture,
|
|
32
|
-
type HttpServerFixture,
|
|
33
|
-
} from './http-fixtures';
|
|
34
|
-
|
|
35
|
-
export async function createTestServerResource(
|
|
36
|
-
serverDialect: ServerDialect
|
|
37
|
-
): Promise<AsyncDisposableResource<TestServer>> {
|
|
38
|
-
const server = await createTestServer(serverDialect);
|
|
39
|
-
return createAsyncDisposableResource(server, () => server.destroy());
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function withTestServer<TResult>(
|
|
43
|
-
serverDialect: ServerDialect,
|
|
44
|
-
run: ResourceRunner<TestServer, TResult>
|
|
45
|
-
): Promise<TResult> {
|
|
46
|
-
return withAsyncDisposableFactory(
|
|
47
|
-
() => createTestServerResource(serverDialect),
|
|
48
|
-
run
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export async function createTestSqliteServerResource(
|
|
53
|
-
dialect: TestSqliteDbDialect
|
|
54
|
-
): Promise<AsyncDisposableResource<TestServer>> {
|
|
55
|
-
const server = await createTestSqliteServer(dialect);
|
|
56
|
-
return createAsyncDisposableResource(server, () => server.destroy());
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export async function withTestSqliteServer<TResult>(
|
|
60
|
-
dialect: TestSqliteDbDialect,
|
|
61
|
-
run: ResourceRunner<TestServer, TResult>
|
|
62
|
-
): Promise<TResult> {
|
|
63
|
-
return withAsyncDisposableFactory(
|
|
64
|
-
() => createTestSqliteServerResource(dialect),
|
|
65
|
-
run
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function createTestClientResource(
|
|
70
|
-
clientDialect: TestClientDialect,
|
|
71
|
-
server: TestServer,
|
|
72
|
-
options: CreateTestClientOptions
|
|
73
|
-
): Promise<AsyncDisposableResource<TestClient>> {
|
|
74
|
-
const client = await createTestClient(clientDialect, server, options);
|
|
75
|
-
return createAsyncDisposableResource(client, () => client.destroy());
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function withTestClient<TResult>(
|
|
79
|
-
clientDialect: TestClientDialect,
|
|
80
|
-
server: TestServer,
|
|
81
|
-
options: CreateTestClientOptions,
|
|
82
|
-
run: ResourceRunner<TestClient, TResult>
|
|
83
|
-
): Promise<TResult> {
|
|
84
|
-
return withAsyncDisposableFactory(
|
|
85
|
-
() => createTestClientResource(clientDialect, server, options),
|
|
86
|
-
run
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export async function createEngineTestClientResource(
|
|
91
|
-
server: TestServer,
|
|
92
|
-
options: CreateEngineTestClientOptions
|
|
93
|
-
): Promise<AsyncDisposableResource<EngineTestClient>> {
|
|
94
|
-
const client = await createEngineTestClient(server, options);
|
|
95
|
-
return createAsyncDisposableResource(client, () => client.destroy());
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function withEngineTestClient<TResult>(
|
|
99
|
-
server: TestServer,
|
|
100
|
-
options: CreateEngineTestClientOptions,
|
|
101
|
-
run: ResourceRunner<EngineTestClient, TResult>
|
|
102
|
-
): Promise<TResult> {
|
|
103
|
-
return withAsyncDisposableFactory(
|
|
104
|
-
() => createEngineTestClientResource(server, options),
|
|
105
|
-
run
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export async function createSyncFixtureResource(
|
|
110
|
-
options: CreateSyncFixtureOptions
|
|
111
|
-
): Promise<AsyncDisposableResource<SyncFixture>> {
|
|
112
|
-
const fixture = await createSyncFixture(options);
|
|
113
|
-
return createAsyncDisposableResource(fixture, () => fixture.destroyAll());
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export async function withSyncFixture<TResult>(
|
|
117
|
-
options: CreateSyncFixtureOptions,
|
|
118
|
-
run: ResourceRunner<SyncFixture, TResult>
|
|
119
|
-
): Promise<TResult> {
|
|
120
|
-
return withAsyncDisposableFactory(
|
|
121
|
-
() => createSyncFixtureResource(options),
|
|
122
|
-
run
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export async function createHttpServerFixtureResource<DB extends SyncCoreDb>(
|
|
127
|
-
options: CreateHttpServerFixtureOptions<DB>
|
|
128
|
-
): Promise<AsyncDisposableResource<HttpServerFixture<DB>>> {
|
|
129
|
-
const fixture = await createHttpServerFixture(options);
|
|
130
|
-
return createAsyncDisposableResource(fixture, () => fixture.destroy());
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export async function withHttpServerFixture<DB extends SyncCoreDb, TResult>(
|
|
134
|
-
options: CreateHttpServerFixtureOptions<DB>,
|
|
135
|
-
run: ResourceRunner<HttpServerFixture<DB>, TResult>
|
|
136
|
-
): Promise<TResult> {
|
|
137
|
-
return withAsyncDisposableFactory(
|
|
138
|
-
() => createHttpServerFixtureResource(options),
|
|
139
|
-
run
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export async function createHttpClientFixtureResource<DB extends SyncClientDb>(
|
|
144
|
-
options: CreateHttpClientFixtureOptions<DB>
|
|
145
|
-
): Promise<AsyncDisposableResource<HttpClientFixture<DB>>> {
|
|
146
|
-
const fixture = await createHttpClientFixture(options);
|
|
147
|
-
return createAsyncDisposableResource(fixture, () => fixture.destroy());
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export async function withHttpClientFixture<DB extends SyncClientDb, TResult>(
|
|
151
|
-
options: CreateHttpClientFixtureOptions<DB>,
|
|
152
|
-
run: ResourceRunner<HttpClientFixture<DB>, TResult>
|
|
153
|
-
): Promise<TResult> {
|
|
154
|
-
return withAsyncDisposableFactory(
|
|
155
|
-
() => createHttpClientFixtureResource(options),
|
|
156
|
-
run
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export interface EngineSessionResourceOptions {
|
|
161
|
-
start?: boolean;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export async function createEngineSessionResource(
|
|
165
|
-
client: EngineTestClient,
|
|
166
|
-
options: EngineSessionResourceOptions = {}
|
|
167
|
-
): Promise<AsyncDisposableResource<EngineTestClient>> {
|
|
168
|
-
if (options.start ?? true) {
|
|
169
|
-
await client.startEngine();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return createAsyncDisposableResource(client, () => {
|
|
173
|
-
client.stopEngine();
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export async function withEngineSession<TResult>(
|
|
178
|
-
client: EngineTestClient,
|
|
179
|
-
run: ResourceRunner<EngineTestClient, TResult>,
|
|
180
|
-
options: EngineSessionResourceOptions = {}
|
|
181
|
-
): Promise<TResult> {
|
|
182
|
-
return withAsyncDisposableFactory(
|
|
183
|
-
() => createEngineSessionResource(client, options),
|
|
184
|
-
run
|
|
185
|
-
);
|
|
186
|
-
}
|
package/src/scenario-flow.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ClientHandlerCollection,
|
|
3
|
-
enqueueOutboxCommit,
|
|
4
|
-
type SyncClientDb,
|
|
5
|
-
type SyncOnceOptions,
|
|
6
|
-
type SyncOnceResult,
|
|
7
|
-
type SyncPullOnceOptions,
|
|
8
|
-
type SyncPullResponse,
|
|
9
|
-
type SyncPushOnceOptions,
|
|
10
|
-
type SyncPushOnceResult,
|
|
11
|
-
syncOnce,
|
|
12
|
-
syncPullOnce,
|
|
13
|
-
syncPushOnce,
|
|
14
|
-
} from '@syncular/client';
|
|
15
|
-
import type {
|
|
16
|
-
SyncCombinedRequest,
|
|
17
|
-
SyncCombinedResponse,
|
|
18
|
-
SyncTransport,
|
|
19
|
-
} from '@syncular/core';
|
|
20
|
-
import type { Kysely } from 'kysely';
|
|
21
|
-
|
|
22
|
-
export interface ScenarioFlowClient<DB extends SyncClientDb> {
|
|
23
|
-
db: Kysely<DB>;
|
|
24
|
-
transport: SyncTransport;
|
|
25
|
-
handlers: ClientHandlerCollection<DB>;
|
|
26
|
-
clientId: string;
|
|
27
|
-
actorId?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface PushThenPullOptions<DB extends SyncClientDb> {
|
|
31
|
-
enqueue?: Parameters<typeof enqueueOutboxCommit<DB>>[1];
|
|
32
|
-
push?: Omit<SyncPushOnceOptions, 'clientId' | 'actorId'>;
|
|
33
|
-
pull: Omit<SyncPullOnceOptions, 'clientId' | 'actorId'>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface PushThenPullResult<DB extends SyncClientDb> {
|
|
37
|
-
enqueueResult?: { id: string; clientCommitId: string };
|
|
38
|
-
pushResult: SyncPushOnceResult;
|
|
39
|
-
pullResult: SyncPullResponse;
|
|
40
|
-
client: ScenarioFlowClient<DB>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface ScenarioFlow<DB extends SyncClientDb> {
|
|
44
|
-
client: ScenarioFlowClient<DB>;
|
|
45
|
-
enqueue: (
|
|
46
|
-
args: Parameters<typeof enqueueOutboxCommit<DB>>[1]
|
|
47
|
-
) => Promise<{ id: string; clientCommitId: string }>;
|
|
48
|
-
push: (
|
|
49
|
-
options?: Omit<SyncPushOnceOptions, 'clientId' | 'actorId'>
|
|
50
|
-
) => Promise<SyncPushOnceResult>;
|
|
51
|
-
pull: (
|
|
52
|
-
options: Omit<SyncPullOnceOptions, 'clientId' | 'actorId'>
|
|
53
|
-
) => Promise<SyncPullResponse>;
|
|
54
|
-
sync: (
|
|
55
|
-
options: Omit<SyncOnceOptions, 'clientId' | 'actorId'>
|
|
56
|
-
) => Promise<SyncOnceResult>;
|
|
57
|
-
transportSync: (
|
|
58
|
-
request: Omit<SyncCombinedRequest, 'clientId'>
|
|
59
|
-
) => Promise<SyncCombinedResponse>;
|
|
60
|
-
pushThenPull: (
|
|
61
|
-
options: PushThenPullOptions<DB>
|
|
62
|
-
) => Promise<PushThenPullResult<DB>>;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function withClientIdentity<
|
|
66
|
-
DB extends SyncClientDb,
|
|
67
|
-
T extends Record<string, unknown>,
|
|
68
|
-
>(
|
|
69
|
-
values: T,
|
|
70
|
-
client: ScenarioFlowClient<DB>
|
|
71
|
-
): T & { clientId: string; actorId?: string } {
|
|
72
|
-
return {
|
|
73
|
-
...values,
|
|
74
|
-
clientId: client.clientId,
|
|
75
|
-
...(client.actorId ? { actorId: client.actorId } : {}),
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function createScenarioFlow<DB extends SyncClientDb>(
|
|
80
|
-
client: ScenarioFlowClient<DB>
|
|
81
|
-
): ScenarioFlow<DB> {
|
|
82
|
-
const enqueue: ScenarioFlow<DB>['enqueue'] = (args) =>
|
|
83
|
-
enqueueOutboxCommit(client.db, args);
|
|
84
|
-
|
|
85
|
-
const push: ScenarioFlow<DB>['push'] = (options) =>
|
|
86
|
-
syncPushOnce(
|
|
87
|
-
client.db,
|
|
88
|
-
client.transport,
|
|
89
|
-
withClientIdentity(options ?? {}, client)
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const pull: ScenarioFlow<DB>['pull'] = (options) =>
|
|
93
|
-
syncPullOnce(
|
|
94
|
-
client.db,
|
|
95
|
-
client.transport,
|
|
96
|
-
client.handlers,
|
|
97
|
-
withClientIdentity(options, client)
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
const sync: ScenarioFlow<DB>['sync'] = (options) =>
|
|
101
|
-
syncOnce(
|
|
102
|
-
client.db,
|
|
103
|
-
client.transport,
|
|
104
|
-
client.handlers,
|
|
105
|
-
withClientIdentity(options, client)
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const transportSync: ScenarioFlow<DB>['transportSync'] = (request) =>
|
|
109
|
-
client.transport.sync({ clientId: client.clientId, ...request });
|
|
110
|
-
|
|
111
|
-
const pushThenPull: ScenarioFlow<DB>['pushThenPull'] = async (options) => {
|
|
112
|
-
const enqueueResult = options.enqueue
|
|
113
|
-
? await enqueueOutboxCommit(client.db, options.enqueue)
|
|
114
|
-
: undefined;
|
|
115
|
-
|
|
116
|
-
const pushResult = await push(options.push);
|
|
117
|
-
const pullResult = await pull(options.pull);
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
enqueueResult,
|
|
121
|
-
pushResult,
|
|
122
|
-
pullResult,
|
|
123
|
-
client,
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
client,
|
|
129
|
-
enqueue,
|
|
130
|
-
push,
|
|
131
|
-
pull,
|
|
132
|
-
sync,
|
|
133
|
-
transportSync,
|
|
134
|
-
pushThenPull,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export async function runPushPullCycle<DB extends SyncClientDb>(
|
|
139
|
-
client: ScenarioFlowClient<DB>,
|
|
140
|
-
options: PushThenPullOptions<DB>
|
|
141
|
-
): Promise<PushThenPullResult<DB>> {
|
|
142
|
-
return createScenarioFlow(client).pushThenPull(options);
|
|
143
|
-
}
|