spacetimedb 2.0.0 → 2.0.1
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 +2 -2
- package/dist/browser/svelte/index.mjs +4 -1
- package/dist/browser/svelte/index.mjs.map +1 -1
- package/dist/browser/vue/index.mjs +4 -1
- package/dist/browser/vue/index.mjs.map +1 -1
- package/dist/index.browser.mjs +11 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.cjs +11 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +11 -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/sdk/index.browser.mjs +1 -1
- package/dist/min/sdk/index.browser.mjs.map +1 -1
- package/dist/sdk/db_connection_impl.d.ts.map +1 -1
- package/dist/sdk/event.d.ts +1 -1
- package/dist/sdk/event.d.ts.map +1 -1
- package/dist/sdk/index.browser.mjs +11 -2
- package/dist/sdk/index.browser.mjs.map +1 -1
- package/dist/sdk/index.cjs +11 -2
- package/dist/sdk/index.cjs.map +1 -1
- package/dist/sdk/index.mjs +11 -2
- package/dist/sdk/index.mjs.map +1 -1
- package/dist/sdk/websocket_test_adapter.d.ts.map +1 -1
- package/dist/server/index.mjs +20 -12
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/procedures.d.ts.map +1 -1
- package/dist/server/reducers.d.ts +1 -1
- package/dist/server/reducers.d.ts.map +1 -1
- package/dist/server/rng.d.ts +0 -5
- package/dist/server/rng.d.ts.map +1 -1
- package/dist/svelte/index.cjs +4 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.mjs +4 -1
- package/dist/svelte/index.mjs.map +1 -1
- package/dist/svelte/useTable.d.ts +2 -3
- package/dist/svelte/useTable.d.ts.map +1 -1
- package/dist/vue/index.cjs +4 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.mjs +4 -1
- package/dist/vue/index.mjs.map +1 -1
- package/dist/vue/useTable.d.ts +2 -3
- package/dist/vue/useTable.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/sdk/db_connection_impl.ts +16 -2
- package/src/sdk/event.ts +1 -1
- package/src/sdk/websocket_test_adapter.ts +1 -0
- package/src/server/procedures.ts +14 -4
- package/src/server/reducers.ts +19 -10
- package/src/server/rng.ts +0 -6
- package/src/svelte/useTable.ts +4 -2
- package/src/vue/useTable.ts +4 -2
package/dist/vue/useTable.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DeepReadonly, type Ref } from 'vue';
|
|
2
2
|
import type { RowType, UntypedTableDef } from '../lib/table';
|
|
3
3
|
import type { Prettify } from '../lib/type_util';
|
|
4
|
+
import { type Query } from '../lib/query';
|
|
4
5
|
export interface UseTableCallbacks<RowType> {
|
|
5
6
|
onInsert?: (row: RowType) => void;
|
|
6
7
|
onDelete?: (row: RowType) => void;
|
|
@@ -17,9 +18,7 @@ export interface UseTableCallbacks<RowType> {
|
|
|
17
18
|
* @param callbacks - Optional callbacks for row insert, delete, and update events.
|
|
18
19
|
* @returns A tuple of [rows, isReady].
|
|
19
20
|
*/
|
|
20
|
-
export declare function useTable<TableDef extends UntypedTableDef>(query:
|
|
21
|
-
toSql(): string;
|
|
22
|
-
} & Record<string, any>, callbacks?: UseTableCallbacks<Prettify<RowType<TableDef>>>): [
|
|
21
|
+
export declare function useTable<TableDef extends UntypedTableDef>(query: Query<TableDef>, callbacks?: UseTableCallbacks<Prettify<RowType<TableDef>>>): [
|
|
23
22
|
DeepReadonly<Ref<readonly Prettify<RowType<TableDef>>[]>>,
|
|
24
23
|
DeepReadonly<Ref<boolean>>
|
|
25
24
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTable.d.ts","sourceRoot":"","sources":["../../src/vue/useTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,YAAY,EACjB,KAAK,GAAG,EACT,MAAM,KAAK,CAAC;AAKb,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"useTable.d.ts","sourceRoot":"","sources":["../../src/vue/useTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,YAAY,EACjB,KAAK,GAAG,EACT,MAAM,KAAK,CAAC;AAKb,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EACL,KAAK,KAAK,EAMX,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,iBAAiB,CAAC,OAAO;IACxC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD;AAkBD;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,SAAS,eAAe,EACvD,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,EACtB,SAAS,CAAC,EAAE,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,GACzD;IACD,YAAY,CAAC,GAAG,CAAC,SAAS,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;IACzD,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;CAC3B,CAqKA"}
|
package/package.json
CHANGED
|
@@ -712,6 +712,7 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
|
|
|
712
712
|
}
|
|
713
713
|
case 'SubscriptionError': {
|
|
714
714
|
const querySetId = serverMessage.value.querySetId.id;
|
|
715
|
+
const requestId = serverMessage.value.requestId;
|
|
715
716
|
const error = Error(serverMessage.value.error);
|
|
716
717
|
const event: Event<never> = {
|
|
717
718
|
id: this.#nextEventId(),
|
|
@@ -723,6 +724,19 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
|
|
|
723
724
|
...eventContext,
|
|
724
725
|
event: error,
|
|
725
726
|
};
|
|
727
|
+
|
|
728
|
+
// If the requestId isn't set, that means we already applied the subscription.
|
|
729
|
+
// Since we don't know how to remove the relevant rows from our table cache, we need
|
|
730
|
+
// to kill the connection. Once we have per-query storage, this won't be fatal.
|
|
731
|
+
if (requestId == null) {
|
|
732
|
+
stdbLogger(
|
|
733
|
+
'error',
|
|
734
|
+
`Disconnecting due to error for a previously applied subscription: ${serverMessage.value.error}`
|
|
735
|
+
);
|
|
736
|
+
this.disconnect();
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
|
|
726
740
|
const subscription =
|
|
727
741
|
this.#subscriptionManager.subscriptions.get(querySetId);
|
|
728
742
|
if (subscription) {
|
|
@@ -740,7 +754,7 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
|
|
|
740
754
|
case 'TransactionUpdate': {
|
|
741
755
|
const event: Event<never> = {
|
|
742
756
|
id: this.#nextEventId(),
|
|
743
|
-
tag: '
|
|
757
|
+
tag: 'Transaction',
|
|
744
758
|
};
|
|
745
759
|
const eventContext = this.#makeEventContext(event);
|
|
746
760
|
const callbacks = this.#applyTransactionUpdates(
|
|
@@ -777,7 +791,7 @@ export class DbConnectionImpl<RemoteModule extends UntypedRemoteModule>
|
|
|
777
791
|
}
|
|
778
792
|
: {
|
|
779
793
|
id: eventId,
|
|
780
|
-
tag: '
|
|
794
|
+
tag: 'Transaction',
|
|
781
795
|
};
|
|
782
796
|
const eventContext = this.#makeEventContext(event as any);
|
|
783
797
|
|
package/src/sdk/event.ts
CHANGED
package/src/server/procedures.ts
CHANGED
|
@@ -101,12 +101,13 @@ function registerProcedure<
|
|
|
101
101
|
Ret extends TypeBuilder<any, any>,
|
|
102
102
|
>(
|
|
103
103
|
ctx: SchemaInner,
|
|
104
|
-
|
|
104
|
+
exportName: string,
|
|
105
105
|
params: Params,
|
|
106
106
|
ret: Ret,
|
|
107
|
-
fn: ProcedureFn<S, Params, Ret
|
|
107
|
+
fn: ProcedureFn<S, Params, Ret>,
|
|
108
|
+
opts?: ProcedureOpts
|
|
108
109
|
) {
|
|
109
|
-
ctx.defineFunction(
|
|
110
|
+
ctx.defineFunction(exportName);
|
|
110
111
|
const paramsType: ProductType = {
|
|
111
112
|
elements: Object.entries(params).map(([n, c]) => ({
|
|
112
113
|
name: n,
|
|
@@ -118,12 +119,21 @@ function registerProcedure<
|
|
|
118
119
|
const returnType = ctx.registerTypesRecursively(ret).algebraicType;
|
|
119
120
|
|
|
120
121
|
ctx.moduleDef.procedures.push({
|
|
121
|
-
sourceName:
|
|
122
|
+
sourceName: exportName,
|
|
122
123
|
params: paramsType,
|
|
123
124
|
returnType,
|
|
124
125
|
visibility: FunctionVisibility.ClientCallable,
|
|
125
126
|
});
|
|
126
127
|
|
|
128
|
+
if (opts?.name != null) {
|
|
129
|
+
ctx.moduleDef.explicitNames.entries.push({
|
|
130
|
+
tag: 'Function',
|
|
131
|
+
value: {
|
|
132
|
+
sourceName: exportName,
|
|
133
|
+
canonicalName: opts.name,
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
}
|
|
127
137
|
const { typespace } = ctx;
|
|
128
138
|
|
|
129
139
|
ctx.procedures.push({
|
package/src/server/reducers.ts
CHANGED
|
@@ -31,15 +31,13 @@ export function makeReducerExport<
|
|
|
31
31
|
fn: Reducer<any, any>,
|
|
32
32
|
lifecycle?: Lifecycle
|
|
33
33
|
): ReducerExport<S, Params> {
|
|
34
|
-
const name = opts?.name;
|
|
35
|
-
|
|
36
34
|
const reducerExport: ReducerExport<S, Params> = (...args) => fn(...args);
|
|
37
35
|
reducerExport[exportContext] = ctx;
|
|
38
36
|
reducerExport[registerExport] = (ctx, exportName) => {
|
|
39
|
-
registerReducer(ctx,
|
|
37
|
+
registerReducer(ctx, exportName, params, fn, opts, lifecycle);
|
|
40
38
|
ctx.functionExports.set(
|
|
41
39
|
reducerExport as ReducerExport<any, any>,
|
|
42
|
-
|
|
40
|
+
exportName
|
|
43
41
|
);
|
|
44
42
|
};
|
|
45
43
|
|
|
@@ -56,19 +54,20 @@ export function makeReducerExport<
|
|
|
56
54
|
*/
|
|
57
55
|
export function registerReducer(
|
|
58
56
|
ctx: SchemaInner,
|
|
59
|
-
|
|
57
|
+
exportName: string,
|
|
60
58
|
params: RowObj | RowBuilder<RowObj>,
|
|
61
59
|
fn: Reducer<any, any>,
|
|
60
|
+
opts?: ReducerOpts,
|
|
62
61
|
lifecycle?: Lifecycle
|
|
63
62
|
): void {
|
|
64
|
-
ctx.defineFunction(
|
|
63
|
+
ctx.defineFunction(exportName);
|
|
65
64
|
|
|
66
65
|
if (!(params instanceof RowBuilder)) {
|
|
67
66
|
params = new RowBuilder(params);
|
|
68
67
|
}
|
|
69
68
|
|
|
70
69
|
if (params.typeName === undefined) {
|
|
71
|
-
params.typeName = toPascalCase(
|
|
70
|
+
params.typeName = toPascalCase(exportName);
|
|
72
71
|
}
|
|
73
72
|
|
|
74
73
|
const ref = ctx.registerTypesRecursively(params);
|
|
@@ -76,7 +75,7 @@ export function registerReducer(
|
|
|
76
75
|
const isLifecycle = lifecycle != null;
|
|
77
76
|
|
|
78
77
|
ctx.moduleDef.reducers.push({
|
|
79
|
-
sourceName:
|
|
78
|
+
sourceName: exportName,
|
|
80
79
|
params: paramsType,
|
|
81
80
|
//ModuleDef validation code is responsible to mark private reducers
|
|
82
81
|
visibility: FunctionVisibility.ClientCallable,
|
|
@@ -85,17 +84,27 @@ export function registerReducer(
|
|
|
85
84
|
errReturnType: AlgebraicType.String,
|
|
86
85
|
});
|
|
87
86
|
|
|
87
|
+
if (opts?.name != null) {
|
|
88
|
+
ctx.moduleDef.explicitNames.entries.push({
|
|
89
|
+
tag: 'Function',
|
|
90
|
+
value: {
|
|
91
|
+
sourceName: exportName,
|
|
92
|
+
canonicalName: opts.name,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
88
97
|
if (isLifecycle) {
|
|
89
98
|
ctx.moduleDef.lifeCycleReducers.push({
|
|
90
99
|
lifecycleSpec: lifecycle,
|
|
91
|
-
functionName:
|
|
100
|
+
functionName: exportName,
|
|
92
101
|
});
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
// If the function isn't named (e.g. `function foobar() {}`), give it the same
|
|
96
105
|
// name as the reducer so that it's clear what it is in in backtraces.
|
|
97
106
|
if (!fn.name) {
|
|
98
|
-
Object.defineProperty(fn, 'name', { value:
|
|
107
|
+
Object.defineProperty(fn, 'name', { value: exportName, writable: false });
|
|
99
108
|
}
|
|
100
109
|
|
|
101
110
|
ctx.reducers.push(fn);
|
package/src/server/rng.ts
CHANGED
|
@@ -4,12 +4,6 @@ import { unsafeUniformIntDistribution } from 'pure-rand/distribution/UnsafeUnifo
|
|
|
4
4
|
import { xoroshiro128plus } from 'pure-rand/generator/XoroShiro';
|
|
5
5
|
import type { Timestamp } from '../lib/timestamp';
|
|
6
6
|
|
|
7
|
-
declare global {
|
|
8
|
-
interface Math {
|
|
9
|
-
random(): never;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
7
|
type IntArray =
|
|
14
8
|
| Int8Array
|
|
15
9
|
| Uint8Array
|
package/src/svelte/useTable.ts
CHANGED
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
evaluateBooleanExpr,
|
|
11
11
|
getQueryAccessorName,
|
|
12
12
|
getQueryWhereClause,
|
|
13
|
+
type Query,
|
|
14
|
+
toSql,
|
|
13
15
|
} from '../lib/query';
|
|
14
16
|
|
|
15
17
|
export interface UseTableCallbacks<RowType> {
|
|
@@ -46,13 +48,13 @@ function classifyMembership(
|
|
|
46
48
|
* @returns A tuple of [rows, isReady].
|
|
47
49
|
*/
|
|
48
50
|
export function useTable<TableDef extends UntypedTableDef>(
|
|
49
|
-
query:
|
|
51
|
+
query: Query<TableDef>,
|
|
50
52
|
callbacks?: UseTableCallbacks<Prettify<RowType<TableDef>>>
|
|
51
53
|
): [Readable<readonly Prettify<RowType<TableDef>>[]>, Readable<boolean>] {
|
|
52
54
|
type Row = RowType<TableDef>;
|
|
53
55
|
const accessorName = getQueryAccessorName(query);
|
|
54
56
|
const whereExpr = getQueryWhereClause(query);
|
|
55
|
-
const querySql =
|
|
57
|
+
const querySql = toSql(query);
|
|
56
58
|
|
|
57
59
|
let connectionStore;
|
|
58
60
|
try {
|
package/src/vue/useTable.ts
CHANGED
|
@@ -14,7 +14,9 @@ import type { UntypedRemoteModule } from '../sdk/spacetime_module';
|
|
|
14
14
|
import type { RowType, UntypedTableDef } from '../lib/table';
|
|
15
15
|
import type { Prettify } from '../lib/type_util';
|
|
16
16
|
import {
|
|
17
|
+
type Query,
|
|
17
18
|
type BooleanExpr,
|
|
19
|
+
toSql,
|
|
18
20
|
evaluateBooleanExpr,
|
|
19
21
|
getQueryAccessorName,
|
|
20
22
|
getQueryWhereClause,
|
|
@@ -54,7 +56,7 @@ function classifyMembership(
|
|
|
54
56
|
* @returns A tuple of [rows, isReady].
|
|
55
57
|
*/
|
|
56
58
|
export function useTable<TableDef extends UntypedTableDef>(
|
|
57
|
-
query:
|
|
59
|
+
query: Query<TableDef>,
|
|
58
60
|
callbacks?: UseTableCallbacks<Prettify<RowType<TableDef>>>
|
|
59
61
|
): [
|
|
60
62
|
DeepReadonly<Ref<readonly Prettify<RowType<TableDef>>[]>>,
|
|
@@ -63,7 +65,7 @@ export function useTable<TableDef extends UntypedTableDef>(
|
|
|
63
65
|
type Row = RowType<TableDef>;
|
|
64
66
|
const accessorName = getQueryAccessorName(query);
|
|
65
67
|
const whereExpr = getQueryWhereClause(query);
|
|
66
|
-
const querySql =
|
|
68
|
+
const querySql = toSql(query);
|
|
67
69
|
|
|
68
70
|
let conn;
|
|
69
71
|
try {
|