diff --git a/crates/bindings-typescript/src/server/schema.ts b/crates/bindings-typescript/src/server/schema.ts index d9cdede9a3f..72c8b58aaa8 100644 --- a/crates/bindings-typescript/src/server/schema.ts +++ b/crates/bindings-typescript/src/server/schema.ts @@ -26,6 +26,7 @@ import { defineView, type AnonymousViewFn, type ViewFn, + type ViewOpts, type ViewReturnTypeBuilder, } from './views'; @@ -282,27 +283,27 @@ class Schema { } view( - name: string, + opts: ViewOpts, ret: Ret, fn: ViewFn ): void { - defineView(name, false, {}, ret, fn); + defineView(opts, false, {}, ret, fn); } // TODO: re-enable once parameterized views are supported in SQL // view( - // name: string, + // opts: ViewOpts, // ret: Ret, // fn: ViewFn // ): void; // view( - // name: string, + // opts: ViewOpts, // params: Params, // ret: Ret, // fn: ViewFn // ): void; // view( - // name: string, + // opts: ViewOpts, // paramsOrRet: Ret | Params, // retOrFn: ViewFn | Ret, // maybeFn?: ViewFn @@ -315,27 +316,27 @@ class Schema { // } anyonymousView( - name: string, + opts: ViewOpts, ret: Ret, fn: AnonymousViewFn ): void { - defineView(name, true, {}, ret, fn); + defineView(opts, true, {}, ret, fn); } // TODO: re-enable once parameterized views are supported in SQL // anyonymousView( - // name: string, + // opts: ViewOpts, // ret: Ret, // fn: AnonymousViewFn // ): void; // anyonymousView( - // name: string, + // opts: ViewOpts, // params: Params, // ret: Ret, // fn: AnonymousViewFn // ): void; // anyonymousView( - // name: string, + // opts: ViewOpts, // paramsOrRet: Ret | Params, // retOrFn: AnonymousViewFn | Ret, // maybeFn?: AnonymousViewFn diff --git a/crates/bindings-typescript/src/server/views.ts b/crates/bindings-typescript/src/server/views.ts index b4a5fbd0b23..e2a378d7a28 100644 --- a/crates/bindings-typescript/src/server/views.ts +++ b/crates/bindings-typescript/src/server/views.ts @@ -24,6 +24,11 @@ export type ReadonlyDbView = { readonly [Tbl in SchemaDef['tables'][number] as Tbl['name']]: ReadonlyTable; }; +export type ViewOpts = { + name: string; + public: true; +}; + export type ViewFn< S extends UntypedSchemaDef, Params extends ParamsObj, @@ -52,7 +57,7 @@ export function defineView< Params extends ParamsObj, Ret extends ViewReturnTypeBuilder, >( - name: string, + opts: ViewOpts, anon: Anonymous, params: Params, ret: Ret, @@ -70,9 +75,9 @@ export function defineView< MODULE_DEF.miscExports.push({ tag: 'View', value: { - name, + name: opts.name, index: (anon ? ANON_VIEWS : VIEWS).length, - isPublic: true, + isPublic: opts.public, isAnonymous: anon, params: paramType, returnType: ret.algebraicType, diff --git a/modules/module-test-ts/src/index.ts b/modules/module-test-ts/src/index.ts index a72225cfa84..57879732a00 100644 --- a/modules/module-test-ts/src/index.ts +++ b/modules/module-test-ts/src/index.ts @@ -219,7 +219,7 @@ const spacetimedb = schema( // ───────────────────────────────────────────────────────────────────────────── spacetimedb.view( - 'my_player', + { name: 'my_player', public: true }, playerLikeRow.optional(), // FIXME: this should not be necessary; change `OptionBuilder` to accept `null|undefined` for `none` ctx => ctx.db.player.identity.find(ctx.sender) ?? undefined