1- import { AlgebraicType } from '../lib/algebraic_type' ;
1+ import * as _syscalls1_0 from 'spacetime:sys@1.0' ;
2+ import * as _syscalls1_2 from 'spacetime:sys@1.2' ;
3+
4+ import type { ModuleHooks , u16 , u32 } from 'spacetime:sys@1.0' ;
5+ import { AlgebraicType , ProductType } from '../lib/algebraic_type' ;
26import RawModuleDef from '../lib/autogen/raw_module_def_type' ;
37import type RawModuleDefV9 from '../lib/autogen/raw_module_def_v_9_type' ;
48import type RawTableDefV9 from '../lib/autogen/raw_table_def_v_9_type' ;
59import type Typespace from '../lib/autogen/typespace_type' ;
6- import { ConnectionId } from '../lib/connection_id' ;
7- import { Identity } from '../lib/identity' ;
8- import { Timestamp } from '../lib/timestamp' ;
910import BinaryReader from '../lib/binary_reader' ;
1011import BinaryWriter from '../lib/binary_writer' ;
11- import { SenderError , SpacetimeHostError } from './errors ' ;
12- import { Range , type Bound } from './range ' ;
12+ import { ConnectionId } from '../lib/connection_id ' ;
13+ import { Identity } from '../lib/identity ' ;
1314import {
1415 type Index ,
1516 type IndexVal ,
16- type UniqueIndex ,
1717 type RangedIndex ,
18+ type UniqueIndex ,
1819} from '../lib/indexes' ;
19- import { type RowType , type Table , type TableMethods } from '../lib/table ' ;
20+ import { callProcedure } from './procedures ' ;
2021import {
21- type ReducerCtx ,
2222 REDUCERS ,
23- type JwtClaims ,
2423 type AuthCtx ,
2524 type JsonObject ,
25+ type JwtClaims ,
26+ type ReducerCtx ,
2627} from '../lib/reducers' ;
2728import { MODULE_DEF } from '../lib/schema' ;
28-
29- import * as _syscalls from 'spacetime:sys@1.0' ;
30- import type { u16 , u32 , ModuleHooks } from 'spacetime:sys@1.0' ;
31- import type { DbView } from './db_view' ;
32- import { toCamelCase } from '../lib/util' ;
29+ import { type RowType , type Table , type TableMethods } from '../lib/table' ;
30+ import { Timestamp } from '../lib/timestamp' ;
3331import type { Infer } from '../lib/type_builders' ;
34- import { bsatnBaseSize } from '../lib/util' ;
32+ import { bsatnBaseSize , toCamelCase } from '../lib/util' ;
3533import {
3634 ANON_VIEWS ,
3735 VIEWS ,
3836 type AnonymousViewCtx ,
3937 type ViewCtx ,
4038} from '../lib/views' ;
39+ import type { DbView } from './db_view' ;
40+ import { SenderError , SpacetimeHostError } from './errors' ;
41+ import { Range , type Bound } from './range' ;
4142
4243const { freeze } = Object ;
4344
44- const sys : typeof _syscalls = freeze (
45- Object . fromEntries (
46- Object . entries ( _syscalls ) . map ( ( [ name , syscall ] ) => [
47- name ,
48- wrapSyscall ( syscall ) ,
49- ] )
50- ) as typeof _syscalls
51- ) ;
45+ export const sys = freeze ( wrapSyscalls ( _syscalls1_0 , _syscalls1_2 ) ) ;
5246
5347export function parseJsonObject ( json : string ) : JsonObject {
5448 let value : unknown ;
@@ -235,9 +229,9 @@ export const hooks_v1_1: import('spacetime:sys@1.1').ModuleHooks = {
235229 // at runtime
236230 db : getDbView ( ) ,
237231 } ) ;
238- const args = AlgebraicType . deserializeValue (
232+ const args = ProductType . deserializeValue (
239233 new BinaryReader ( argsBuf ) ,
240- AlgebraicType . Product ( params ) ,
234+ params ,
241235 MODULE_DEF . typespace
242236 ) ;
243237 const ret = fn ( ctx , args ) ;
@@ -253,9 +247,9 @@ export const hooks_v1_1: import('spacetime:sys@1.1').ModuleHooks = {
253247 // at runtime
254248 db : getDbView ( ) ,
255249 } ) ;
256- const args = AlgebraicType . deserializeValue (
250+ const args = ProductType . deserializeValue (
257251 new BinaryReader ( argsBuf ) ,
258- AlgebraicType . Product ( params ) ,
252+ params ,
259253 MODULE_DEF . typespace
260254 ) ;
261255 const ret = fn ( ctx , args ) ;
@@ -265,6 +259,18 @@ export const hooks_v1_1: import('spacetime:sys@1.1').ModuleHooks = {
265259 } ,
266260} ;
267261
262+ export const hooks_v1_2 : import ( 'spacetime:sys@1.2' ) . ModuleHooks = {
263+ __call_procedure__ ( id , sender , connection_id , timestamp , args ) {
264+ return callProcedure (
265+ id ,
266+ new Identity ( sender ) ,
267+ ConnectionId . nullIfZero ( new ConnectionId ( connection_id ) ) ,
268+ new Timestamp ( timestamp ) ,
269+ args
270+ ) ;
271+ } ,
272+ } ;
273+
268274let DB_VIEW : DbView < any > | null = null ;
269275function getDbView ( ) {
270276 DB_VIEW ??= makeDbView ( MODULE_DEF ) ;
@@ -587,6 +593,21 @@ class TableIterator implements IterableIterator<any, undefined> {
587593 }
588594}
589595
596+ type Intersections < Ts extends readonly any [ ] > = Ts extends [
597+ infer T ,
598+ ...infer Rest ,
599+ ]
600+ ? T & Intersections < Rest >
601+ : unknown ;
602+
603+ function wrapSyscalls <
604+ Modules extends Record < string , ( ...args : any [ ] ) => any > [ ] ,
605+ > ( ...modules : Modules ) : Intersections < Modules > {
606+ return Object . fromEntries (
607+ modules . flatMap ( Object . entries ) . map ( ( [ k , v ] ) => [ k , wrapSyscall ( v ) ] )
608+ ) as Intersections < Modules > ;
609+ }
610+
590611function wrapSyscall < F extends ( ...args : any [ ] ) => any > (
591612 func : F
592613) : ( ...args : Parameters < F > ) => ReturnType < F > {
0 commit comments