spacetimedb 2.4.1 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +759 -759
- package/README.md +211 -120
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.mjs.map +1 -1
- package/dist/browser/angular/index.mjs.map +1 -1
- package/dist/browser/react/index.mjs +129 -57
- package/dist/browser/react/index.mjs.map +1 -1
- package/dist/browser/solid/index.mjs +1933 -0
- package/dist/browser/solid/index.mjs.map +1 -0
- package/dist/browser/svelte/index.mjs.map +1 -1
- package/dist/browser/vue/index.mjs.map +1 -1
- package/dist/index.browser.mjs +10 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.cjs +10 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +1 -1
- package/dist/min/index.browser.mjs +1 -1
- package/dist/min/index.browser.mjs.map +1 -1
- package/dist/min/react/index.mjs +1 -1
- package/dist/min/react/index.mjs.map +1 -1
- package/dist/min/sdk/index.browser.mjs +1 -1
- package/dist/min/sdk/index.browser.mjs.map +1 -1
- package/dist/react/index.cjs +129 -57
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.mjs +129 -57
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/useTable.d.ts.map +1 -1
- package/dist/sdk/connection_manager.d.ts +8 -0
- package/dist/sdk/connection_manager.d.ts.map +1 -1
- package/dist/sdk/db_connection_impl.d.ts +7 -0
- package/dist/sdk/db_connection_impl.d.ts.map +1 -1
- package/dist/sdk/index.browser.mjs +10 -2
- package/dist/sdk/index.browser.mjs.map +1 -1
- package/dist/sdk/index.cjs +10 -2
- package/dist/sdk/index.cjs.map +1 -1
- package/dist/sdk/index.mjs +10 -2
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/sdk/websocket_test_adapter.d.ts +2 -1
- package/dist/sdk/websocket_test_adapter.d.ts.map +1 -1
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/runtime.d.ts.map +1 -1
- package/dist/solid/SpacetimeDBProvider.d.ts +7 -0
- package/dist/solid/SpacetimeDBProvider.d.ts.map +1 -0
- package/dist/solid/connection_state.d.ts +6 -0
- package/dist/solid/connection_state.d.ts.map +1 -0
- package/dist/solid/index.cjs +1939 -0
- package/dist/solid/index.cjs.map +1 -0
- package/dist/solid/index.d.ts +6 -0
- package/dist/solid/index.d.ts.map +1 -0
- package/dist/solid/index.mjs +1933 -0
- package/dist/solid/index.mjs.map +1 -0
- package/dist/solid/useProcedure.d.ts +4 -0
- package/dist/solid/useProcedure.d.ts.map +1 -0
- package/dist/solid/useReducer.d.ts +4 -0
- package/dist/solid/useReducer.d.ts.map +1 -0
- package/dist/solid/useSpacetimeDB.d.ts +4 -0
- package/dist/solid/useSpacetimeDB.d.ts.map +1 -0
- package/dist/solid/useTable.d.ts +32 -0
- package/dist/solid/useTable.d.ts.map +1 -0
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.mjs.map +1 -1
- package/dist/tanstack/index.cjs +120 -50
- package/dist/tanstack/index.cjs.map +1 -1
- package/dist/tanstack/index.mjs +120 -50
- package/dist/tanstack/index.mjs.map +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.mjs.map +1 -1
- package/package.json +13 -3
- package/src/angular/connection_state.ts +19 -19
- package/src/angular/index.ts +3 -3
- package/src/angular/injectors/index.ts +4 -4
- package/src/angular/injectors/inject-reducer.ts +62 -62
- package/src/angular/injectors/inject-spacetimedb-connected.ts +13 -13
- package/src/angular/injectors/inject-spacetimedb.ts +10 -10
- package/src/angular/injectors/inject-table.ts +234 -234
- package/src/angular/providers/index.ts +1 -1
- package/src/angular/providers/provide-spacetimedb.ts +96 -96
- package/src/index.ts +16 -16
- package/src/lib/algebraic_type.ts +819 -819
- package/src/lib/algebraic_type_variants.ts +26 -26
- package/src/lib/algebraic_value.ts +10 -10
- package/src/lib/autogen/types.ts +746 -746
- package/src/lib/binary_reader.ts +188 -188
- package/src/lib/binary_writer.ts +213 -213
- package/src/lib/connection_id.ts +102 -102
- package/src/lib/constraints.ts +48 -48
- package/src/lib/errors.ts +26 -26
- package/src/lib/filter.ts +195 -195
- package/src/lib/identity.ts +83 -83
- package/src/lib/indexes.ts +251 -251
- package/src/lib/option.ts +34 -34
- package/src/lib/query.ts +1019 -1019
- package/src/lib/reducer_schema.ts +38 -38
- package/src/lib/reducers.ts +116 -116
- package/src/lib/result.ts +36 -36
- package/src/lib/schedule_at.ts +86 -86
- package/src/lib/schema.ts +420 -420
- package/src/lib/table.ts +548 -548
- package/src/lib/table_schema.ts +64 -64
- package/src/lib/time_duration.ts +77 -77
- package/src/lib/timestamp.ts +148 -148
- package/src/lib/type_builders.test-d.ts +128 -128
- package/src/lib/type_builders.ts +4014 -4014
- package/src/lib/type_util.ts +124 -124
- package/src/lib/util.ts +196 -196
- package/src/lib/uuid.ts +337 -337
- package/src/react/SpacetimeDBProvider.ts +84 -84
- package/src/react/connection_state.ts +6 -6
- package/src/react/index.ts +5 -5
- package/src/react/useProcedure.ts +60 -60
- package/src/react/useReducer.ts +53 -53
- package/src/react/useSpacetimeDB.ts +18 -18
- package/src/react/useTable.ts +256 -251
- package/src/sdk/client_api/index.ts +114 -114
- package/src/sdk/client_api/types/procedures.ts +8 -8
- package/src/sdk/client_api/types/reducers.ts +8 -8
- package/src/sdk/client_api/types.ts +288 -288
- package/src/sdk/client_cache.ts +129 -129
- package/src/sdk/client_table.ts +179 -179
- package/src/sdk/connection_manager.ts +352 -237
- package/src/sdk/db_connection_builder.ts +290 -290
- package/src/sdk/db_connection_impl.ts +1356 -1347
- package/src/sdk/db_context.ts +28 -28
- package/src/sdk/db_view.ts +12 -12
- package/src/sdk/decompress.ts +51 -51
- package/src/sdk/event.ts +18 -18
- package/src/sdk/event_context.ts +51 -51
- package/src/sdk/event_emitter.ts +32 -32
- package/src/sdk/index.ts +14 -14
- package/src/sdk/internal.ts +2 -2
- package/src/sdk/json_api.ts +46 -46
- package/src/sdk/logger.ts +134 -134
- package/src/sdk/message_types.ts +46 -46
- package/src/sdk/procedures.ts +83 -83
- package/src/sdk/reducer_event.ts +20 -20
- package/src/sdk/reducer_handle.ts +12 -12
- package/src/sdk/reducers.ts +159 -159
- package/src/sdk/schema.ts +45 -45
- package/src/sdk/spacetime_module.ts +28 -28
- package/src/sdk/subscription_builder_impl.ts +275 -275
- package/src/sdk/table_cache.ts +581 -581
- package/src/sdk/type_utils.ts +19 -19
- package/src/sdk/version.ts +133 -133
- package/src/sdk/websocket_decompress_adapter.ts +63 -63
- package/src/sdk/websocket_protocols.ts +25 -25
- package/src/sdk/websocket_test_adapter.ts +107 -100
- package/src/sdk/websocket_v3_frames.ts +126 -126
- package/src/sdk/ws.ts +105 -105
- package/src/server/console.ts +81 -81
- package/src/server/db_view.ts +21 -21
- package/src/server/errors.ts +138 -138
- package/src/server/http.test-d.ts +80 -80
- package/src/server/http.ts +14 -14
- package/src/server/http_handlers.ts +413 -413
- package/src/server/http_internal.ts +79 -79
- package/src/server/http_shared.ts +186 -186
- package/src/server/index.ts +37 -37
- package/src/server/polyfills.ts +4 -4
- package/src/server/procedures.ts +239 -239
- package/src/server/query.ts +1 -1
- package/src/server/range.ts +53 -53
- package/src/server/reducers.ts +113 -113
- package/src/server/rng.ts +113 -113
- package/src/server/runtime.ts +1102 -1102
- package/src/server/schema.test-d.ts +99 -99
- package/src/server/schema.ts +663 -663
- package/src/server/sys.d.ts +125 -125
- package/src/server/view.test-d.ts +194 -194
- package/src/server/views.ts +340 -340
- package/src/solid/SpacetimeDBProvider.ts +97 -0
- package/src/solid/connection_state.ts +6 -0
- package/src/solid/index.ts +5 -0
- package/src/solid/useProcedure.ts +57 -0
- package/src/solid/useReducer.ts +50 -0
- package/src/solid/useSpacetimeDB.ts +18 -0
- package/src/solid/useTable.ts +203 -0
- package/src/svelte/SpacetimeDBProvider.ts +101 -101
- package/src/svelte/connection_state.ts +16 -16
- package/src/svelte/index.ts +4 -4
- package/src/svelte/useReducer.ts +61 -61
- package/src/svelte/useSpacetimeDB.ts +22 -22
- package/src/svelte/useTable.ts +218 -218
- package/src/tanstack/SpacetimeDBQueryClient.ts +330 -330
- package/src/tanstack/hooks.ts +83 -83
- package/src/tanstack/index.ts +16 -16
- package/src/util-stub.ts +1 -1
- package/src/vue/SpacetimeDBProvider.ts +157 -157
- package/src/vue/connection_state.ts +19 -19
- package/src/vue/index.ts +5 -5
- package/src/vue/useProcedure.ts +62 -62
- package/src/vue/useReducer.ts +55 -55
- package/src/vue/useSpacetimeDB.ts +18 -18
- package/src/vue/useTable.ts +229 -229
package/src/sdk/db_context.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import type { ClientDbView } from './db_view';
|
|
2
|
-
import type { ReducersView } from './reducers';
|
|
3
|
-
import type { UntypedRemoteModule } from './spacetime_module';
|
|
4
|
-
import type { SubscriptionBuilderImpl } from './subscription_builder_impl';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Interface representing a database context.
|
|
8
|
-
*
|
|
9
|
-
* @template DbView - Type representing the database view.
|
|
10
|
-
* @template ReducersDef - Type representing the reducers.
|
|
11
|
-
*/
|
|
12
|
-
export interface DbContext<RemoteModule extends UntypedRemoteModule> {
|
|
13
|
-
db: ClientDbView<RemoteModule>;
|
|
14
|
-
reducers: ReducersView<RemoteModule>;
|
|
15
|
-
isActive: boolean;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Creates a new subscription builder.
|
|
19
|
-
*
|
|
20
|
-
* @returns The subscription builder.
|
|
21
|
-
*/
|
|
22
|
-
subscriptionBuilder(): SubscriptionBuilderImpl<RemoteModule>;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Disconnects from the database.
|
|
26
|
-
*/
|
|
27
|
-
disconnect(): void;
|
|
28
|
-
}
|
|
1
|
+
import type { ClientDbView } from './db_view';
|
|
2
|
+
import type { ReducersView } from './reducers';
|
|
3
|
+
import type { UntypedRemoteModule } from './spacetime_module';
|
|
4
|
+
import type { SubscriptionBuilderImpl } from './subscription_builder_impl';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Interface representing a database context.
|
|
8
|
+
*
|
|
9
|
+
* @template DbView - Type representing the database view.
|
|
10
|
+
* @template ReducersDef - Type representing the reducers.
|
|
11
|
+
*/
|
|
12
|
+
export interface DbContext<RemoteModule extends UntypedRemoteModule> {
|
|
13
|
+
db: ClientDbView<RemoteModule>;
|
|
14
|
+
reducers: ReducersView<RemoteModule>;
|
|
15
|
+
isActive: boolean;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new subscription builder.
|
|
19
|
+
*
|
|
20
|
+
* @returns The subscription builder.
|
|
21
|
+
*/
|
|
22
|
+
subscriptionBuilder(): SubscriptionBuilderImpl<RemoteModule>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Disconnects from the database.
|
|
26
|
+
*/
|
|
27
|
+
disconnect(): void;
|
|
28
|
+
}
|
package/src/sdk/db_view.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { UntypedRemoteModule } from './spacetime_module';
|
|
2
|
-
import type { ClientTable } from './client_table';
|
|
3
|
-
import type { Values } from '../lib/type_util';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A type representing a client-side database view, mapping table names to their corresponding client Table handles.
|
|
7
|
-
*/
|
|
8
|
-
export type ClientDbView<RemoteModule extends UntypedRemoteModule> = {
|
|
9
|
-
readonly [TblName in Values<
|
|
10
|
-
RemoteModule['tables']
|
|
11
|
-
>['accessorName']]: ClientTable<RemoteModule, TblName>;
|
|
12
|
-
};
|
|
1
|
+
import type { UntypedRemoteModule } from './spacetime_module';
|
|
2
|
+
import type { ClientTable } from './client_table';
|
|
3
|
+
import type { Values } from '../lib/type_util';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A type representing a client-side database view, mapping table names to their corresponding client Table handles.
|
|
7
|
+
*/
|
|
8
|
+
export type ClientDbView<RemoteModule extends UntypedRemoteModule> = {
|
|
9
|
+
readonly [TblName in Values<
|
|
10
|
+
RemoteModule['tables']
|
|
11
|
+
>['accessorName']]: ClientTable<RemoteModule, TblName>;
|
|
12
|
+
};
|
package/src/sdk/decompress.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
export async function decompress(
|
|
2
|
-
buffer: Uint8Array<ArrayBuffer>,
|
|
3
|
-
type: CompressionFormat,
|
|
4
|
-
chunkSize: number = 128 * 1024 // 128KB
|
|
5
|
-
): Promise<Uint8Array> {
|
|
6
|
-
// Create a single ReadableStream to handle chunks
|
|
7
|
-
let offset = 0;
|
|
8
|
-
const readableStream = new ReadableStream<BufferSource>({
|
|
9
|
-
pull(controller) {
|
|
10
|
-
if (offset < buffer.length) {
|
|
11
|
-
// Slice a chunk of the buffer and enqueue it
|
|
12
|
-
const chunk = buffer.subarray(
|
|
13
|
-
offset,
|
|
14
|
-
Math.min(offset + chunkSize, buffer.length)
|
|
15
|
-
);
|
|
16
|
-
controller.enqueue(chunk);
|
|
17
|
-
offset += chunkSize;
|
|
18
|
-
} else {
|
|
19
|
-
controller.close();
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Create a single DecompressionStream
|
|
25
|
-
const decompressionStream = new DecompressionStream(type);
|
|
26
|
-
|
|
27
|
-
// Pipe the ReadableStream through the DecompressionStream
|
|
28
|
-
const decompressedStream = readableStream.pipeThrough(decompressionStream);
|
|
29
|
-
|
|
30
|
-
// Collect the decompressed chunks efficiently
|
|
31
|
-
const reader = decompressedStream.getReader();
|
|
32
|
-
const chunks: Uint8Array[] = [];
|
|
33
|
-
let totalLength = 0;
|
|
34
|
-
let result: any;
|
|
35
|
-
|
|
36
|
-
while (!(result = await reader.read()).done) {
|
|
37
|
-
chunks.push(result.value);
|
|
38
|
-
totalLength += result.value.length;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Allocate a single Uint8Array for the decompressed data
|
|
42
|
-
const decompressedArray = new Uint8Array(totalLength);
|
|
43
|
-
let chunkOffset = 0;
|
|
44
|
-
|
|
45
|
-
for (const chunk of chunks) {
|
|
46
|
-
decompressedArray.set(chunk, chunkOffset);
|
|
47
|
-
chunkOffset += chunk.length;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return decompressedArray;
|
|
51
|
-
}
|
|
1
|
+
export async function decompress(
|
|
2
|
+
buffer: Uint8Array<ArrayBuffer>,
|
|
3
|
+
type: CompressionFormat,
|
|
4
|
+
chunkSize: number = 128 * 1024 // 128KB
|
|
5
|
+
): Promise<Uint8Array> {
|
|
6
|
+
// Create a single ReadableStream to handle chunks
|
|
7
|
+
let offset = 0;
|
|
8
|
+
const readableStream = new ReadableStream<BufferSource>({
|
|
9
|
+
pull(controller) {
|
|
10
|
+
if (offset < buffer.length) {
|
|
11
|
+
// Slice a chunk of the buffer and enqueue it
|
|
12
|
+
const chunk = buffer.subarray(
|
|
13
|
+
offset,
|
|
14
|
+
Math.min(offset + chunkSize, buffer.length)
|
|
15
|
+
);
|
|
16
|
+
controller.enqueue(chunk);
|
|
17
|
+
offset += chunkSize;
|
|
18
|
+
} else {
|
|
19
|
+
controller.close();
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Create a single DecompressionStream
|
|
25
|
+
const decompressionStream = new DecompressionStream(type);
|
|
26
|
+
|
|
27
|
+
// Pipe the ReadableStream through the DecompressionStream
|
|
28
|
+
const decompressedStream = readableStream.pipeThrough(decompressionStream);
|
|
29
|
+
|
|
30
|
+
// Collect the decompressed chunks efficiently
|
|
31
|
+
const reader = decompressedStream.getReader();
|
|
32
|
+
const chunks: Uint8Array[] = [];
|
|
33
|
+
let totalLength = 0;
|
|
34
|
+
let result: any;
|
|
35
|
+
|
|
36
|
+
while (!(result = await reader.read()).done) {
|
|
37
|
+
chunks.push(result.value);
|
|
38
|
+
totalLength += result.value.length;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Allocate a single Uint8Array for the decompressed data
|
|
42
|
+
const decompressedArray = new Uint8Array(totalLength);
|
|
43
|
+
let chunkOffset = 0;
|
|
44
|
+
|
|
45
|
+
for (const chunk of chunks) {
|
|
46
|
+
decompressedArray.set(chunk, chunkOffset);
|
|
47
|
+
chunkOffset += chunk.length;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return decompressedArray;
|
|
51
|
+
}
|
package/src/sdk/event.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import type { ReducerEvent } from './reducer_event';
|
|
2
|
-
import type { ReducerEventInfo } from './reducers';
|
|
3
|
-
|
|
4
|
-
type WithId = {
|
|
5
|
-
/**
|
|
6
|
-
* A client-generated id to distinguish between different events.
|
|
7
|
-
*/
|
|
8
|
-
id: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type Event<Reducer extends ReducerEventInfo> = WithId &
|
|
12
|
-
(
|
|
13
|
-
| { tag: 'Reducer'; value: ReducerEvent<Reducer> }
|
|
14
|
-
| { tag: 'SubscribeApplied' }
|
|
15
|
-
| { tag: 'UnsubscribeApplied' }
|
|
16
|
-
| { tag: 'Error'; value: Error }
|
|
17
|
-
| { tag: 'Transaction' }
|
|
18
|
-
);
|
|
1
|
+
import type { ReducerEvent } from './reducer_event';
|
|
2
|
+
import type { ReducerEventInfo } from './reducers';
|
|
3
|
+
|
|
4
|
+
type WithId = {
|
|
5
|
+
/**
|
|
6
|
+
* A client-generated id to distinguish between different events.
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type Event<Reducer extends ReducerEventInfo> = WithId &
|
|
12
|
+
(
|
|
13
|
+
| { tag: 'Reducer'; value: ReducerEvent<Reducer> }
|
|
14
|
+
| { tag: 'SubscribeApplied' }
|
|
15
|
+
| { tag: 'UnsubscribeApplied' }
|
|
16
|
+
| { tag: 'Error'; value: Error }
|
|
17
|
+
| { tag: 'Transaction' }
|
|
18
|
+
);
|
package/src/sdk/event_context.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import type { InferTypeOfRow } from '../lib/type_builders.ts';
|
|
2
|
-
import type { DbContext } from './db_context';
|
|
3
|
-
import type { Event } from './event.ts';
|
|
4
|
-
import type { ReducerEvent } from './reducer_event.ts';
|
|
5
|
-
import type { ReducerEventInfo } from './reducers.ts';
|
|
6
|
-
import type { UntypedRemoteModule } from './spacetime_module.ts';
|
|
7
|
-
|
|
8
|
-
export type UntypedEventContext = EventContextInterface<UntypedRemoteModule>;
|
|
9
|
-
|
|
10
|
-
export interface EventContextInterface<RemoteModule extends UntypedRemoteModule>
|
|
11
|
-
extends DbContext<RemoteModule> {
|
|
12
|
-
/** Enum with variants for all possible events. */
|
|
13
|
-
event: Event<
|
|
14
|
-
ReducerEventInfo<
|
|
15
|
-
RemoteModule['reducers'][number]['name'],
|
|
16
|
-
InferTypeOfRow<RemoteModule['reducers'][number]['params']>
|
|
17
|
-
>
|
|
18
|
-
>;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ReducerEventContextInterface<
|
|
22
|
-
RemoteModule extends UntypedRemoteModule,
|
|
23
|
-
> extends DbContext<RemoteModule> {
|
|
24
|
-
/** Enum with variants for all possible events. */
|
|
25
|
-
event: ReducerEvent<
|
|
26
|
-
ReducerEventInfo<
|
|
27
|
-
RemoteModule['reducers'][number]['name'],
|
|
28
|
-
InferTypeOfRow<RemoteModule['reducers'][number]['params']>
|
|
29
|
-
>
|
|
30
|
-
>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
34
|
-
export interface ProcedureEventContextInterface<
|
|
35
|
-
RemoteModule extends UntypedRemoteModule,
|
|
36
|
-
> extends DbContext<RemoteModule> {
|
|
37
|
-
/** No event is provided */
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
41
|
-
export interface SubscriptionEventContextInterface<
|
|
42
|
-
RemoteModule extends UntypedRemoteModule,
|
|
43
|
-
> extends DbContext<RemoteModule> {
|
|
44
|
-
/** No event is provided **/
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface ErrorContextInterface<RemoteModule extends UntypedRemoteModule>
|
|
48
|
-
extends DbContext<RemoteModule> {
|
|
49
|
-
/** Enum with variants for all possible events. */
|
|
50
|
-
event?: Error;
|
|
51
|
-
}
|
|
1
|
+
import type { InferTypeOfRow } from '../lib/type_builders.ts';
|
|
2
|
+
import type { DbContext } from './db_context';
|
|
3
|
+
import type { Event } from './event.ts';
|
|
4
|
+
import type { ReducerEvent } from './reducer_event.ts';
|
|
5
|
+
import type { ReducerEventInfo } from './reducers.ts';
|
|
6
|
+
import type { UntypedRemoteModule } from './spacetime_module.ts';
|
|
7
|
+
|
|
8
|
+
export type UntypedEventContext = EventContextInterface<UntypedRemoteModule>;
|
|
9
|
+
|
|
10
|
+
export interface EventContextInterface<RemoteModule extends UntypedRemoteModule>
|
|
11
|
+
extends DbContext<RemoteModule> {
|
|
12
|
+
/** Enum with variants for all possible events. */
|
|
13
|
+
event: Event<
|
|
14
|
+
ReducerEventInfo<
|
|
15
|
+
RemoteModule['reducers'][number]['name'],
|
|
16
|
+
InferTypeOfRow<RemoteModule['reducers'][number]['params']>
|
|
17
|
+
>
|
|
18
|
+
>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface ReducerEventContextInterface<
|
|
22
|
+
RemoteModule extends UntypedRemoteModule,
|
|
23
|
+
> extends DbContext<RemoteModule> {
|
|
24
|
+
/** Enum with variants for all possible events. */
|
|
25
|
+
event: ReducerEvent<
|
|
26
|
+
ReducerEventInfo<
|
|
27
|
+
RemoteModule['reducers'][number]['name'],
|
|
28
|
+
InferTypeOfRow<RemoteModule['reducers'][number]['params']>
|
|
29
|
+
>
|
|
30
|
+
>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
34
|
+
export interface ProcedureEventContextInterface<
|
|
35
|
+
RemoteModule extends UntypedRemoteModule,
|
|
36
|
+
> extends DbContext<RemoteModule> {
|
|
37
|
+
/** No event is provided */
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
41
|
+
export interface SubscriptionEventContextInterface<
|
|
42
|
+
RemoteModule extends UntypedRemoteModule,
|
|
43
|
+
> extends DbContext<RemoteModule> {
|
|
44
|
+
/** No event is provided **/
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface ErrorContextInterface<RemoteModule extends UntypedRemoteModule>
|
|
48
|
+
extends DbContext<RemoteModule> {
|
|
49
|
+
/** Enum with variants for all possible events. */
|
|
50
|
+
event?: Error;
|
|
51
|
+
}
|
package/src/sdk/event_emitter.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
2
|
-
export class EventEmitter<Key, Callback extends Function = Function> {
|
|
3
|
-
#events: Map<Key, Set<Callback>> = new Map();
|
|
4
|
-
|
|
5
|
-
on(event: Key, callback: Callback): void {
|
|
6
|
-
let callbacks = this.#events.get(event);
|
|
7
|
-
if (!callbacks) {
|
|
8
|
-
callbacks = new Set();
|
|
9
|
-
this.#events.set(event, callbacks);
|
|
10
|
-
}
|
|
11
|
-
callbacks.add(callback);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
off(event: Key, callback: Callback): void {
|
|
15
|
-
const callbacks = this.#events.get(event);
|
|
16
|
-
if (!callbacks) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
callbacks.delete(callback);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
emit(event: Key, ...args: any[]): void {
|
|
23
|
-
const callbacks = this.#events.get(event);
|
|
24
|
-
if (!callbacks) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (const callback of callbacks) {
|
|
29
|
-
callback(...args);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
|
2
|
+
export class EventEmitter<Key, Callback extends Function = Function> {
|
|
3
|
+
#events: Map<Key, Set<Callback>> = new Map();
|
|
4
|
+
|
|
5
|
+
on(event: Key, callback: Callback): void {
|
|
6
|
+
let callbacks = this.#events.get(event);
|
|
7
|
+
if (!callbacks) {
|
|
8
|
+
callbacks = new Set();
|
|
9
|
+
this.#events.set(event, callbacks);
|
|
10
|
+
}
|
|
11
|
+
callbacks.add(callback);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
off(event: Key, callback: Callback): void {
|
|
15
|
+
const callbacks = this.#events.get(event);
|
|
16
|
+
if (!callbacks) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
callbacks.delete(callback);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
emit(event: Key, ...args: any[]): void {
|
|
23
|
+
const callbacks = this.#events.get(event);
|
|
24
|
+
if (!callbacks) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
for (const callback of callbacks) {
|
|
29
|
+
callback(...args);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/sdk/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// Should be at the top as other modules depend on it
|
|
2
|
-
export * from './db_connection_impl.ts';
|
|
3
|
-
export * from './client_cache.ts';
|
|
4
|
-
export * from './message_types.ts';
|
|
5
|
-
export * from '../lib/errors.ts';
|
|
6
|
-
export * from './logger.ts';
|
|
7
|
-
export { type ClientTable } from './client_table.ts';
|
|
8
|
-
export { type RemoteModule } from './spacetime_module.ts';
|
|
9
|
-
export * from '../lib/type_builders.ts';
|
|
10
|
-
export { schema, convertToAccessorMap } from './schema.ts';
|
|
11
|
-
export { table } from '../lib/table.ts';
|
|
12
|
-
export { reducerSchema, reducers } from './reducers.ts';
|
|
13
|
-
export { procedureSchema, procedures } from './procedures.ts';
|
|
14
|
-
export * from './type_utils.ts';
|
|
1
|
+
// Should be at the top as other modules depend on it
|
|
2
|
+
export * from './db_connection_impl.ts';
|
|
3
|
+
export * from './client_cache.ts';
|
|
4
|
+
export * from './message_types.ts';
|
|
5
|
+
export * from '../lib/errors.ts';
|
|
6
|
+
export * from './logger.ts';
|
|
7
|
+
export { type ClientTable } from './client_table.ts';
|
|
8
|
+
export { type RemoteModule } from './spacetime_module.ts';
|
|
9
|
+
export * from '../lib/type_builders.ts';
|
|
10
|
+
export { schema, convertToAccessorMap } from './schema.ts';
|
|
11
|
+
export { table } from '../lib/table.ts';
|
|
12
|
+
export { reducerSchema, reducers } from './reducers.ts';
|
|
13
|
+
export { procedureSchema, procedures } from './procedures.ts';
|
|
14
|
+
export * from './type_utils.ts';
|
package/src/sdk/internal.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// Internal symbols not exported from the public SDK surface.
|
|
2
|
-
export const INTERNAL_REMOTE_MODULE = Symbol('INTERNAL_REMOTE_MODULE');
|
|
1
|
+
// Internal symbols not exported from the public SDK surface.
|
|
2
|
+
export const INTERNAL_REMOTE_MODULE = Symbol('INTERNAL_REMOTE_MODULE');
|
package/src/sdk/json_api.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
export interface Message {
|
|
2
|
-
IdentityToken?: IdentityToken | undefined;
|
|
3
|
-
SubscriptionUpdate?: SubscriptionUpdate | undefined;
|
|
4
|
-
TransactionUpdate?: TransactionUpdate | undefined;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export interface IdentityToken {
|
|
8
|
-
identity: string;
|
|
9
|
-
token: string;
|
|
10
|
-
address: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface SubscriptionUpdate {
|
|
14
|
-
table_updates: TableUpdate[];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface TableUpdate {
|
|
18
|
-
table_id: number;
|
|
19
|
-
table_name: string;
|
|
20
|
-
table_row_operations: TableRowOperation[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface TableRowOperation {
|
|
24
|
-
op: 'insert' | 'delete';
|
|
25
|
-
row: any[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface TransactionUpdate {
|
|
29
|
-
event: Event;
|
|
30
|
-
subscription_update: SubscriptionUpdate;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface Event {
|
|
34
|
-
timestamp: number;
|
|
35
|
-
status: 'committed' | 'failed' | 'out_of_energy';
|
|
36
|
-
caller_identity: string;
|
|
37
|
-
caller_address: string;
|
|
38
|
-
function_call: FunctionCall;
|
|
39
|
-
energy_quanta_used: number;
|
|
40
|
-
message: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface FunctionCall {
|
|
44
|
-
reducer: string;
|
|
45
|
-
args: string;
|
|
46
|
-
}
|
|
1
|
+
export interface Message {
|
|
2
|
+
IdentityToken?: IdentityToken | undefined;
|
|
3
|
+
SubscriptionUpdate?: SubscriptionUpdate | undefined;
|
|
4
|
+
TransactionUpdate?: TransactionUpdate | undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface IdentityToken {
|
|
8
|
+
identity: string;
|
|
9
|
+
token: string;
|
|
10
|
+
address: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface SubscriptionUpdate {
|
|
14
|
+
table_updates: TableUpdate[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface TableUpdate {
|
|
18
|
+
table_id: number;
|
|
19
|
+
table_name: string;
|
|
20
|
+
table_row_operations: TableRowOperation[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface TableRowOperation {
|
|
24
|
+
op: 'insert' | 'delete';
|
|
25
|
+
row: any[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface TransactionUpdate {
|
|
29
|
+
event: Event;
|
|
30
|
+
subscription_update: SubscriptionUpdate;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface Event {
|
|
34
|
+
timestamp: number;
|
|
35
|
+
status: 'committed' | 'failed' | 'out_of_energy';
|
|
36
|
+
caller_identity: string;
|
|
37
|
+
caller_address: string;
|
|
38
|
+
function_call: FunctionCall;
|
|
39
|
+
energy_quanta_used: number;
|
|
40
|
+
message: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FunctionCall {
|
|
44
|
+
reducer: string;
|
|
45
|
+
args: string;
|
|
46
|
+
}
|