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/type_utils.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { Infer, InferTypeOfRow } from '.';
|
|
2
|
-
import type { Prettify } from '../lib/type_util';
|
|
3
|
-
import type { UntypedProcedureDef } from './procedures';
|
|
4
|
-
import type { UntypedReducerDef } from './reducers';
|
|
5
|
-
|
|
6
|
-
export type IsEmptyObject<T> = [keyof T] extends [never] ? true : false;
|
|
7
|
-
export type MaybeParams<T> = IsEmptyObject<T> extends true ? [] : [params: T];
|
|
8
|
-
|
|
9
|
-
export type ParamsType<R extends UntypedReducerDef> = MaybeParams<
|
|
10
|
-
Prettify<InferTypeOfRow<R['params']>>
|
|
11
|
-
>;
|
|
12
|
-
|
|
13
|
-
export type ProcedureParamsType<P extends UntypedProcedureDef> = MaybeParams<
|
|
14
|
-
Prettify<InferTypeOfRow<P['params']>>
|
|
15
|
-
>;
|
|
16
|
-
|
|
17
|
-
export type ProcedureReturnType<P extends UntypedProcedureDef> = Infer<
|
|
18
|
-
P['returnType']
|
|
19
|
-
>;
|
|
1
|
+
import type { Infer, InferTypeOfRow } from '.';
|
|
2
|
+
import type { Prettify } from '../lib/type_util';
|
|
3
|
+
import type { UntypedProcedureDef } from './procedures';
|
|
4
|
+
import type { UntypedReducerDef } from './reducers';
|
|
5
|
+
|
|
6
|
+
export type IsEmptyObject<T> = [keyof T] extends [never] ? true : false;
|
|
7
|
+
export type MaybeParams<T> = IsEmptyObject<T> extends true ? [] : [params: T];
|
|
8
|
+
|
|
9
|
+
export type ParamsType<R extends UntypedReducerDef> = MaybeParams<
|
|
10
|
+
Prettify<InferTypeOfRow<R['params']>>
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
export type ProcedureParamsType<P extends UntypedProcedureDef> = MaybeParams<
|
|
14
|
+
Prettify<InferTypeOfRow<P['params']>>
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
export type ProcedureReturnType<P extends UntypedProcedureDef> = Infer<
|
|
18
|
+
P['returnType']
|
|
19
|
+
>;
|
package/src/sdk/version.ts
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
export type PrereleaseId = string | number;
|
|
2
|
-
|
|
3
|
-
export type PreRelease = PrereleaseId[];
|
|
4
|
-
|
|
5
|
-
// Compare pre-release identifiers according to the semver spec (https://semver.org/#spec-item-11).
|
|
6
|
-
function comparePreReleases(a: PreRelease, b: PreRelease): number {
|
|
7
|
-
const len = Math.min(a.length, b.length);
|
|
8
|
-
for (let i = 0; i < len; i++) {
|
|
9
|
-
const aPart = a[i];
|
|
10
|
-
const bPart = b[i];
|
|
11
|
-
if (aPart === bPart) continue;
|
|
12
|
-
if (typeof aPart === 'number' && typeof bPart === 'number') {
|
|
13
|
-
return aPart - bPart;
|
|
14
|
-
}
|
|
15
|
-
if (typeof aPart === 'string' && typeof bPart === 'string') {
|
|
16
|
-
return aPart.localeCompare(bPart);
|
|
17
|
-
}
|
|
18
|
-
// According to item 11.4.3, numeric identifiers always have lower precedence than non-numeric identifiers.
|
|
19
|
-
// So if `a` is a string, it has higher precedence than `b`.
|
|
20
|
-
return typeof aPart === 'string' ? 1 : -1;
|
|
21
|
-
}
|
|
22
|
-
// See rule 11.4.4 in the semver spec.
|
|
23
|
-
return a.length - b.length;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// We don't use these, and they don't matter for version ordering, so I'm not going to parse it to spec.
|
|
27
|
-
export type BuildInfo = string;
|
|
28
|
-
|
|
29
|
-
// This is exported for tests.
|
|
30
|
-
export class SemanticVersion {
|
|
31
|
-
major: number;
|
|
32
|
-
minor: number;
|
|
33
|
-
patch: number;
|
|
34
|
-
preRelease: PreRelease | null;
|
|
35
|
-
buildInfo: BuildInfo | null;
|
|
36
|
-
|
|
37
|
-
constructor(
|
|
38
|
-
major: number,
|
|
39
|
-
minor: number,
|
|
40
|
-
patch: number,
|
|
41
|
-
preRelease: PreRelease | null = null,
|
|
42
|
-
buildInfo: BuildInfo | null = null
|
|
43
|
-
) {
|
|
44
|
-
this.major = major;
|
|
45
|
-
this.minor = minor;
|
|
46
|
-
this.patch = patch;
|
|
47
|
-
this.preRelease = preRelease;
|
|
48
|
-
this.buildInfo = buildInfo;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
toString(): string {
|
|
52
|
-
let versionString = `${this.major}.${this.minor}.${this.patch}`;
|
|
53
|
-
if (this.preRelease) {
|
|
54
|
-
versionString += `-${this.preRelease.join('.')}`;
|
|
55
|
-
}
|
|
56
|
-
if (this.buildInfo) {
|
|
57
|
-
versionString += `+${this.buildInfo}`;
|
|
58
|
-
}
|
|
59
|
-
return versionString;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
compare(other: SemanticVersion): number {
|
|
63
|
-
if (this.major !== other.major) {
|
|
64
|
-
return this.major - other.major;
|
|
65
|
-
}
|
|
66
|
-
if (this.minor !== other.minor) {
|
|
67
|
-
return this.minor - other.minor;
|
|
68
|
-
}
|
|
69
|
-
if (this.patch !== other.patch) {
|
|
70
|
-
return this.patch - other.patch;
|
|
71
|
-
}
|
|
72
|
-
if (this.preRelease && other.preRelease) {
|
|
73
|
-
return comparePreReleases(this.preRelease, other.preRelease);
|
|
74
|
-
}
|
|
75
|
-
if (this.preRelease) {
|
|
76
|
-
return -1; // The version without a pre-release is greater.
|
|
77
|
-
}
|
|
78
|
-
if (other.preRelease) {
|
|
79
|
-
return -1; // Since we don't have a pre-release, this version is greater.
|
|
80
|
-
}
|
|
81
|
-
return 0; // versions are equal
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
clone(): SemanticVersion {
|
|
85
|
-
return new SemanticVersion(
|
|
86
|
-
this.major,
|
|
87
|
-
this.minor,
|
|
88
|
-
this.patch,
|
|
89
|
-
this.preRelease ? [...this.preRelease] : null,
|
|
90
|
-
this.buildInfo
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
static parseVersionString(version: string): SemanticVersion {
|
|
95
|
-
const regex =
|
|
96
|
-
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?(?:\+([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?$/;
|
|
97
|
-
const match = version.match(regex);
|
|
98
|
-
if (!match) {
|
|
99
|
-
throw new Error(`Invalid version string: ${version}`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const major = parseInt(match[1], 10);
|
|
103
|
-
const minor = parseInt(match[2], 10);
|
|
104
|
-
const patch = parseInt(match[3], 10);
|
|
105
|
-
const preRelease = match[4]
|
|
106
|
-
? match[4].split('.').map(id => (isNaN(Number(id)) ? id : Number(id)))
|
|
107
|
-
: null;
|
|
108
|
-
const buildInfo = match[5] || null;
|
|
109
|
-
|
|
110
|
-
return new SemanticVersion(major, minor, patch, preRelease, buildInfo);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// The SDK depends on some module information that was not generated before this version.
|
|
115
|
-
export const _MINIMUM_CLI_VERSION: SemanticVersion = new SemanticVersion(
|
|
116
|
-
1,
|
|
117
|
-
4,
|
|
118
|
-
0
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
export function ensureMinimumVersionOrThrow(versionString?: string): void {
|
|
122
|
-
if (versionString === undefined) {
|
|
123
|
-
throw new Error(versionErrorMessage(versionString));
|
|
124
|
-
}
|
|
125
|
-
const version = SemanticVersion.parseVersionString(versionString);
|
|
126
|
-
if (version.compare(_MINIMUM_CLI_VERSION) < 0) {
|
|
127
|
-
throw new Error(versionErrorMessage(versionString));
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function versionErrorMessage(incompatibleVersion?: string): string {
|
|
132
|
-
return `Module code was generated with an incompatible version of the spacetimedb cli (${incompatibleVersion}). Update the cli version to at least ${_MINIMUM_CLI_VERSION.toString()} and regenerate the bindings. You can upgrade to the latest cli version by running: spacetime version upgrade`;
|
|
133
|
-
}
|
|
1
|
+
export type PrereleaseId = string | number;
|
|
2
|
+
|
|
3
|
+
export type PreRelease = PrereleaseId[];
|
|
4
|
+
|
|
5
|
+
// Compare pre-release identifiers according to the semver spec (https://semver.org/#spec-item-11).
|
|
6
|
+
function comparePreReleases(a: PreRelease, b: PreRelease): number {
|
|
7
|
+
const len = Math.min(a.length, b.length);
|
|
8
|
+
for (let i = 0; i < len; i++) {
|
|
9
|
+
const aPart = a[i];
|
|
10
|
+
const bPart = b[i];
|
|
11
|
+
if (aPart === bPart) continue;
|
|
12
|
+
if (typeof aPart === 'number' && typeof bPart === 'number') {
|
|
13
|
+
return aPart - bPart;
|
|
14
|
+
}
|
|
15
|
+
if (typeof aPart === 'string' && typeof bPart === 'string') {
|
|
16
|
+
return aPart.localeCompare(bPart);
|
|
17
|
+
}
|
|
18
|
+
// According to item 11.4.3, numeric identifiers always have lower precedence than non-numeric identifiers.
|
|
19
|
+
// So if `a` is a string, it has higher precedence than `b`.
|
|
20
|
+
return typeof aPart === 'string' ? 1 : -1;
|
|
21
|
+
}
|
|
22
|
+
// See rule 11.4.4 in the semver spec.
|
|
23
|
+
return a.length - b.length;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// We don't use these, and they don't matter for version ordering, so I'm not going to parse it to spec.
|
|
27
|
+
export type BuildInfo = string;
|
|
28
|
+
|
|
29
|
+
// This is exported for tests.
|
|
30
|
+
export class SemanticVersion {
|
|
31
|
+
major: number;
|
|
32
|
+
minor: number;
|
|
33
|
+
patch: number;
|
|
34
|
+
preRelease: PreRelease | null;
|
|
35
|
+
buildInfo: BuildInfo | null;
|
|
36
|
+
|
|
37
|
+
constructor(
|
|
38
|
+
major: number,
|
|
39
|
+
minor: number,
|
|
40
|
+
patch: number,
|
|
41
|
+
preRelease: PreRelease | null = null,
|
|
42
|
+
buildInfo: BuildInfo | null = null
|
|
43
|
+
) {
|
|
44
|
+
this.major = major;
|
|
45
|
+
this.minor = minor;
|
|
46
|
+
this.patch = patch;
|
|
47
|
+
this.preRelease = preRelease;
|
|
48
|
+
this.buildInfo = buildInfo;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toString(): string {
|
|
52
|
+
let versionString = `${this.major}.${this.minor}.${this.patch}`;
|
|
53
|
+
if (this.preRelease) {
|
|
54
|
+
versionString += `-${this.preRelease.join('.')}`;
|
|
55
|
+
}
|
|
56
|
+
if (this.buildInfo) {
|
|
57
|
+
versionString += `+${this.buildInfo}`;
|
|
58
|
+
}
|
|
59
|
+
return versionString;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
compare(other: SemanticVersion): number {
|
|
63
|
+
if (this.major !== other.major) {
|
|
64
|
+
return this.major - other.major;
|
|
65
|
+
}
|
|
66
|
+
if (this.minor !== other.minor) {
|
|
67
|
+
return this.minor - other.minor;
|
|
68
|
+
}
|
|
69
|
+
if (this.patch !== other.patch) {
|
|
70
|
+
return this.patch - other.patch;
|
|
71
|
+
}
|
|
72
|
+
if (this.preRelease && other.preRelease) {
|
|
73
|
+
return comparePreReleases(this.preRelease, other.preRelease);
|
|
74
|
+
}
|
|
75
|
+
if (this.preRelease) {
|
|
76
|
+
return -1; // The version without a pre-release is greater.
|
|
77
|
+
}
|
|
78
|
+
if (other.preRelease) {
|
|
79
|
+
return -1; // Since we don't have a pre-release, this version is greater.
|
|
80
|
+
}
|
|
81
|
+
return 0; // versions are equal
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
clone(): SemanticVersion {
|
|
85
|
+
return new SemanticVersion(
|
|
86
|
+
this.major,
|
|
87
|
+
this.minor,
|
|
88
|
+
this.patch,
|
|
89
|
+
this.preRelease ? [...this.preRelease] : null,
|
|
90
|
+
this.buildInfo
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static parseVersionString(version: string): SemanticVersion {
|
|
95
|
+
const regex =
|
|
96
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?(?:\+([\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*))?$/;
|
|
97
|
+
const match = version.match(regex);
|
|
98
|
+
if (!match) {
|
|
99
|
+
throw new Error(`Invalid version string: ${version}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const major = parseInt(match[1], 10);
|
|
103
|
+
const minor = parseInt(match[2], 10);
|
|
104
|
+
const patch = parseInt(match[3], 10);
|
|
105
|
+
const preRelease = match[4]
|
|
106
|
+
? match[4].split('.').map(id => (isNaN(Number(id)) ? id : Number(id)))
|
|
107
|
+
: null;
|
|
108
|
+
const buildInfo = match[5] || null;
|
|
109
|
+
|
|
110
|
+
return new SemanticVersion(major, minor, patch, preRelease, buildInfo);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// The SDK depends on some module information that was not generated before this version.
|
|
115
|
+
export const _MINIMUM_CLI_VERSION: SemanticVersion = new SemanticVersion(
|
|
116
|
+
1,
|
|
117
|
+
4,
|
|
118
|
+
0
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export function ensureMinimumVersionOrThrow(versionString?: string): void {
|
|
122
|
+
if (versionString === undefined) {
|
|
123
|
+
throw new Error(versionErrorMessage(versionString));
|
|
124
|
+
}
|
|
125
|
+
const version = SemanticVersion.parseVersionString(versionString);
|
|
126
|
+
if (version.compare(_MINIMUM_CLI_VERSION) < 0) {
|
|
127
|
+
throw new Error(versionErrorMessage(versionString));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function versionErrorMessage(incompatibleVersion?: string): string {
|
|
132
|
+
return `Module code was generated with an incompatible version of the spacetimedb cli (${incompatibleVersion}). Update the cli version to at least ${_MINIMUM_CLI_VERSION.toString()} and regenerate the bindings. You can upgrade to the latest cli version by running: spacetime version upgrade`;
|
|
133
|
+
}
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { decompress } from './decompress';
|
|
2
|
-
import { openWebSocket, type WebSocketAdapter, type WebSocketArgs } from './ws';
|
|
3
|
-
|
|
4
|
-
export class WebsocketDecompressAdapter implements WebSocketAdapter {
|
|
5
|
-
get protocol(): string {
|
|
6
|
-
return this.#ws.protocol;
|
|
7
|
-
}
|
|
8
|
-
set onclose(handler: (ev: CloseEvent) => void) {
|
|
9
|
-
this.#ws.onclose = handler;
|
|
10
|
-
}
|
|
11
|
-
set onopen(handler: () => void) {
|
|
12
|
-
this.#ws.onopen = handler;
|
|
13
|
-
}
|
|
14
|
-
set onmessage(handler: (msg: { data: Uint8Array }) => void) {
|
|
15
|
-
this.#ws.onmessage = async (msg: MessageEvent<ArrayBuffer>) => {
|
|
16
|
-
const data = await this.#decompress(new Uint8Array(msg.data));
|
|
17
|
-
handler({ data });
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
set onerror(handler: (msg: ErrorEvent) => void) {
|
|
21
|
-
this.#ws.onerror = handler as (msg: Event) => void;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
#ws: WebSocket;
|
|
25
|
-
|
|
26
|
-
async #decompress(buffer: Uint8Array<ArrayBuffer>): Promise<Uint8Array> {
|
|
27
|
-
const tag = buffer[0];
|
|
28
|
-
const data = buffer.subarray(1);
|
|
29
|
-
switch (tag) {
|
|
30
|
-
case 0:
|
|
31
|
-
return data;
|
|
32
|
-
case 1:
|
|
33
|
-
// Some runtimes support brotli, but it's not yet defined in `lib.dom.d.ts`.
|
|
34
|
-
// We assert runtime support in `DbConnectionBuilder.withCompression`, so
|
|
35
|
-
// this cast is safe.
|
|
36
|
-
return await decompress(data, 'brotli' as CompressionFormat);
|
|
37
|
-
case 2:
|
|
38
|
-
return await decompress(data, 'gzip');
|
|
39
|
-
default:
|
|
40
|
-
throw new Error(
|
|
41
|
-
'Unexpected Compression Algorithm. Please use `gzip` or `none`'
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
send(msg: Uint8Array<ArrayBuffer>): void {
|
|
47
|
-
this.#ws.send(msg);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
close(): void {
|
|
51
|
-
this.#ws.close();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
constructor(ws: WebSocket) {
|
|
55
|
-
this.#ws = ws;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static async openWebSocket(
|
|
59
|
-
args: WebSocketArgs
|
|
60
|
-
): Promise<WebsocketDecompressAdapter> {
|
|
61
|
-
return new WebsocketDecompressAdapter(await openWebSocket(args));
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
import { decompress } from './decompress';
|
|
2
|
+
import { openWebSocket, type WebSocketAdapter, type WebSocketArgs } from './ws';
|
|
3
|
+
|
|
4
|
+
export class WebsocketDecompressAdapter implements WebSocketAdapter {
|
|
5
|
+
get protocol(): string {
|
|
6
|
+
return this.#ws.protocol;
|
|
7
|
+
}
|
|
8
|
+
set onclose(handler: (ev: CloseEvent) => void) {
|
|
9
|
+
this.#ws.onclose = handler;
|
|
10
|
+
}
|
|
11
|
+
set onopen(handler: () => void) {
|
|
12
|
+
this.#ws.onopen = handler;
|
|
13
|
+
}
|
|
14
|
+
set onmessage(handler: (msg: { data: Uint8Array }) => void) {
|
|
15
|
+
this.#ws.onmessage = async (msg: MessageEvent<ArrayBuffer>) => {
|
|
16
|
+
const data = await this.#decompress(new Uint8Array(msg.data));
|
|
17
|
+
handler({ data });
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
set onerror(handler: (msg: ErrorEvent) => void) {
|
|
21
|
+
this.#ws.onerror = handler as (msg: Event) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#ws: WebSocket;
|
|
25
|
+
|
|
26
|
+
async #decompress(buffer: Uint8Array<ArrayBuffer>): Promise<Uint8Array> {
|
|
27
|
+
const tag = buffer[0];
|
|
28
|
+
const data = buffer.subarray(1);
|
|
29
|
+
switch (tag) {
|
|
30
|
+
case 0:
|
|
31
|
+
return data;
|
|
32
|
+
case 1:
|
|
33
|
+
// Some runtimes support brotli, but it's not yet defined in `lib.dom.d.ts`.
|
|
34
|
+
// We assert runtime support in `DbConnectionBuilder.withCompression`, so
|
|
35
|
+
// this cast is safe.
|
|
36
|
+
return await decompress(data, 'brotli' as CompressionFormat);
|
|
37
|
+
case 2:
|
|
38
|
+
return await decompress(data, 'gzip');
|
|
39
|
+
default:
|
|
40
|
+
throw new Error(
|
|
41
|
+
'Unexpected Compression Algorithm. Please use `gzip` or `none`'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
send(msg: Uint8Array<ArrayBuffer>): void {
|
|
47
|
+
this.#ws.send(msg);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
close(): void {
|
|
51
|
+
this.#ws.close();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
constructor(ws: WebSocket) {
|
|
55
|
+
this.#ws = ws;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static async openWebSocket(
|
|
59
|
+
args: WebSocketArgs
|
|
60
|
+
): Promise<WebsocketDecompressAdapter> {
|
|
61
|
+
return new WebsocketDecompressAdapter(await openWebSocket(args));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { stdbLogger } from './logger.ts';
|
|
2
|
-
|
|
3
|
-
export const V2_WS_PROTOCOL = 'v2.bsatn.spacetimedb';
|
|
4
|
-
export const V3_WS_PROTOCOL = 'v3.bsatn.spacetimedb';
|
|
5
|
-
export const PREFERRED_WS_PROTOCOLS = [V3_WS_PROTOCOL, V2_WS_PROTOCOL] as const;
|
|
6
|
-
|
|
7
|
-
export type NegotiatedWsProtocol =
|
|
8
|
-
| typeof V2_WS_PROTOCOL
|
|
9
|
-
| typeof V3_WS_PROTOCOL;
|
|
10
|
-
|
|
11
|
-
export function normalizeWsProtocol(protocol: string): NegotiatedWsProtocol {
|
|
12
|
-
if (protocol === V3_WS_PROTOCOL) {
|
|
13
|
-
return V3_WS_PROTOCOL;
|
|
14
|
-
}
|
|
15
|
-
// We treat an empty negotiated subprotocol as legacy v2 for compatibility.
|
|
16
|
-
if (protocol === '' || protocol === V2_WS_PROTOCOL) {
|
|
17
|
-
return V2_WS_PROTOCOL;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
stdbLogger(
|
|
21
|
-
'warn',
|
|
22
|
-
`Unexpected websocket subprotocol "${protocol}", falling back to ${V2_WS_PROTOCOL}.`
|
|
23
|
-
);
|
|
24
|
-
return V2_WS_PROTOCOL;
|
|
25
|
-
}
|
|
1
|
+
import { stdbLogger } from './logger.ts';
|
|
2
|
+
|
|
3
|
+
export const V2_WS_PROTOCOL = 'v2.bsatn.spacetimedb';
|
|
4
|
+
export const V3_WS_PROTOCOL = 'v3.bsatn.spacetimedb';
|
|
5
|
+
export const PREFERRED_WS_PROTOCOLS = [V3_WS_PROTOCOL, V2_WS_PROTOCOL] as const;
|
|
6
|
+
|
|
7
|
+
export type NegotiatedWsProtocol =
|
|
8
|
+
| typeof V2_WS_PROTOCOL
|
|
9
|
+
| typeof V3_WS_PROTOCOL;
|
|
10
|
+
|
|
11
|
+
export function normalizeWsProtocol(protocol: string): NegotiatedWsProtocol {
|
|
12
|
+
if (protocol === V3_WS_PROTOCOL) {
|
|
13
|
+
return V3_WS_PROTOCOL;
|
|
14
|
+
}
|
|
15
|
+
// We treat an empty negotiated subprotocol as legacy v2 for compatibility.
|
|
16
|
+
if (protocol === '' || protocol === V2_WS_PROTOCOL) {
|
|
17
|
+
return V2_WS_PROTOCOL;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
stdbLogger(
|
|
21
|
+
'warn',
|
|
22
|
+
`Unexpected websocket subprotocol "${protocol}", falling back to ${V2_WS_PROTOCOL}.`
|
|
23
|
+
);
|
|
24
|
+
return V2_WS_PROTOCOL;
|
|
25
|
+
}
|