From e07264270ee9a803a52a7c4a566f574c8be335ff Mon Sep 17 00:00:00 2001 From: Alessandro Asoni Date: Tue, 2 Apr 2024 10:56:23 +0200 Subject: [PATCH] Add dist folder to release-alpha --- dist/address.d.ts | 27 + dist/address.js | 80 ++ dist/algebraic_type.d.ts | 163 ++++ dist/algebraic_type.js | 244 +++++ dist/algebraic_value.d.ts | 153 ++++ dist/algebraic_value.js | 408 +++++++++ dist/binary_reader.d.ts | 22 + dist/binary_reader.js | 100 ++ dist/binary_writer.d.ts | 24 + dist/binary_writer.js | 118 +++ dist/client_api.d.ts | 1479 ++++++++++++++++++++++++++++++ dist/client_api.js | 1240 +++++++++++++++++++++++++ dist/client_db.d.ts | 16 + dist/client_db.js | 39 + dist/database_table.d.ts | 28 + dist/database_table.js | 44 + dist/global.d.ts | 12 + dist/global.js | 2 + dist/identity.d.ts | 23 + dist/identity.js | 54 ++ dist/index.d.ts | 5 + dist/index.js | 21 + dist/json_api.d.ts | 39 + dist/json_api.js | 2 + dist/logger.d.ts | 3 + dist/logger.js | 28 + dist/message_types.d.ts | 28 + dist/message_types.js | 49 + dist/operations_map.d.ts | 9 + dist/operations_map.js | 39 + dist/reducer.d.ts | 15 + dist/reducer.js | 32 + dist/reducer_event.d.ts | 11 + dist/reducer_event.js | 20 + dist/serializer.d.ts | 23 + dist/serializer.js | 187 ++++ dist/spacetimedb.d.ts | 235 +++++ dist/spacetimedb.js | 683 ++++++++++++++ dist/table.d.ts | 118 +++ dist/table.js | 222 +++++ dist/tsconfig.tsbuildinfo | 1 + dist/types.d.ts | 1 + dist/types.js | 2 + dist/utils.d.ts | 3 + dist/utils.js | 30 + dist/websocket_test_adapter.d.ts | 15 + dist/websocket_test_adapter.js | 30 + 47 files changed, 6127 insertions(+) create mode 100644 dist/address.d.ts create mode 100644 dist/address.js create mode 100644 dist/algebraic_type.d.ts create mode 100644 dist/algebraic_type.js create mode 100644 dist/algebraic_value.d.ts create mode 100644 dist/algebraic_value.js create mode 100644 dist/binary_reader.d.ts create mode 100644 dist/binary_reader.js create mode 100644 dist/binary_writer.d.ts create mode 100644 dist/binary_writer.js create mode 100644 dist/client_api.d.ts create mode 100644 dist/client_api.js create mode 100644 dist/client_db.d.ts create mode 100644 dist/client_db.js create mode 100644 dist/database_table.d.ts create mode 100644 dist/database_table.js create mode 100644 dist/global.d.ts create mode 100644 dist/global.js create mode 100644 dist/identity.d.ts create mode 100644 dist/identity.js create mode 100644 dist/index.d.ts create mode 100644 dist/index.js create mode 100644 dist/json_api.d.ts create mode 100644 dist/json_api.js create mode 100644 dist/logger.d.ts create mode 100644 dist/logger.js create mode 100644 dist/message_types.d.ts create mode 100644 dist/message_types.js create mode 100644 dist/operations_map.d.ts create mode 100644 dist/operations_map.js create mode 100644 dist/reducer.d.ts create mode 100644 dist/reducer.js create mode 100644 dist/reducer_event.d.ts create mode 100644 dist/reducer_event.js create mode 100644 dist/serializer.d.ts create mode 100644 dist/serializer.js create mode 100644 dist/spacetimedb.d.ts create mode 100644 dist/spacetimedb.js create mode 100644 dist/table.d.ts create mode 100644 dist/table.js create mode 100644 dist/tsconfig.tsbuildinfo create mode 100644 dist/types.d.ts create mode 100644 dist/types.js create mode 100644 dist/utils.d.ts create mode 100644 dist/utils.js create mode 100644 dist/websocket_test_adapter.d.ts create mode 100644 dist/websocket_test_adapter.js diff --git a/dist/address.d.ts b/dist/address.d.ts new file mode 100644 index 0000000..ca0ab24 --- /dev/null +++ b/dist/address.d.ts @@ -0,0 +1,27 @@ +/** + * A unique public identifier for a client connected to a database. + */ +export declare class Address { + private data; + /** + * Creates a new `Address`. + */ + constructor(data: Uint8Array); + private isZero; + static nullIfZero(data: Uint8Array): Address | null; + static random(): Address; + /** + * Compare two addresses for equality. + */ + isEqual(other: Address): boolean; + /** + * Print the address as a hexadecimal string. + */ + toHexString(): string; + toUint8Array(): Uint8Array; + /** + * Parse an Address from a hexadecimal string. + */ + static fromString(str: string): Address; + static fromStringOrNull(str: string): Address | null; +} diff --git a/dist/address.js b/dist/address.js new file mode 100644 index 0000000..f943bc5 --- /dev/null +++ b/dist/address.js @@ -0,0 +1,80 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Address = void 0; +/** + * A unique public identifier for a client connected to a database. + */ +class Address { + data; + /** + * Creates a new `Address`. + */ + constructor(data) { + this.data = data; + } + isZero() { + return this.data.every((b) => b == 0); + } + static nullIfZero(data) { + let addr = new Address(data); + if (addr.isZero()) { + return null; + } + else { + return addr; + } + } + static random() { + function randomByte() { + return Math.floor(Math.random() * 255); + } + let data = new Uint8Array(16); + for (let i = 0; i < 16; i++) { + data[i] = randomByte(); + } + return new Address(data); + } + /** + * Compare two addresses for equality. + */ + isEqual(other) { + if (this.data.length !== other.data.length) { + return false; + } + for (let i = 0; i < this.data.length; i++) { + if (this.data[i] !== other.data[i]) { + return false; + } + } + return true; + } + /** + * Print the address as a hexadecimal string. + */ + toHexString() { + return Array.prototype.map + .call(this.data, (x) => ("00" + x.toString(16)).slice(-2)) + .join(""); + } + toUint8Array() { + return this.data; + } + /** + * Parse an Address from a hexadecimal string. + */ + static fromString(str) { + let matches = str.match(/.{1,2}/g) || []; + let data = Uint8Array.from(matches.map((byte) => parseInt(byte, 16))); + return new Address(data); + } + static fromStringOrNull(str) { + let addr = Address.fromString(str); + if (addr.isZero()) { + return null; + } + else { + return addr; + } + } +} +exports.Address = Address; diff --git a/dist/algebraic_type.d.ts b/dist/algebraic_type.d.ts new file mode 100644 index 0000000..bdb2578 --- /dev/null +++ b/dist/algebraic_type.d.ts @@ -0,0 +1,163 @@ +/** + * A variant of a sum type. + * + * NOTE: Each element has an implicit element tag based on its order. + * Uniquely identifies an element similarly to protobuf tags. + */ +export declare class SumTypeVariant { + name: string; + algebraicType: AlgebraicType; + constructor(name: string, algebraicType: AlgebraicType); +} +/** +* Unlike most languages, sums in SATS are *[structural]* and not nominal. +* When checking whether two nominal types are the same, +* their names and/or declaration sites (e.g., module / namespace) are considered. +* Meanwhile, a structural type system would only check the structure of the type itself, +* e.g., the names of its variants and their inner data types in the case of a sum. +* +* This is also known as a discriminated union (implementation) or disjoint union. +* Another name is [coproduct (category theory)](https://ncatlab.org/nlab/show/coproduct). +* +* These structures are known as sum types because the number of possible values a sum +* ```ignore +* { N_0(T_0), N_1(T_1), ..., N_n(T_n) } +* ``` +* is: +* ```ignore +* Σ (i ∈ 0..n). values(T_i) +* ``` +* so for example, `values({ A(U64), B(Bool) }) = values(U64) + values(Bool)`. +* +* See also: https://ncatlab.org/nlab/show/sum+type. +* +* [structural]: https://en.wikipedia.org/wiki/Structural_type_system +*/ +export declare class SumType { + variants: SumTypeVariant[]; + constructor(variants: SumTypeVariant[]); +} +/** +* A factor / element of a product type. +* +* An element consist of an optional name and a type. +* +* NOTE: Each element has an implicit element tag based on its order. +* Uniquely identifies an element similarly to protobuf tags. +*/ +export declare class ProductTypeElement { + name: string; + algebraicType: AlgebraicType; + constructor(name: string, algebraicType: AlgebraicType); +} +/** +* A structural product type of the factors given by `elements`. +* +* This is also known as `struct` and `tuple` in many languages, +* but note that unlike most languages, products in SATs are *[structural]* and not nominal. +* When checking whether two nominal types are the same, +* their names and/or declaration sites (e.g., module / namespace) are considered. +* Meanwhile, a structural type system would only check the structure of the type itself, +* e.g., the names of its fields and their types in the case of a record. +* The name "product" comes from category theory. +* +* See also: https://ncatlab.org/nlab/show/product+type. +* +* These structures are known as product types because the number of possible values in product +* ```ignore +* { N_0: T_0, N_1: T_1, ..., N_n: T_n } +* ``` +* is: +* ```ignore +* Π (i ∈ 0..n). values(T_i) +* ``` +* so for example, `values({ A: U64, B: Bool }) = values(U64) * values(Bool)`. +* +* [structural]: https://en.wikipedia.org/wiki/Structural_type_system +*/ +export declare class ProductType { + elements: ProductTypeElement[]; + constructor(elements: ProductTypeElement[]); + isEmpty(): boolean; +} +export declare class MapType { + keyType: AlgebraicType; + valueType: AlgebraicType; + constructor(keyType: AlgebraicType, valueType: AlgebraicType); +} +export declare class BuiltinType { + type: BuiltinType.Type; + arrayType: AlgebraicType | undefined; + mapType: MapType | undefined; + constructor(type: BuiltinType.Type, arrayOrMapType: AlgebraicType | MapType | undefined); +} +export declare namespace BuiltinType { + enum Type { + Bool = "Bool", + I8 = "I8", + U8 = "U8", + I16 = "I16", + U16 = "U16", + I32 = "I32", + U32 = "U32", + I64 = "I64", + U64 = "U64", + I128 = "I128", + U128 = "U128", + F32 = "F32", + F64 = "F64", + /** UTF-8 encoded */ + String = "String", + /** This is a SATS `ArrayType` + * + * An array type is a **homogeneous** product type of dynamic length. + * + * That is, it is a product type + * where every element / factor / field is of the same type + * and where the length is statically unknown. + */ + Array = "Array", + /** This is a SATS `MapType` */ + Map = "Map" + } +} +type TypeRef = null; +type None = null; +export type EnumLabel = { + label: string; +}; +type AnyType = ProductType | SumType | BuiltinType | EnumLabel | TypeRef | None; +/** +* The SpacetimeDB Algebraic Type System (SATS) is a structural type system in +* which a nominal type system can be constructed. +* +* The type system unifies the concepts sum types, product types, and built-in +* primitive types into a single type system. +*/ +export declare class AlgebraicType { + type: Type; + type_?: AnyType; + get product(): ProductType; + set product(value: ProductType | undefined); + get sum(): SumType; + set sum(value: SumType | undefined); + get builtin(): BuiltinType; + set builtin(value: BuiltinType | undefined); + static createProductType(elements: ProductTypeElement[]): AlgebraicType; + static createArrayType(elementType: AlgebraicType): AlgebraicType; + static createSumType(variants: SumTypeVariant[]): AlgebraicType; + static createPrimitiveType(type: BuiltinType.Type): AlgebraicType; + isProductType(): boolean; + isSumType(): boolean; +} +export declare namespace AlgebraicType { + enum Type { + SumType = "SumType", + ProductType = "ProductType", + BuiltinType = "BuiltinType", + None = "None" + } +} +type Type = AlgebraicType.Type; +declare let Type: typeof AlgebraicType.Type; +export {}; diff --git a/dist/algebraic_type.js b/dist/algebraic_type.js new file mode 100644 index 0000000..d2f087b --- /dev/null +++ b/dist/algebraic_type.js @@ -0,0 +1,244 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AlgebraicType = exports.BuiltinType = exports.MapType = exports.ProductType = exports.ProductTypeElement = exports.SumType = exports.SumTypeVariant = void 0; +/** + * A variant of a sum type. + * + * NOTE: Each element has an implicit element tag based on its order. + * Uniquely identifies an element similarly to protobuf tags. + */ +class SumTypeVariant { + name; + algebraicType; + constructor(name, algebraicType) { + this.name = name; + this.algebraicType = algebraicType; + } +} +exports.SumTypeVariant = SumTypeVariant; +/** +* Unlike most languages, sums in SATS are *[structural]* and not nominal. +* When checking whether two nominal types are the same, +* their names and/or declaration sites (e.g., module / namespace) are considered. +* Meanwhile, a structural type system would only check the structure of the type itself, +* e.g., the names of its variants and their inner data types in the case of a sum. +* +* This is also known as a discriminated union (implementation) or disjoint union. +* Another name is [coproduct (category theory)](https://ncatlab.org/nlab/show/coproduct). +* +* These structures are known as sum types because the number of possible values a sum +* ```ignore +* { N_0(T_0), N_1(T_1), ..., N_n(T_n) } +* ``` +* is: +* ```ignore +* Σ (i ∈ 0..n). values(T_i) +* ``` +* so for example, `values({ A(U64), B(Bool) }) = values(U64) + values(Bool)`. +* +* See also: https://ncatlab.org/nlab/show/sum+type. +* +* [structural]: https://en.wikipedia.org/wiki/Structural_type_system +*/ +class SumType { + variants; + constructor(variants) { + this.variants = variants; + } +} +exports.SumType = SumType; +/** +* A factor / element of a product type. +* +* An element consist of an optional name and a type. +* +* NOTE: Each element has an implicit element tag based on its order. +* Uniquely identifies an element similarly to protobuf tags. +*/ +class ProductTypeElement { + name; + algebraicType; + constructor(name, algebraicType) { + this.name = name; + this.algebraicType = algebraicType; + } +} +exports.ProductTypeElement = ProductTypeElement; +/** +* A structural product type of the factors given by `elements`. +* +* This is also known as `struct` and `tuple` in many languages, +* but note that unlike most languages, products in SATs are *[structural]* and not nominal. +* When checking whether two nominal types are the same, +* their names and/or declaration sites (e.g., module / namespace) are considered. +* Meanwhile, a structural type system would only check the structure of the type itself, +* e.g., the names of its fields and their types in the case of a record. +* The name "product" comes from category theory. +* +* See also: https://ncatlab.org/nlab/show/product+type. +* +* These structures are known as product types because the number of possible values in product +* ```ignore +* { N_0: T_0, N_1: T_1, ..., N_n: T_n } +* ``` +* is: +* ```ignore +* Π (i ∈ 0..n). values(T_i) +* ``` +* so for example, `values({ A: U64, B: Bool }) = values(U64) * values(Bool)`. +* +* [structural]: https://en.wikipedia.org/wiki/Structural_type_system +*/ +class ProductType { + elements; + constructor(elements) { + this.elements = elements; + } + isEmpty() { + return this.elements.length === 0; + } +} +exports.ProductType = ProductType; +/* A map type from keys of type `keyType` to values of type `valueType`. */ +class MapType { + keyType; + valueType; + constructor(keyType, valueType) { + this.keyType = keyType; + this.valueType = valueType; + } +} +exports.MapType = MapType; +class BuiltinType { + type; + arrayType; + mapType; + constructor(type, arrayOrMapType) { + this.type = type; + if (arrayOrMapType !== undefined) { + if (arrayOrMapType.constructor === MapType) { + this.mapType = arrayOrMapType; + } + else if (arrayOrMapType.constructor === AlgebraicType) { + this.arrayType = arrayOrMapType; + } + } + } +} +exports.BuiltinType = BuiltinType; +// exporting BuiltinType as a namespace as well as a class allows to add +// export types on the namespace, so we can use BuiltinType.Type +/* +* Represents the built-in types in SATS. +* +* Some of these types are nominal in our otherwise structural type system. +*/ +(function (BuiltinType) { + let Type; + (function (Type) { + Type["Bool"] = "Bool"; + Type["I8"] = "I8"; + Type["U8"] = "U8"; + Type["I16"] = "I16"; + Type["U16"] = "U16"; + Type["I32"] = "I32"; + Type["U32"] = "U32"; + Type["I64"] = "I64"; + Type["U64"] = "U64"; + Type["I128"] = "I128"; + Type["U128"] = "U128"; + Type["F32"] = "F32"; + Type["F64"] = "F64"; + /** UTF-8 encoded */ + Type["String"] = "String"; + /** This is a SATS `ArrayType` + * + * An array type is a **homogeneous** product type of dynamic length. + * + * That is, it is a product type + * where every element / factor / field is of the same type + * and where the length is statically unknown. + */ + Type["Array"] = "Array"; + /** This is a SATS `MapType` */ + Type["Map"] = "Map"; + })(Type = BuiltinType.Type || (BuiltinType.Type = {})); +})(BuiltinType = exports.BuiltinType || (exports.BuiltinType = {})); +/** +* The SpacetimeDB Algebraic Type System (SATS) is a structural type system in +* which a nominal type system can be constructed. +* +* The type system unifies the concepts sum types, product types, and built-in +* primitive types into a single type system. +*/ +class AlgebraicType { + type; + type_; + get product() { + if (this.type !== Type.ProductType) { + throw "product type was requested, but the type is not ProductType"; + } + return this.type_; + } + set product(value) { + this.type_ = value; + this.type = value == undefined ? Type.None : Type.ProductType; + } + get sum() { + if (this.type !== Type.SumType) { + throw "sum type was requested, but the type is not SumType"; + } + return this.type_; + } + set sum(value) { + this.type_ = value; + this.type = value == undefined ? Type.None : Type.SumType; + } + get builtin() { + if (this.type !== Type.BuiltinType) { + throw "builtin type was requested, but the type is not BuiltinType"; + } + return this.type_; + } + set builtin(value) { + this.type_ = value; + this.type = value == undefined ? Type.None : Type.BuiltinType; + } + static createProductType(elements) { + let type = new AlgebraicType(); + type.product = new ProductType(elements); + return type; + } + static createArrayType(elementType) { + let type = new AlgebraicType(); + type.builtin = new BuiltinType(BuiltinType.Type.Array, elementType); + return type; + } + static createSumType(variants) { + let type = new AlgebraicType(); + type.sum = new SumType(variants); + return type; + } + static createPrimitiveType(type) { + let algebraicType = new AlgebraicType(); + algebraicType.builtin = new BuiltinType(type, undefined); + return algebraicType; + } + isProductType() { + return this.type === Type.ProductType; + } + isSumType() { + return this.type === Type.SumType; + } +} +exports.AlgebraicType = AlgebraicType; +(function (AlgebraicType) { + let Type; + (function (Type) { + Type["SumType"] = "SumType"; + Type["ProductType"] = "ProductType"; + Type["BuiltinType"] = "BuiltinType"; + Type["None"] = "None"; + })(Type = AlgebraicType.Type || (AlgebraicType.Type = {})); +})(AlgebraicType = exports.AlgebraicType || (exports.AlgebraicType = {})); +let Type = AlgebraicType.Type; diff --git a/dist/algebraic_value.d.ts b/dist/algebraic_value.d.ts new file mode 100644 index 0000000..1f69158 --- /dev/null +++ b/dist/algebraic_value.d.ts @@ -0,0 +1,153 @@ +import { ProductType, SumType, AlgebraicType, BuiltinType } from "./algebraic_type"; +import BinaryReader from "./binary_reader"; +export interface ReducerArgsAdapter { + next: () => ValueAdapter; +} +export declare class JSONReducerArgsAdapter { + args: any[]; + index: number; + constructor(args: any[]); + next(): ValueAdapter; +} +export declare class BinaryReducerArgsAdapter { + adapter: BinaryAdapter; + constructor(adapter: BinaryAdapter); + next(): ValueAdapter; +} +/** Defines the interface for deserialize `AlgebraicValue`s*/ +export interface ValueAdapter { + readUInt8Array: () => Uint8Array; + readArray: (type: AlgebraicType) => AlgebraicValue[]; + readMap: (keyType: AlgebraicType, valueType: AlgebraicType) => Map; + readString: () => string; + readSum: (type: SumType) => SumValue; + readProduct: (type: ProductType) => ProductValue; + readBool: () => boolean; + readByte: () => number; + readI8: () => number; + readU8: () => number; + readI16: () => number; + readU16: () => number; + readI32: () => number; + readU32: () => number; + readI64: () => BigInt; + readU64: () => BigInt; + readU128: () => BigInt; + readI128: () => BigInt; + readF32: () => number; + readF64: () => number; + callMethod(methodName: K): any; +} +export declare class BinaryAdapter implements ValueAdapter { + private reader; + constructor(reader: BinaryReader); + callMethod(methodName: K): any; + readUInt8Array(): Uint8Array; + readArray(type: AlgebraicType): AlgebraicValue[]; + readMap(keyType: AlgebraicType, valueType: AlgebraicType): Map; + readString(): string; + readSum(type: SumType): SumValue; + readProduct(type: ProductType): ProductValue; + readBool(): boolean; + readByte(): number; + readI8(): number; + readU8(): number; + readI16(): number; + readU16(): number; + readI32(): number; + readU32(): number; + readI64(): BigInt; + readU64(): BigInt; + readU128(): BigInt; + readI128(): BigInt; + readF32(): number; + readF64(): number; +} +export declare class JSONAdapter implements ValueAdapter { + private value; + constructor(value: any); + callMethod(methodName: K): any; + readUInt8Array(): Uint8Array; + readArray(type: AlgebraicType): AlgebraicValue[]; + readMap(_keyType: AlgebraicType, _valueType: AlgebraicType): Map; + readString(): string; + readSum(type: SumType): SumValue; + readProduct(type: ProductType): ProductValue; + readBool(): boolean; + readByte(): number; + readI8(): number; + readU8(): number; + readI16(): number; + readU16(): number; + readI32(): number; + readU32(): number; + readI64(): BigInt; + readU64(): BigInt; + readU128(): BigInt; + readI128(): BigInt; + readF32(): number; + readF64(): number; +} +/** A value of a sum type choosing a specific variant of the type. */ +export declare class SumValue { + /** A tag representing the choice of one variant of the sum type's variants. */ + tag: number; + /** + * Given a variant `Var(Ty)` in a sum type `{ Var(Ty), ... }`, + * this provides the `value` for `Ty`. + */ + value: AlgebraicValue; + constructor(tag: number, value: AlgebraicValue); + static deserialize(type: SumType | undefined, adapter: ValueAdapter): SumValue; +} +/** +* A product value is made of a list of +* "elements" / "fields" / "factors" of other `AlgebraicValue`s. +* +* The type of product value is a [product type](`ProductType`). +*/ +export declare class ProductValue { + elements: AlgebraicValue[]; + constructor(elements: AlgebraicValue[]); + static deserialize(type: ProductType | undefined, adapter: ValueAdapter): ProductValue; +} +/** A built-in value of a [`BuiltinType`]. */ +type BuiltinValueType = boolean | string | number | AlgebraicValue[] | BigInt | Map | Uint8Array; +export declare class BuiltinValue { + value: BuiltinValueType; + constructor(value: BuiltinValueType); + static deserialize(type: BuiltinType, adapter: ValueAdapter): BuiltinValue; + asString(): string; + asArray(): AlgebraicValue[]; + asJsArray(type: string): any[]; + asNumber(): number; + asBool(): boolean; + asBigInt(): BigInt; + asBoolean(): boolean; + asBytes(): Uint8Array; +} +type AnyValue = SumValue | ProductValue | BuiltinValue; +/** A value in SATS. */ +export declare class AlgebraicValue { + /** A structural sum value. */ + sum: SumValue | undefined; + /** A structural product value. */ + product: ProductValue | undefined; + /** A builtin value that has a builtin type */ + builtin: BuiltinValue | undefined; + constructor(value: AnyValue | undefined); + callMethod(methodName: K): any; + static deserialize(type: AlgebraicType, adapter: ValueAdapter): AlgebraicValue; + asProductValue(): ProductValue; + asBuiltinValue(): BuiltinValue; + asSumValue(): SumValue; + asArray(): AlgebraicValue[]; + asString(): string; + asNumber(): number; + asBool(): boolean; + asBigInt(): BigInt; + asBoolean(): boolean; + asBytes(): Uint8Array; + private assertBuiltin; +} +export {}; diff --git a/dist/algebraic_value.js b/dist/algebraic_value.js new file mode 100644 index 0000000..02d93fa --- /dev/null +++ b/dist/algebraic_value.js @@ -0,0 +1,408 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AlgebraicValue = exports.BuiltinValue = exports.ProductValue = exports.SumValue = exports.JSONAdapter = exports.BinaryAdapter = exports.BinaryReducerArgsAdapter = exports.JSONReducerArgsAdapter = void 0; +const algebraic_type_1 = require("./algebraic_type"); +class JSONReducerArgsAdapter { + args; + index = 0; + constructor(args) { + this.args = args; + } + next() { + if (this.index >= this.args.length) { + throw "Number of arguments in the reducer is larger than what we got from the server"; + } + const adapter = new JSONAdapter(this.args[this.index]); + this.index += 1; + return adapter; + } +} +exports.JSONReducerArgsAdapter = JSONReducerArgsAdapter; +class BinaryReducerArgsAdapter { + adapter; + constructor(adapter) { + this.adapter = adapter; + } + next() { + return this.adapter; + } +} +exports.BinaryReducerArgsAdapter = BinaryReducerArgsAdapter; +class BinaryAdapter { + reader; + constructor(reader) { + this.reader = reader; + } + callMethod(methodName) { + return this[methodName](); + } + readUInt8Array() { + const length = this.reader.readU32(); + return this.reader.readUInt8Array(length); + } + readArray(type) { + const length = this.reader.readU32(); + let result = []; + for (let i = 0; i < length; i++) { + result.push(AlgebraicValue.deserialize(type, this)); + } + return result; + } + readMap(keyType, valueType) { + const mapLength = this.reader.readU32(); + let result = new Map(); + for (let i = 0; i < mapLength; i++) { + const key = AlgebraicValue.deserialize(keyType, this); + const value = AlgebraicValue.deserialize(valueType, this); + result.set(key, value); + } + return result; + } + readString() { + const strLength = this.reader.readU32(); + return this.reader.readString(strLength); + } + readSum(type) { + let tag = this.reader.readByte(); + let sumValue = AlgebraicValue.deserialize(type.variants[tag].algebraicType, this); + return new SumValue(tag, sumValue); + } + readProduct(type) { + let elements = []; + for (let element of type.elements) { + elements.push(AlgebraicValue.deserialize(element.algebraicType, this)); + } + return new ProductValue(elements); + } + readBool() { + return this.reader.readBool(); + } + readByte() { + return this.reader.readByte(); + } + readI8() { + return this.reader.readI8(); + } + readU8() { + return this.reader.readU8(); + } + readI16() { + return this.reader.readI16(); + } + readU16() { + return this.reader.readU16(); + } + readI32() { + return this.reader.readI32(); + } + readU32() { + return this.reader.readU32(); + } + readI64() { + return this.reader.readI64(); + } + readU64() { + return this.reader.readU64(); + } + readU128() { + return this.reader.readU128(); + } + readI128() { + return this.reader.readI128(); + } + readF32() { + return this.reader.readF32(); + } + readF64() { + return this.reader.readF64(); + } +} +exports.BinaryAdapter = BinaryAdapter; +class JSONAdapter { + value; + constructor(value) { + this.value = value; + } + callMethod(methodName) { + return this[methodName](); + } + readUInt8Array() { + return Uint8Array.from(this.value.match(/.{1,2}/g).map((byte) => parseInt(byte, 16))); + } + readArray(type) { + let result = []; + for (let el of this.value) { + result.push(AlgebraicValue.deserialize(type, new JSONAdapter(el))); + } + return result; + } + readMap(_keyType, _valueType) { + let result = new Map(); + // for (let i = 0; i < this.value.length; i++) { + // const key = AlgebraicValue.deserialize( + // keyType, + // new JSONAdapter() + // ); + // const value = AlgebraicValue.deserialize( + // valueType, + // this + // ); + // result.set(key, value); + // } + // + return result; + } + readString() { + return this.value; + } + readSum(type) { + let tag = parseInt(Object.keys(this.value)[0]); + let variant = type.variants[tag]; + let enumValue = Object.values(this.value)[0]; + let sumValue = AlgebraicValue.deserialize(variant.algebraicType, new JSONAdapter(enumValue)); + return new SumValue(tag, sumValue); + } + readProduct(type) { + let elements = []; + for (let i in type.elements) { + let element = type.elements[i]; + elements.push(AlgebraicValue.deserialize(element.algebraicType, new JSONAdapter(this.value[i]))); + } + return new ProductValue(elements); + } + readBool() { + return this.value; + } + readByte() { + return this.value; + } + readI8() { + return this.value; + } + readU8() { + return this.value; + } + readI16() { + return this.value; + } + readU16() { + return this.value; + } + readI32() { + return this.value; + } + readU32() { + return this.value; + } + readI64() { + return this.value; + } + readU64() { + return this.value; + } + readU128() { + return this.value; + } + readI128() { + return this.value; + } + readF32() { + return this.value; + } + readF64() { + return this.value; + } +} +exports.JSONAdapter = JSONAdapter; +/** A value of a sum type choosing a specific variant of the type. */ +class SumValue { + /** A tag representing the choice of one variant of the sum type's variants. */ + tag; + /** + * Given a variant `Var(Ty)` in a sum type `{ Var(Ty), ... }`, + * this provides the `value` for `Ty`. + */ + value; + constructor(tag, value) { + this.tag = tag; + this.value = value; + } + static deserialize(type, adapter) { + if (type === undefined) { + // TODO: get rid of undefined here + throw "sum type is undefined"; + } + return adapter.readSum(type); + } +} +exports.SumValue = SumValue; +/** +* A product value is made of a list of +* "elements" / "fields" / "factors" of other `AlgebraicValue`s. +* +* The type of product value is a [product type](`ProductType`). +*/ +class ProductValue { + elements; + constructor(elements) { + this.elements = elements; + } + static deserialize(type, adapter) { + if (type === undefined) { + throw "type is undefined"; + } + return adapter.readProduct(type); + } +} +exports.ProductValue = ProductValue; +class BuiltinValue { + value; + constructor(value) { + this.value = value; + } + static deserialize(type, adapter) { + switch (type.type) { + case algebraic_type_1.BuiltinType.Type.Array: + let arrayBuiltinType = type.arrayType && + type.arrayType.type === algebraic_type_1.AlgebraicType.Type.BuiltinType + ? type.arrayType.builtin.type + : undefined; + if (arrayBuiltinType !== undefined && + arrayBuiltinType === algebraic_type_1.BuiltinType.Type.U8) { + const value = adapter.readUInt8Array(); + return new this(value); + } + else { + const arrayResult = adapter.readArray(type.arrayType); + return new this(arrayResult); + } + case algebraic_type_1.BuiltinType.Type.Map: + let keyType = type.mapType.keyType; + let valueType = type.mapType.valueType; + const mapResult = adapter.readMap(keyType, valueType); + return new this(mapResult); + case algebraic_type_1.BuiltinType.Type.String: + const result = adapter.readString(); + return new this(result); + default: + const methodName = "read" + type.type; + return new this(adapter.callMethod(methodName)); + } + } + asString() { + return this.value; + } + asArray() { + return this.value; + } + asJsArray(type) { + return this.asArray().map((el) => el.callMethod(("as" + type))); + } + asNumber() { + return this.value; + } + asBool() { + return this.value; + } + asBigInt() { + return this.value; + } + asBoolean() { + return this.value; + } + asBytes() { + return this.value; + } +} +exports.BuiltinValue = BuiltinValue; +/** A value in SATS. */ +class AlgebraicValue { + /** A structural sum value. */ + sum; + /** A structural product value. */ + product; + /** A builtin value that has a builtin type */ + builtin; + constructor(value) { + if (value === undefined) { + // TODO: possibly get rid of it + throw "value is undefined"; + } + switch (value.constructor) { + case SumValue: + this.sum = value; + break; + case ProductValue: + this.product = value; + break; + case BuiltinValue: + this.builtin = value; + break; + } + } + callMethod(methodName) { + return this[methodName](); + } + static deserialize(type, adapter) { + switch (type.type) { + case algebraic_type_1.AlgebraicType.Type.ProductType: + return new this(ProductValue.deserialize(type.product, adapter)); + case algebraic_type_1.AlgebraicType.Type.SumType: + return new this(SumValue.deserialize(type.sum, adapter)); + case algebraic_type_1.AlgebraicType.Type.BuiltinType: + return new this(BuiltinValue.deserialize(type.builtin, adapter)); + default: + throw new Error("not implemented"); + } + } + asProductValue() { + if (!this.product) { + throw "AlgebraicValue is not a ProductValue and product was requested"; + } + return this.product; + } + asBuiltinValue() { + this.assertBuiltin(); + return this.builtin; + } + asSumValue() { + if (!this.sum) { + throw "AlgebraicValue is not a SumValue and a sum value was requested"; + } + return this.sum; + } + asArray() { + this.assertBuiltin(); + return this.builtin.asArray(); + } + asString() { + this.assertBuiltin(); + return this.builtin.asString(); + } + asNumber() { + this.assertBuiltin(); + return this.builtin.asNumber(); + } + asBool() { + this.assertBuiltin(); + return this.builtin.asBool(); + } + asBigInt() { + this.assertBuiltin(); + return this.builtin.asBigInt(); + } + asBoolean() { + this.assertBuiltin(); + return this.builtin.asBool(); + } + asBytes() { + this.assertBuiltin(); + return this.builtin.asBytes(); + } + assertBuiltin() { + if (!this.builtin) { + throw "AlgebraicValue is not a BuiltinValue and a string was requested"; + } + } +} +exports.AlgebraicValue = AlgebraicValue; diff --git a/dist/binary_reader.d.ts b/dist/binary_reader.d.ts new file mode 100644 index 0000000..a9cbb41 --- /dev/null +++ b/dist/binary_reader.d.ts @@ -0,0 +1,22 @@ +export default class BinaryReader { + private buffer; + private offset; + constructor(input: Uint8Array); + readUInt8Array(length: number): Uint8Array; + readBool(): boolean; + readByte(): number; + readBytes(length: number): Uint8Array; + readI8(): number; + readU8(): number; + readI16(): number; + readU16(): number; + readI32(): number; + readU32(): number; + readI64(): BigInt; + readU64(): BigInt; + readU128(): BigInt; + readI128(): BigInt; + readF32(): number; + readF64(): number; + readString(length: number): string; +} diff --git a/dist/binary_reader.js b/dist/binary_reader.js new file mode 100644 index 0000000..0fc2823 --- /dev/null +++ b/dist/binary_reader.js @@ -0,0 +1,100 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class BinaryReader { + buffer; + offset = 0; + constructor(input) { + this.buffer = new DataView(input.buffer); + this.offset = input.byteOffset; + } + readUInt8Array(length) { + const value = new Uint8Array(this.buffer.buffer, this.offset, length); + this.offset += length; + return value; + } + readBool() { + const value = this.buffer.getUint8(this.offset); + this.offset += 1; + return value !== 0; + } + readByte() { + const value = this.buffer.getUint8(this.offset); + this.offset += 1; + return value; + } + readBytes(length) { + const value = new DataView(this.buffer.buffer, this.offset, length); + this.offset += length; + return new Uint8Array(value.buffer); + } + readI8() { + const value = this.buffer.getInt8(this.offset); + this.offset += 1; + return value; + } + readU8() { + const value = this.buffer.getUint8(this.offset); + this.offset += 1; + return value; + } + readI16() { + const value = this.buffer.getInt16(this.offset, true); + this.offset += 2; + return value; + } + readU16() { + const value = this.buffer.getUint16(this.offset, true); + this.offset += 2; + return value; + } + readI32() { + const value = this.buffer.getInt32(this.offset, true); + this.offset += 4; + return value; + } + readU32() { + const value = this.buffer.getUint32(this.offset, true); + this.offset += 4; + return value; + } + readI64() { + const value = this.buffer.getBigInt64(this.offset, true); + this.offset += 8; + return value; + } + readU64() { + const value = this.buffer.getBigUint64(this.offset, true); + this.offset += 8; + return value; + } + readU128() { + const lowerPart = this.buffer.getBigUint64(this.offset, true); + const upperPart = this.buffer.getBigUint64(this.offset + 8, true); + this.offset += 16; + return (upperPart << BigInt(64)) + lowerPart; + } + readI128() { + const lowerPart = this.buffer.getBigInt64(this.offset, true); + const upperPart = this.buffer.getBigInt64(this.offset + 8, true); + this.offset += 16; + return (upperPart << BigInt(64)) + lowerPart; + } + readF32() { + const value = this.buffer.getFloat32(this.offset, true); + this.offset += 4; + return value; + } + readF64() { + const value = this.buffer.getFloat64(this.offset, true); + this.offset += 8; + return value; + } + readString(length) { + const uint8Array = new Uint8Array(this.buffer.buffer, this.offset, length); + const decoder = new TextDecoder("utf-8"); + const value = decoder.decode(uint8Array); + this.offset += length; + return value; + } +} +exports.default = BinaryReader; diff --git a/dist/binary_writer.d.ts b/dist/binary_writer.d.ts new file mode 100644 index 0000000..d872812 --- /dev/null +++ b/dist/binary_writer.d.ts @@ -0,0 +1,24 @@ +export default class BinaryWriter { + private buffer; + private view; + private offset; + constructor(size: number); + private expandBuffer; + getBuffer(): Uint8Array; + writeUInt8Array(value: Uint8Array): void; + writeBool(value: boolean): void; + writeByte(value: number): void; + writeI8(value: number): void; + writeU8(value: number): void; + writeI16(value: number): void; + writeU16(value: number): void; + writeI32(value: number): void; + writeU32(value: number): void; + writeI64(value: bigint): void; + writeU64(value: bigint): void; + writeU128(value: bigint): void; + writeI128(value: bigint): void; + writeF32(value: number): void; + writeF64(value: number): void; + writeString(value: string): void; +} diff --git a/dist/binary_writer.js b/dist/binary_writer.js new file mode 100644 index 0000000..1e6ea79 --- /dev/null +++ b/dist/binary_writer.js @@ -0,0 +1,118 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class BinaryWriter { + buffer; + view; + offset = 0; + constructor(size) { + this.buffer = new Uint8Array(size); + this.view = new DataView(this.buffer.buffer); + } + expandBuffer(additionalCapacity) { + const minCapacity = this.offset + additionalCapacity + 1; + if (minCapacity <= this.buffer.length) + return; + let newCapacity = this.buffer.length * 2; + if (newCapacity < minCapacity) + newCapacity = minCapacity; + const newBuffer = new Uint8Array(newCapacity); + newBuffer.set(this.buffer); + this.buffer = newBuffer; + this.view = new DataView(this.buffer.buffer); + } + getBuffer() { + return this.buffer.slice(0, this.offset); + } + writeUInt8Array(value) { + const length = value.length; + this.expandBuffer(4 + length); + this.writeU32(length); + this.buffer.set(value, this.offset); + this.offset += value.length; + } + writeBool(value) { + this.expandBuffer(1); + this.view.setUint8(this.offset, value ? 1 : 0); + this.offset += 1; + } + writeByte(value) { + this.expandBuffer(1); + this.view.setUint8(this.offset, value); + this.offset += 1; + } + writeI8(value) { + this.expandBuffer(1); + this.view.setInt8(this.offset, value); + this.offset += 1; + } + writeU8(value) { + this.expandBuffer(1); + this.view.setUint8(this.offset, value); + this.offset += 1; + } + writeI16(value) { + this.expandBuffer(2); + this.view.setInt16(this.offset, value, true); + this.offset += 2; + } + writeU16(value) { + this.expandBuffer(2); + this.view.setUint16(this.offset, value, true); + this.offset += 2; + } + writeI32(value) { + this.expandBuffer(4); + this.view.setInt32(this.offset, value, true); + this.offset += 4; + } + writeU32(value) { + this.expandBuffer(4); + this.view.setUint32(this.offset, value, true); + this.offset += 4; + } + writeI64(value) { + this.expandBuffer(8); + this.view.setBigInt64(this.offset, value, true); + this.offset += 8; + } + writeU64(value) { + this.expandBuffer(8); + this.view.setBigUint64(this.offset, value, true); + this.offset += 8; + } + writeU128(value) { + this.expandBuffer(16); + const lowerPart = value & BigInt("0xFFFFFFFFFFFFFFFF"); + const upperPart = value >> BigInt(64); + this.view.setBigUint64(this.offset, lowerPart, true); + this.view.setBigUint64(this.offset + 8, upperPart, true); + this.offset += 16; + } + writeI128(value) { + this.expandBuffer(16); + const lowerPart = value & BigInt("0xFFFFFFFFFFFFFFFF"); + const upperPart = value >> BigInt(64); + this.view.setBigInt64(this.offset, lowerPart, true); + this.view.setBigInt64(this.offset + 8, upperPart, true); + this.offset += 16; + } + writeF32(value) { + this.expandBuffer(4); + this.view.setFloat32(this.offset, value, true); + this.offset += 4; + } + writeF64(value) { + this.expandBuffer(8); + this.view.setFloat64(this.offset, value, true); + this.offset += 8; + } + writeString(value) { + const encoder = new TextEncoder(); + const encodedString = encoder.encode(value); + this.writeU32(encodedString.length); + this.expandBuffer(encodedString.length); + this.buffer.set(encodedString, this.offset); + this.offset += encodedString.length; + } +} +exports.default = BinaryWriter; diff --git a/dist/client_api.d.ts b/dist/client_api.d.ts new file mode 100644 index 0000000..d36db44 --- /dev/null +++ b/dist/client_api.d.ts @@ -0,0 +1,1479 @@ +import * as _m0 from "protobufjs/minimal"; +export declare const protobufPackage = "client_api"; +/** + * //// Generic Message ////// + * TODO: Theoretically this format could be replaced by AlgebraicValue/AlgebraicType + * but I don't think we want to do that yet. + * TODO: Split this up into ServerBound and ClientBound if there's no overlap + */ +export interface Message { + /** client -> database, request a reducer run. */ + functionCall?: FunctionCall | undefined; + /** + * database -> client, contained in `TransactionUpdate`, informs of changes to + * subscribed rows. + */ + subscriptionUpdate?: SubscriptionUpdate | undefined; + /** database -> client, contained in `TransactionUpdate`, describes a reducer run. */ + event?: Event | undefined; + /** database -> client, upon reducer run. */ + transactionUpdate?: TransactionUpdate | undefined; + /** database -> client, after connecting, to inform client of its identity. */ + identityToken?: IdentityToken | undefined; + /** client -> database, register SQL queries on which to receive updates. */ + subscribe?: Subscribe | undefined; + /** client -> database, send a one-off SQL query without establishing a subscription. */ + oneOffQuery?: OneOffQuery | undefined; + /** database -> client, return results to a one off SQL query. */ + oneOffQueryResponse?: OneOffQueryResponse | undefined; +} +/** + * / Received by database from client to inform of user's identity, token and client address. + * / + * / The database will always send an `IdentityToken` message + * / as the first message for a new WebSocket connection. + * / If the client is re-connecting with existing credentials, + * / the message will include those credentials. + * / If the client connected anonymously, + * / the database will generate new credentials to identify it. + */ +export interface IdentityToken { + identity: Uint8Array; + token: string; + address: Uint8Array; +} +/** + * / Sent by client to database to request a reducer runs. + * / + * / - `reducer` is the string name of a reducer to run. + * / + * / - `argBytes` is the arguments to the reducer, encoded as BSATN. + * / + * / SpacetimeDB models reducers as taking a single `AlgebraicValue` as an argument, which + * / generally will be a `ProductValue` containing all of the args (except the + * / `ReducerContext`, which is injected by the host, not provided in this API). + */ +export interface FunctionCall { + /** TODO: Maybe this should be replaced with an int identifier for performance? */ + reducer: string; + argBytes: Uint8Array; +} +/** + * / Sent by client to database to register a set of queries, about which the client will + * / receive `TransactionUpdate`s. + * / + * / `query_strings` is a sequence of strings, each of which is a SQL query. + * / + * / After issuing a `Subscribe` message, the client will receive a single + * / `SubscriptionUpdate` message containing every current row of every table which matches + * / the subscribed queries. Then, after each reducer run which updates one or more + * / subscribed rows, the client will receive a `TransactionUpdate` containing the updates. + * / + * / A `Subscribe` message sets or replaces the entire set of queries to which the client + * / is subscribed. If the client is previously subscribed to some set of queries `A`, and + * / then sends a `Subscribe` message to subscribe to a set `B`, afterwards, the client + * / will be subscribed to `B` but not `A`. In this case, the client will receive a + * / `SubscriptionUpdate` containing every existing row that matches `B`, even if some were + * / already in `A`. + */ +export interface Subscribe { + queryStrings: string[]; +} +/** + * / Part of a `TransactionUpdate` received by client from database upon a reducer run. + * / + * / - `timestamp` is the time when the reducer started, + * / as microseconds since the Unix epoch. + * / + * / - `callerIdentity` is the identity of the user who requested the reducer run. + * / For event-driven and scheduled reducers, + * / it is the identity of the database owner. + * / + * / - `functionCall` contains the name of the reducer which ran and the arguments it + * / received. + * / + * / - `status` of `committed` means that the reducer ran successfully and its changes were + * / committed to the database. The rows altered in the database + * / will be recorded in the parent `TransactionUpdate`'s + * / `SubscriptionUpdate`. + * / + * / - `status` of `failed` means that the reducer panicked, and any changes it attempted to + * / make were rolled back. + * / + * / - `status` of `out_of_energy` means that the reducer was interrupted + * / due to insufficient energy/funds, + * / and any changes it attempted to make were rolled back. + * / + * / - `message` is the error message with which the reducer failed. + * / For `committed` or `out_of_energy` statuses, + * / it is the empty string. + * / + * / - `energy_quanta_used` and `host_execution_duration_micros` seem self-explanatory; + * / they describe the amount of energy credits consumed by running the reducer, + * / and how long it took to run. + * / + * / - `callerAddress` is the 16-byte address of the user who requested the reducer run. + * / The all-zeros address is a sentinel which denotes no address. + * / `init` and `update` reducers will have a `callerAddress` + * / if and only if one was provided to the `publish` HTTP endpoint. + * / Scheduled reducers will never have a `callerAddress`. + * / Reducers invoked by HTTP will have a `callerAddress` + * / if and only if one was provided to the `call` HTTP endpoint. + * / Reducers invoked by WebSocket will always have a `callerAddress`. + */ +export interface Event { + timestamp: number; + callerIdentity: Uint8Array; + functionCall: FunctionCall | undefined; + /** + * TODO: arguably these should go inside an EventStatus message + * since success doesn't have a message + */ + status: Event_Status; + message: string; + energyQuantaUsed: number; + hostExecutionDurationMicros: number; + callerAddress: Uint8Array; +} +export declare enum Event_Status { + committed = 0, + failed = 1, + out_of_energy = 2, + UNRECOGNIZED = -1 +} +export declare function event_StatusFromJSON(object: any): Event_Status; +export declare function event_StatusToJSON(object: Event_Status): string; +/** + * / Part of a `TransactionUpdate` received by client from database when subscribed rows in + * / a table are altered, or received alone after a `Subscription` to initialize the + * / client's mirror of the database. + * / + * / A single `SubscriptionUpdate` may contain `TableUpdate` messages for multiple + * / tables. + */ +export interface SubscriptionUpdate { + tableUpdates: TableUpdate[]; +} +/** + * / Part of a `SubscriptionUpdate` received by client from database for alterations to a + * / single table. + * / + * / `tableId` and `tableName` identify the table. Clients should use the `tableName`, as + * / it is a stable part of a module's API, whereas `tableId` may + * / or may not change between runs. + * / + * / `tableRowOperations` are actual modified rows. + */ +export interface TableUpdate { + tableId: number; + tableName: string; + tableRowOperations: TableRowOperation[]; +} +/** + * / Part of a `TableUpdate` received by client from database for alteration to a single + * / row of a table. + * / + * / The table being altered is identified by the parent `TableUpdate`. + * / + * / - `op` of `DELETE` means that the row in question has been removed and is no longer + * / resident in the table. + * / + * / - `op` of `INSERT` means that the row in question has been either newly inserted or + * / updated, and is resident in the table. + * / + * / - `row` is the row itself, encoded as BSATN. + */ +export interface TableRowOperation { + op: TableRowOperation_OperationType; + row: Uint8Array; +} +export declare enum TableRowOperation_OperationType { + DELETE = 0, + INSERT = 1, + UNRECOGNIZED = -1 +} +export declare function tableRowOperation_OperationTypeFromJSON(object: any): TableRowOperation_OperationType; +export declare function tableRowOperation_OperationTypeToJSON(object: TableRowOperation_OperationType): string; +/** + * / Received by client from database upon a reducer run. + * / + * / Clients receive `TransactionUpdate`s only for reducers + * / which update at least one of their subscribed rows, + * / or for their own `failed` or `out_of_energy` reducer invocations. + * / + * / - `event` contains information about the reducer. + * / + * / - `subscriptionUpdate` contains changes to subscribed rows. + */ +export interface TransactionUpdate { + event: Event | undefined; + subscriptionUpdate: SubscriptionUpdate | undefined; +} +/** + * / A one-off query submission. + * / + * / Query should be a "SELECT * FROM Table WHERE ...". Other types of queries will be rejected. + * / Multiple such semicolon-delimited queries are allowed. + * / + * / One-off queries are identified by a client-generated messageID. + * / To avoid data leaks, the server will NOT cache responses to messages based on UUID! + * / It also will not check for duplicate IDs. They are just a way to match responses to messages. + */ +export interface OneOffQuery { + messageId: Uint8Array; + queryString: string; +} +/** + * / A one-off query response. + * / Will contain either one error or multiple response rows. + * / At most one of these messages will be sent in reply to any query. + * / + * / The messageId will be identical to the one sent in the original query. + */ +export interface OneOffQueryResponse { + messageId: Uint8Array; + error: string; + tables: OneOffTable[]; +} +/** / A table included as part of a one-off query. */ +export interface OneOffTable { + tableName: string; + row: Uint8Array[]; +} +export declare const Message: { + encode(message: Message, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): Message; + fromJSON(object: any): Message; + toJSON(message: Message): unknown; + create]: never; }) | undefined; + subscriptionUpdate?: ({ + tableUpdates?: { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } & { + tableUpdates?: ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] & ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + } & { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] & ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { [K_1 in Exclude]: never; })[] & { [K_2 in Exclude]: never; }) | undefined; + } & { [K_3 in Exclude]: never; })[] & { [K_4 in Exclude]: never; }) | undefined; + } & { [K_5 in Exclude]: never; }) | undefined; + event?: ({ + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: ({ + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } & { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } & { [K_6 in Exclude]: never; }) | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { [K_7 in Exclude]: never; }) | undefined; + transactionUpdate?: ({ + event?: { + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } | undefined; + subscriptionUpdate?: { + tableUpdates?: { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + } & { + event?: ({ + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: ({ + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } & { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } & { [K_8 in Exclude]: never; }) | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { [K_9 in Exclude]: never; }) | undefined; + subscriptionUpdate?: ({ + tableUpdates?: { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } & { + tableUpdates?: ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] & ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + } & { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] & ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { [K_10 in Exclude]: never; })[] & { [K_11 in Exclude]: never; }) | undefined; + } & { [K_12 in Exclude]: never; })[] & { [K_13 in Exclude]: never; }) | undefined; + } & { [K_14 in Exclude]: never; }) | undefined; + } & { [K_15 in Exclude]: never; }) | undefined; + identityToken?: ({ + identity?: Uint8Array | undefined; + token?: string | undefined; + address?: Uint8Array | undefined; + } & { + identity?: Uint8Array | undefined; + token?: string | undefined; + address?: Uint8Array | undefined; + } & { [K_16 in Exclude]: never; }) | undefined; + subscribe?: ({ + queryStrings?: string[] | undefined; + } & { + queryStrings?: (string[] & string[] & { [K_17 in Exclude]: never; }) | undefined; + } & { [K_18 in Exclude]: never; }) | undefined; + oneOffQuery?: ({ + messageId?: Uint8Array | undefined; + queryString?: string | undefined; + } & { + messageId?: Uint8Array | undefined; + queryString?: string | undefined; + } & { [K_19 in Exclude]: never; }) | undefined; + oneOffQueryResponse?: ({ + messageId?: Uint8Array | undefined; + error?: string | undefined; + tables?: { + tableName?: string | undefined; + row?: Uint8Array[] | undefined; + }[] | undefined; + } & { + messageId?: Uint8Array | undefined; + error?: string | undefined; + tables?: ({ + tableName?: string | undefined; + row?: Uint8Array[] | undefined; + }[] & ({ + tableName?: string | undefined; + row?: Uint8Array[] | undefined; + } & { + tableName?: string | undefined; + row?: (Uint8Array[] & Uint8Array[] & { [K_20 in Exclude]: never; }) | undefined; + } & { [K_21 in Exclude]: never; })[] & { [K_22 in Exclude]: never; }) | undefined; + } & { [K_23 in Exclude]: never; }) | undefined; + } & { [K_24 in Exclude]: never; }>(base?: I | undefined): Message; + fromPartial]: never; }) | undefined; + subscriptionUpdate?: ({ + tableUpdates?: { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } & { + tableUpdates?: ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] & ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + } & { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] & ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { [K_26 in Exclude]: never; })[] & { [K_27 in Exclude]: never; }) | undefined; + } & { [K_28 in Exclude]: never; })[] & { [K_29 in Exclude]: never; }) | undefined; + } & { [K_30 in Exclude]: never; }) | undefined; + event?: ({ + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: ({ + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } & { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } & { [K_31 in Exclude]: never; }) | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { [K_32 in Exclude]: never; }) | undefined; + transactionUpdate?: ({ + event?: { + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } | undefined; + subscriptionUpdate?: { + tableUpdates?: { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } | undefined; + } & { + event?: ({ + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { + timestamp?: number | undefined; + callerIdentity?: Uint8Array | undefined; + functionCall?: ({ + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } & { + reducer?: string | undefined; + argBytes?: Uint8Array | undefined; + } & { [K_33 in Exclude]: never; }) | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { [K_34 in Exclude]: never; }) | undefined; + subscriptionUpdate?: ({ + tableUpdates?: { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } & { + tableUpdates?: ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] & ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + } & { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] & ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { [K_35 in Exclude]: never; })[] & { [K_36 in Exclude]: never; }) | undefined; + } & { [K_37 in Exclude]: never; })[] & { [K_38 in Exclude]: never; }) | undefined; + } & { [K_39 in Exclude]: never; }) | undefined; + } & { [K_40 in Exclude]: never; }) | undefined; + identityToken?: ({ + identity?: Uint8Array | undefined; + token?: string | undefined; + address?: Uint8Array | undefined; + } & { + identity?: Uint8Array | undefined; + token?: string | undefined; + address?: Uint8Array | undefined; + } & { [K_41 in Exclude]: never; }) | undefined; + subscribe?: ({ + queryStrings?: string[] | undefined; + } & { + queryStrings?: (string[] & string[] & { [K_42 in Exclude]: never; }) | undefined; + } & { [K_43 in Exclude]: never; }) | undefined; + oneOffQuery?: ({ + messageId?: Uint8Array | undefined; + queryString?: string | undefined; + } & { + messageId?: Uint8Array | undefined; + queryString?: string | undefined; + } & { [K_44 in Exclude]: never; }) | undefined; + oneOffQueryResponse?: ({ + messageId?: Uint8Array | undefined; + error?: string | undefined; + tables?: { + tableName?: string | undefined; + row?: Uint8Array[] | undefined; + }[] | undefined; + } & { + messageId?: Uint8Array | undefined; + error?: string | undefined; + tables?: ({ + tableName?: string | undefined; + row?: Uint8Array[] | undefined; + }[] & ({ + tableName?: string | undefined; + row?: Uint8Array[] | undefined; + } & { + tableName?: string | undefined; + row?: (Uint8Array[] & Uint8Array[] & { [K_45 in Exclude]: never; }) | undefined; + } & { [K_46 in Exclude]: never; })[] & { [K_47 in Exclude]: never; }) | undefined; + } & { [K_48 in Exclude]: never; }) | undefined; + } & { [K_49 in Exclude]: never; }>(object: I_1): Message; +}; +export declare const IdentityToken: { + encode(message: IdentityToken, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): IdentityToken; + fromJSON(object: any): IdentityToken; + toJSON(message: IdentityToken): unknown; + create]: never; }>(base?: I | undefined): IdentityToken; + fromPartial]: never; }>(object: I_1): IdentityToken; +}; +export declare const FunctionCall: { + encode(message: FunctionCall, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): FunctionCall; + fromJSON(object: any): FunctionCall; + toJSON(message: FunctionCall): unknown; + create]: never; }>(base?: I | undefined): FunctionCall; + fromPartial]: never; }>(object: I_1): FunctionCall; +}; +export declare const Subscribe: { + encode(message: Subscribe, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): Subscribe; + fromJSON(object: any): Subscribe; + toJSON(message: Subscribe): unknown; + create]: never; }) | undefined; + } & { [K_1 in Exclude]: never; }>(base?: I | undefined): Subscribe; + fromPartial]: never; }) | undefined; + } & { [K_3 in Exclude]: never; }>(object: I_1): Subscribe; +}; +export declare const Event: { + encode(message: Event, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): Event; + fromJSON(object: any): Event; + toJSON(message: Event): unknown; + create]: never; }) | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { [K_1 in Exclude]: never; }>(base?: I | undefined): Event; + fromPartial]: never; }) | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { [K_3 in Exclude]: never; }>(object: I_1): Event; +}; +export declare const SubscriptionUpdate: { + encode(message: SubscriptionUpdate, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): SubscriptionUpdate; + fromJSON(object: any): SubscriptionUpdate; + toJSON(message: SubscriptionUpdate): unknown; + create]: never; })[] & { [K_1 in Exclude]: never; }) | undefined; + } & { [K_2 in Exclude]: never; })[] & { [K_3 in Exclude]: never; }) | undefined; + } & { [K_4 in Exclude]: never; }>(base?: I | undefined): SubscriptionUpdate; + fromPartial]: never; })[] & { [K_6 in Exclude]: never; }) | undefined; + } & { [K_7 in Exclude]: never; })[] & { [K_8 in Exclude]: never; }) | undefined; + } & { [K_9 in Exclude]: never; }>(object: I_1): SubscriptionUpdate; +}; +export declare const TableUpdate: { + encode(message: TableUpdate, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): TableUpdate; + fromJSON(object: any): TableUpdate; + toJSON(message: TableUpdate): unknown; + create]: never; })[] & { [K_1 in Exclude]: never; }) | undefined; + } & { [K_2 in Exclude]: never; }>(base?: I | undefined): TableUpdate; + fromPartial]: never; })[] & { [K_4 in Exclude]: never; }) | undefined; + } & { [K_5 in Exclude]: never; }>(object: I_1): TableUpdate; +}; +export declare const TableRowOperation: { + encode(message: TableRowOperation, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): TableRowOperation; + fromJSON(object: any): TableRowOperation; + toJSON(message: TableRowOperation): unknown; + create]: never; }>(base?: I | undefined): TableRowOperation; + fromPartial]: never; }>(object: I_1): TableRowOperation; +}; +export declare const TransactionUpdate: { + encode(message: TransactionUpdate, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): TransactionUpdate; + fromJSON(object: any): TransactionUpdate; + toJSON(message: TransactionUpdate): unknown; + create]: never; }) | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { [K_1 in Exclude]: never; }) | undefined; + subscriptionUpdate?: ({ + tableUpdates?: { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } & { + tableUpdates?: ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] & ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + } & { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] & ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { [K_2 in Exclude]: never; })[] & { [K_3 in Exclude]: never; }) | undefined; + } & { [K_4 in Exclude]: never; })[] & { [K_5 in Exclude]: never; }) | undefined; + } & { [K_6 in Exclude]: never; }) | undefined; + } & { [K_7 in Exclude]: never; }>(base?: I | undefined): TransactionUpdate; + fromPartial]: never; }) | undefined; + status?: Event_Status | undefined; + message?: string | undefined; + energyQuantaUsed?: number | undefined; + hostExecutionDurationMicros?: number | undefined; + callerAddress?: Uint8Array | undefined; + } & { [K_9 in Exclude]: never; }) | undefined; + subscriptionUpdate?: ({ + tableUpdates?: { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] | undefined; + } & { + tableUpdates?: ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + }[] & ({ + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] | undefined; + } & { + tableId?: number | undefined; + tableName?: string | undefined; + tableRowOperations?: ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + }[] & ({ + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { + op?: TableRowOperation_OperationType | undefined; + row?: Uint8Array | undefined; + } & { [K_10 in Exclude]: never; })[] & { [K_11 in Exclude]: never; }) | undefined; + } & { [K_12 in Exclude]: never; })[] & { [K_13 in Exclude]: never; }) | undefined; + } & { [K_14 in Exclude]: never; }) | undefined; + } & { [K_15 in Exclude]: never; }>(object: I_1): TransactionUpdate; +}; +export declare const OneOffQuery: { + encode(message: OneOffQuery, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): OneOffQuery; + fromJSON(object: any): OneOffQuery; + toJSON(message: OneOffQuery): unknown; + create]: never; }>(base?: I | undefined): OneOffQuery; + fromPartial]: never; }>(object: I_1): OneOffQuery; +}; +export declare const OneOffQueryResponse: { + encode(message: OneOffQueryResponse, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): OneOffQueryResponse; + fromJSON(object: any): OneOffQueryResponse; + toJSON(message: OneOffQueryResponse): unknown; + create]: never; }) | undefined; + } & { [K_1 in Exclude]: never; })[] & { [K_2 in Exclude]: never; }) | undefined; + } & { [K_3 in Exclude]: never; }>(base?: I | undefined): OneOffQueryResponse; + fromPartial]: never; }) | undefined; + } & { [K_5 in Exclude]: never; })[] & { [K_6 in Exclude]: never; }) | undefined; + } & { [K_7 in Exclude]: never; }>(object: I_1): OneOffQueryResponse; +}; +export declare const OneOffTable: { + encode(message: OneOffTable, writer?: _m0.Writer): _m0.Writer; + decode(input: _m0.Reader | Uint8Array, length?: number): OneOffTable; + fromJSON(object: any): OneOffTable; + toJSON(message: OneOffTable): unknown; + create]: never; }) | undefined; + } & { [K_1 in Exclude]: never; }>(base?: I | undefined): OneOffTable; + fromPartial]: never; }) | undefined; + } & { [K_3 in Exclude]: never; }>(object: I_1): OneOffTable; +}; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; +export type DeepPartial = T extends Builtin ? T : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> : T extends {} ? { + [K in keyof T]?: DeepPartial; +} : Partial; +type KeysOfUnion = T extends T ? keyof T : never; +export type Exact = P extends Builtin ? P : P & { + [K in keyof P]: Exact; +} & { + [K in Exclude>]: never; +}; +export {}; diff --git a/dist/client_api.js b/dist/client_api.js new file mode 100644 index 0000000..d76c382 --- /dev/null +++ b/dist/client_api.js @@ -0,0 +1,1240 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.OneOffTable = exports.OneOffQueryResponse = exports.OneOffQuery = exports.TransactionUpdate = exports.TableRowOperation = exports.TableUpdate = exports.SubscriptionUpdate = exports.Event = exports.Subscribe = exports.FunctionCall = exports.IdentityToken = exports.Message = exports.tableRowOperation_OperationTypeToJSON = exports.tableRowOperation_OperationTypeFromJSON = exports.TableRowOperation_OperationType = exports.event_StatusToJSON = exports.event_StatusFromJSON = exports.Event_Status = exports.protobufPackage = void 0; +/* eslint-disable */ +const _m0 = __importStar(require("protobufjs/minimal")); +const long_1 = __importDefault(require("long")); +exports.protobufPackage = "client_api"; +var Event_Status; +(function (Event_Status) { + Event_Status[Event_Status["committed"] = 0] = "committed"; + Event_Status[Event_Status["failed"] = 1] = "failed"; + Event_Status[Event_Status["out_of_energy"] = 2] = "out_of_energy"; + Event_Status[Event_Status["UNRECOGNIZED"] = -1] = "UNRECOGNIZED"; +})(Event_Status = exports.Event_Status || (exports.Event_Status = {})); +function event_StatusFromJSON(object) { + switch (object) { + case 0: + case "committed": + return Event_Status.committed; + case 1: + case "failed": + return Event_Status.failed; + case 2: + case "out_of_energy": + return Event_Status.out_of_energy; + case -1: + case "UNRECOGNIZED": + default: + return Event_Status.UNRECOGNIZED; + } +} +exports.event_StatusFromJSON = event_StatusFromJSON; +function event_StatusToJSON(object) { + switch (object) { + case Event_Status.committed: + return "committed"; + case Event_Status.failed: + return "failed"; + case Event_Status.out_of_energy: + return "out_of_energy"; + case Event_Status.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} +exports.event_StatusToJSON = event_StatusToJSON; +var TableRowOperation_OperationType; +(function (TableRowOperation_OperationType) { + TableRowOperation_OperationType[TableRowOperation_OperationType["DELETE"] = 0] = "DELETE"; + TableRowOperation_OperationType[TableRowOperation_OperationType["INSERT"] = 1] = "INSERT"; + TableRowOperation_OperationType[TableRowOperation_OperationType["UNRECOGNIZED"] = -1] = "UNRECOGNIZED"; +})(TableRowOperation_OperationType = exports.TableRowOperation_OperationType || (exports.TableRowOperation_OperationType = {})); +function tableRowOperation_OperationTypeFromJSON(object) { + switch (object) { + case 0: + case "DELETE": + return TableRowOperation_OperationType.DELETE; + case 1: + case "INSERT": + return TableRowOperation_OperationType.INSERT; + case -1: + case "UNRECOGNIZED": + default: + return TableRowOperation_OperationType.UNRECOGNIZED; + } +} +exports.tableRowOperation_OperationTypeFromJSON = tableRowOperation_OperationTypeFromJSON; +function tableRowOperation_OperationTypeToJSON(object) { + switch (object) { + case TableRowOperation_OperationType.DELETE: + return "DELETE"; + case TableRowOperation_OperationType.INSERT: + return "INSERT"; + case TableRowOperation_OperationType.UNRECOGNIZED: + default: + return "UNRECOGNIZED"; + } +} +exports.tableRowOperation_OperationTypeToJSON = tableRowOperation_OperationTypeToJSON; +function createBaseMessage() { + return { + functionCall: undefined, + subscriptionUpdate: undefined, + event: undefined, + transactionUpdate: undefined, + identityToken: undefined, + subscribe: undefined, + oneOffQuery: undefined, + oneOffQueryResponse: undefined, + }; +} +exports.Message = { + encode(message, writer = _m0.Writer.create()) { + if (message.functionCall !== undefined) { + exports.FunctionCall.encode(message.functionCall, writer.uint32(10).fork()).ldelim(); + } + if (message.subscriptionUpdate !== undefined) { + exports.SubscriptionUpdate.encode(message.subscriptionUpdate, writer.uint32(18).fork()).ldelim(); + } + if (message.event !== undefined) { + exports.Event.encode(message.event, writer.uint32(26).fork()).ldelim(); + } + if (message.transactionUpdate !== undefined) { + exports.TransactionUpdate.encode(message.transactionUpdate, writer.uint32(34).fork()).ldelim(); + } + if (message.identityToken !== undefined) { + exports.IdentityToken.encode(message.identityToken, writer.uint32(42).fork()).ldelim(); + } + if (message.subscribe !== undefined) { + exports.Subscribe.encode(message.subscribe, writer.uint32(50).fork()).ldelim(); + } + if (message.oneOffQuery !== undefined) { + exports.OneOffQuery.encode(message.oneOffQuery, writer.uint32(58).fork()).ldelim(); + } + if (message.oneOffQueryResponse !== undefined) { + exports.OneOffQueryResponse.encode(message.oneOffQueryResponse, writer.uint32(66).fork()).ldelim(); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseMessage(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + message.functionCall = exports.FunctionCall.decode(reader, reader.uint32()); + continue; + case 2: + if (tag !== 18) { + break; + } + message.subscriptionUpdate = exports.SubscriptionUpdate.decode(reader, reader.uint32()); + continue; + case 3: + if (tag !== 26) { + break; + } + message.event = exports.Event.decode(reader, reader.uint32()); + continue; + case 4: + if (tag !== 34) { + break; + } + message.transactionUpdate = exports.TransactionUpdate.decode(reader, reader.uint32()); + continue; + case 5: + if (tag !== 42) { + break; + } + message.identityToken = exports.IdentityToken.decode(reader, reader.uint32()); + continue; + case 6: + if (tag !== 50) { + break; + } + message.subscribe = exports.Subscribe.decode(reader, reader.uint32()); + continue; + case 7: + if (tag !== 58) { + break; + } + message.oneOffQuery = exports.OneOffQuery.decode(reader, reader.uint32()); + continue; + case 8: + if (tag !== 66) { + break; + } + message.oneOffQueryResponse = exports.OneOffQueryResponse.decode(reader, reader.uint32()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + functionCall: isSet(object.functionCall) + ? exports.FunctionCall.fromJSON(object.functionCall) + : undefined, + subscriptionUpdate: isSet(object.subscriptionUpdate) + ? exports.SubscriptionUpdate.fromJSON(object.subscriptionUpdate) + : undefined, + event: isSet(object.event) ? exports.Event.fromJSON(object.event) : undefined, + transactionUpdate: isSet(object.transactionUpdate) + ? exports.TransactionUpdate.fromJSON(object.transactionUpdate) + : undefined, + identityToken: isSet(object.identityToken) + ? exports.IdentityToken.fromJSON(object.identityToken) + : undefined, + subscribe: isSet(object.subscribe) + ? exports.Subscribe.fromJSON(object.subscribe) + : undefined, + oneOffQuery: isSet(object.oneOffQuery) + ? exports.OneOffQuery.fromJSON(object.oneOffQuery) + : undefined, + oneOffQueryResponse: isSet(object.oneOffQueryResponse) + ? exports.OneOffQueryResponse.fromJSON(object.oneOffQueryResponse) + : undefined, + }; + }, + toJSON(message) { + const obj = {}; + if (message.functionCall !== undefined) { + obj.functionCall = exports.FunctionCall.toJSON(message.functionCall); + } + if (message.subscriptionUpdate !== undefined) { + obj.subscriptionUpdate = exports.SubscriptionUpdate.toJSON(message.subscriptionUpdate); + } + if (message.event !== undefined) { + obj.event = exports.Event.toJSON(message.event); + } + if (message.transactionUpdate !== undefined) { + obj.transactionUpdate = exports.TransactionUpdate.toJSON(message.transactionUpdate); + } + if (message.identityToken !== undefined) { + obj.identityToken = exports.IdentityToken.toJSON(message.identityToken); + } + if (message.subscribe !== undefined) { + obj.subscribe = exports.Subscribe.toJSON(message.subscribe); + } + if (message.oneOffQuery !== undefined) { + obj.oneOffQuery = exports.OneOffQuery.toJSON(message.oneOffQuery); + } + if (message.oneOffQueryResponse !== undefined) { + obj.oneOffQueryResponse = exports.OneOffQueryResponse.toJSON(message.oneOffQueryResponse); + } + return obj; + }, + create(base) { + return exports.Message.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseMessage(); + message.functionCall = + object.functionCall !== undefined && object.functionCall !== null + ? exports.FunctionCall.fromPartial(object.functionCall) + : undefined; + message.subscriptionUpdate = + object.subscriptionUpdate !== undefined && + object.subscriptionUpdate !== null + ? exports.SubscriptionUpdate.fromPartial(object.subscriptionUpdate) + : undefined; + message.event = + object.event !== undefined && object.event !== null + ? exports.Event.fromPartial(object.event) + : undefined; + message.transactionUpdate = + object.transactionUpdate !== undefined && + object.transactionUpdate !== null + ? exports.TransactionUpdate.fromPartial(object.transactionUpdate) + : undefined; + message.identityToken = + object.identityToken !== undefined && object.identityToken !== null + ? exports.IdentityToken.fromPartial(object.identityToken) + : undefined; + message.subscribe = + object.subscribe !== undefined && object.subscribe !== null + ? exports.Subscribe.fromPartial(object.subscribe) + : undefined; + message.oneOffQuery = + object.oneOffQuery !== undefined && object.oneOffQuery !== null + ? exports.OneOffQuery.fromPartial(object.oneOffQuery) + : undefined; + message.oneOffQueryResponse = + object.oneOffQueryResponse !== undefined && + object.oneOffQueryResponse !== null + ? exports.OneOffQueryResponse.fromPartial(object.oneOffQueryResponse) + : undefined; + return message; + }, +}; +function createBaseIdentityToken() { + return { identity: new Uint8Array(0), token: "", address: new Uint8Array(0) }; +} +exports.IdentityToken = { + encode(message, writer = _m0.Writer.create()) { + if (message.identity.length !== 0) { + writer.uint32(10).bytes(message.identity); + } + if (message.token !== "") { + writer.uint32(18).string(message.token); + } + if (message.address.length !== 0) { + writer.uint32(26).bytes(message.address); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseIdentityToken(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + message.identity = reader.bytes(); + continue; + case 2: + if (tag !== 18) { + break; + } + message.token = reader.string(); + continue; + case 3: + if (tag !== 26) { + break; + } + message.address = reader.bytes(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + identity: isSet(object.identity) + ? bytesFromBase64(object.identity) + : new Uint8Array(0), + token: isSet(object.token) ? String(object.token) : "", + address: isSet(object.address) + ? bytesFromBase64(object.address) + : new Uint8Array(0), + }; + }, + toJSON(message) { + const obj = {}; + if (message.identity.length !== 0) { + obj.identity = base64FromBytes(message.identity); + } + if (message.token !== "") { + obj.token = message.token; + } + if (message.address.length !== 0) { + obj.address = base64FromBytes(message.address); + } + return obj; + }, + create(base) { + return exports.IdentityToken.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseIdentityToken(); + message.identity = object.identity ?? new Uint8Array(0); + message.token = object.token ?? ""; + message.address = object.address ?? new Uint8Array(0); + return message; + }, +}; +function createBaseFunctionCall() { + return { reducer: "", argBytes: new Uint8Array(0) }; +} +exports.FunctionCall = { + encode(message, writer = _m0.Writer.create()) { + if (message.reducer !== "") { + writer.uint32(10).string(message.reducer); + } + if (message.argBytes.length !== 0) { + writer.uint32(18).bytes(message.argBytes); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseFunctionCall(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + message.reducer = reader.string(); + continue; + case 2: + if (tag !== 18) { + break; + } + message.argBytes = reader.bytes(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + reducer: isSet(object.reducer) ? String(object.reducer) : "", + argBytes: isSet(object.argBytes) + ? bytesFromBase64(object.argBytes) + : new Uint8Array(0), + }; + }, + toJSON(message) { + const obj = {}; + if (message.reducer !== "") { + obj.reducer = message.reducer; + } + if (message.argBytes.length !== 0) { + obj.argBytes = base64FromBytes(message.argBytes); + } + return obj; + }, + create(base) { + return exports.FunctionCall.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseFunctionCall(); + message.reducer = object.reducer ?? ""; + message.argBytes = object.argBytes ?? new Uint8Array(0); + return message; + }, +}; +function createBaseSubscribe() { + return { queryStrings: [] }; +} +exports.Subscribe = { + encode(message, writer = _m0.Writer.create()) { + for (const v of message.queryStrings) { + writer.uint32(10).string(v); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseSubscribe(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + message.queryStrings.push(reader.string()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + queryStrings: Array.isArray(object?.queryStrings) + ? object.queryStrings.map((e) => String(e)) + : [], + }; + }, + toJSON(message) { + const obj = {}; + if (message.queryStrings?.length) { + obj.queryStrings = message.queryStrings; + } + return obj; + }, + create(base) { + return exports.Subscribe.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseSubscribe(); + message.queryStrings = object.queryStrings?.map((e) => e) || []; + return message; + }, +}; +function createBaseEvent() { + return { + timestamp: 0, + callerIdentity: new Uint8Array(0), + functionCall: undefined, + status: 0, + message: "", + energyQuantaUsed: 0, + hostExecutionDurationMicros: 0, + callerAddress: new Uint8Array(0), + }; +} +exports.Event = { + encode(message, writer = _m0.Writer.create()) { + if (message.timestamp !== 0) { + writer.uint32(8).uint64(message.timestamp); + } + if (message.callerIdentity.length !== 0) { + writer.uint32(18).bytes(message.callerIdentity); + } + if (message.functionCall !== undefined) { + exports.FunctionCall.encode(message.functionCall, writer.uint32(26).fork()).ldelim(); + } + if (message.status !== 0) { + writer.uint32(32).int32(message.status); + } + if (message.message !== "") { + writer.uint32(42).string(message.message); + } + if (message.energyQuantaUsed !== 0) { + writer.uint32(48).int64(message.energyQuantaUsed); + } + if (message.hostExecutionDurationMicros !== 0) { + writer.uint32(56).uint64(message.hostExecutionDurationMicros); + } + if (message.callerAddress.length !== 0) { + writer.uint32(66).bytes(message.callerAddress); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseEvent(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + message.timestamp = longToNumber(reader.uint64()); + continue; + case 2: + if (tag !== 18) { + break; + } + message.callerIdentity = reader.bytes(); + continue; + case 3: + if (tag !== 26) { + break; + } + message.functionCall = exports.FunctionCall.decode(reader, reader.uint32()); + continue; + case 4: + if (tag !== 32) { + break; + } + message.status = reader.int32(); + continue; + case 5: + if (tag !== 42) { + break; + } + message.message = reader.string(); + continue; + case 6: + if (tag !== 48) { + break; + } + message.energyQuantaUsed = longToNumber(reader.int64()); + continue; + case 7: + if (tag !== 56) { + break; + } + message.hostExecutionDurationMicros = longToNumber(reader.uint64()); + continue; + case 8: + if (tag !== 66) { + break; + } + message.callerAddress = reader.bytes(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + timestamp: isSet(object.timestamp) ? Number(object.timestamp) : 0, + callerIdentity: isSet(object.callerIdentity) + ? bytesFromBase64(object.callerIdentity) + : new Uint8Array(0), + functionCall: isSet(object.functionCall) + ? exports.FunctionCall.fromJSON(object.functionCall) + : undefined, + status: isSet(object.status) ? event_StatusFromJSON(object.status) : 0, + message: isSet(object.message) ? String(object.message) : "", + energyQuantaUsed: isSet(object.energyQuantaUsed) + ? Number(object.energyQuantaUsed) + : 0, + hostExecutionDurationMicros: isSet(object.hostExecutionDurationMicros) + ? Number(object.hostExecutionDurationMicros) + : 0, + callerAddress: isSet(object.callerAddress) + ? bytesFromBase64(object.callerAddress) + : new Uint8Array(0), + }; + }, + toJSON(message) { + const obj = {}; + if (message.timestamp !== 0) { + obj.timestamp = Math.round(message.timestamp); + } + if (message.callerIdentity.length !== 0) { + obj.callerIdentity = base64FromBytes(message.callerIdentity); + } + if (message.functionCall !== undefined) { + obj.functionCall = exports.FunctionCall.toJSON(message.functionCall); + } + if (message.status !== 0) { + obj.status = event_StatusToJSON(message.status); + } + if (message.message !== "") { + obj.message = message.message; + } + if (message.energyQuantaUsed !== 0) { + obj.energyQuantaUsed = Math.round(message.energyQuantaUsed); + } + if (message.hostExecutionDurationMicros !== 0) { + obj.hostExecutionDurationMicros = Math.round(message.hostExecutionDurationMicros); + } + if (message.callerAddress.length !== 0) { + obj.callerAddress = base64FromBytes(message.callerAddress); + } + return obj; + }, + create(base) { + return exports.Event.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseEvent(); + message.timestamp = object.timestamp ?? 0; + message.callerIdentity = object.callerIdentity ?? new Uint8Array(0); + message.functionCall = + object.functionCall !== undefined && object.functionCall !== null + ? exports.FunctionCall.fromPartial(object.functionCall) + : undefined; + message.status = object.status ?? 0; + message.message = object.message ?? ""; + message.energyQuantaUsed = object.energyQuantaUsed ?? 0; + message.hostExecutionDurationMicros = + object.hostExecutionDurationMicros ?? 0; + message.callerAddress = object.callerAddress ?? new Uint8Array(0); + return message; + }, +}; +function createBaseSubscriptionUpdate() { + return { tableUpdates: [] }; +} +exports.SubscriptionUpdate = { + encode(message, writer = _m0.Writer.create()) { + for (const v of message.tableUpdates) { + exports.TableUpdate.encode(v, writer.uint32(10).fork()).ldelim(); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseSubscriptionUpdate(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + message.tableUpdates.push(exports.TableUpdate.decode(reader, reader.uint32())); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + tableUpdates: Array.isArray(object?.tableUpdates) + ? object.tableUpdates.map((e) => exports.TableUpdate.fromJSON(e)) + : [], + }; + }, + toJSON(message) { + const obj = {}; + if (message.tableUpdates?.length) { + obj.tableUpdates = message.tableUpdates.map((e) => exports.TableUpdate.toJSON(e)); + } + return obj; + }, + create(base) { + return exports.SubscriptionUpdate.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseSubscriptionUpdate(); + message.tableUpdates = + object.tableUpdates?.map((e) => exports.TableUpdate.fromPartial(e)) || []; + return message; + }, +}; +function createBaseTableUpdate() { + return { tableId: 0, tableName: "", tableRowOperations: [] }; +} +exports.TableUpdate = { + encode(message, writer = _m0.Writer.create()) { + if (message.tableId !== 0) { + writer.uint32(8).uint32(message.tableId); + } + if (message.tableName !== "") { + writer.uint32(18).string(message.tableName); + } + for (const v of message.tableRowOperations) { + exports.TableRowOperation.encode(v, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseTableUpdate(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + message.tableId = reader.uint32(); + continue; + case 2: + if (tag !== 18) { + break; + } + message.tableName = reader.string(); + continue; + case 3: + if (tag !== 26) { + break; + } + message.tableRowOperations.push(exports.TableRowOperation.decode(reader, reader.uint32())); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + tableId: isSet(object.tableId) ? Number(object.tableId) : 0, + tableName: isSet(object.tableName) ? String(object.tableName) : "", + tableRowOperations: Array.isArray(object?.tableRowOperations) + ? object.tableRowOperations.map((e) => exports.TableRowOperation.fromJSON(e)) + : [], + }; + }, + toJSON(message) { + const obj = {}; + if (message.tableId !== 0) { + obj.tableId = Math.round(message.tableId); + } + if (message.tableName !== "") { + obj.tableName = message.tableName; + } + if (message.tableRowOperations?.length) { + obj.tableRowOperations = message.tableRowOperations.map((e) => exports.TableRowOperation.toJSON(e)); + } + return obj; + }, + create(base) { + return exports.TableUpdate.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseTableUpdate(); + message.tableId = object.tableId ?? 0; + message.tableName = object.tableName ?? ""; + message.tableRowOperations = + object.tableRowOperations?.map((e) => exports.TableRowOperation.fromPartial(e)) || + []; + return message; + }, +}; +function createBaseTableRowOperation() { + return { op: 0, row: new Uint8Array(0) }; +} +exports.TableRowOperation = { + encode(message, writer = _m0.Writer.create()) { + if (message.op !== 0) { + writer.uint32(8).int32(message.op); + } + if (message.row.length !== 0) { + writer.uint32(26).bytes(message.row); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseTableRowOperation(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 8) { + break; + } + message.op = reader.int32(); + continue; + case 3: + if (tag !== 26) { + break; + } + message.row = reader.bytes(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + op: isSet(object.op) + ? tableRowOperation_OperationTypeFromJSON(object.op) + : 0, + row: isSet(object.row) ? bytesFromBase64(object.row) : new Uint8Array(0), + }; + }, + toJSON(message) { + const obj = {}; + if (message.op !== 0) { + obj.op = tableRowOperation_OperationTypeToJSON(message.op); + } + if (message.row.length !== 0) { + obj.row = base64FromBytes(message.row); + } + return obj; + }, + create(base) { + return exports.TableRowOperation.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseTableRowOperation(); + message.op = object.op ?? 0; + message.row = object.row ?? new Uint8Array(0); + return message; + }, +}; +function createBaseTransactionUpdate() { + return { event: undefined, subscriptionUpdate: undefined }; +} +exports.TransactionUpdate = { + encode(message, writer = _m0.Writer.create()) { + if (message.event !== undefined) { + exports.Event.encode(message.event, writer.uint32(10).fork()).ldelim(); + } + if (message.subscriptionUpdate !== undefined) { + exports.SubscriptionUpdate.encode(message.subscriptionUpdate, writer.uint32(18).fork()).ldelim(); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseTransactionUpdate(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + message.event = exports.Event.decode(reader, reader.uint32()); + continue; + case 2: + if (tag !== 18) { + break; + } + message.subscriptionUpdate = exports.SubscriptionUpdate.decode(reader, reader.uint32()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + event: isSet(object.event) ? exports.Event.fromJSON(object.event) : undefined, + subscriptionUpdate: isSet(object.subscriptionUpdate) + ? exports.SubscriptionUpdate.fromJSON(object.subscriptionUpdate) + : undefined, + }; + }, + toJSON(message) { + const obj = {}; + if (message.event !== undefined) { + obj.event = exports.Event.toJSON(message.event); + } + if (message.subscriptionUpdate !== undefined) { + obj.subscriptionUpdate = exports.SubscriptionUpdate.toJSON(message.subscriptionUpdate); + } + return obj; + }, + create(base) { + return exports.TransactionUpdate.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseTransactionUpdate(); + message.event = + object.event !== undefined && object.event !== null + ? exports.Event.fromPartial(object.event) + : undefined; + message.subscriptionUpdate = + object.subscriptionUpdate !== undefined && + object.subscriptionUpdate !== null + ? exports.SubscriptionUpdate.fromPartial(object.subscriptionUpdate) + : undefined; + return message; + }, +}; +function createBaseOneOffQuery() { + return { messageId: new Uint8Array(0), queryString: "" }; +} +exports.OneOffQuery = { + encode(message, writer = _m0.Writer.create()) { + if (message.messageId.length !== 0) { + writer.uint32(10).bytes(message.messageId); + } + if (message.queryString !== "") { + writer.uint32(18).string(message.queryString); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseOneOffQuery(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + message.messageId = reader.bytes(); + continue; + case 2: + if (tag !== 18) { + break; + } + message.queryString = reader.string(); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + messageId: isSet(object.messageId) + ? bytesFromBase64(object.messageId) + : new Uint8Array(0), + queryString: isSet(object.queryString) ? String(object.queryString) : "", + }; + }, + toJSON(message) { + const obj = {}; + if (message.messageId.length !== 0) { + obj.messageId = base64FromBytes(message.messageId); + } + if (message.queryString !== "") { + obj.queryString = message.queryString; + } + return obj; + }, + create(base) { + return exports.OneOffQuery.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseOneOffQuery(); + message.messageId = object.messageId ?? new Uint8Array(0); + message.queryString = object.queryString ?? ""; + return message; + }, +}; +function createBaseOneOffQueryResponse() { + return { messageId: new Uint8Array(0), error: "", tables: [] }; +} +exports.OneOffQueryResponse = { + encode(message, writer = _m0.Writer.create()) { + if (message.messageId.length !== 0) { + writer.uint32(10).bytes(message.messageId); + } + if (message.error !== "") { + writer.uint32(18).string(message.error); + } + for (const v of message.tables) { + exports.OneOffTable.encode(v, writer.uint32(26).fork()).ldelim(); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseOneOffQueryResponse(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (tag !== 10) { + break; + } + message.messageId = reader.bytes(); + continue; + case 2: + if (tag !== 18) { + break; + } + message.error = reader.string(); + continue; + case 3: + if (tag !== 26) { + break; + } + message.tables.push(exports.OneOffTable.decode(reader, reader.uint32())); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + messageId: isSet(object.messageId) + ? bytesFromBase64(object.messageId) + : new Uint8Array(0), + error: isSet(object.error) ? String(object.error) : "", + tables: Array.isArray(object?.tables) + ? object.tables.map((e) => exports.OneOffTable.fromJSON(e)) + : [], + }; + }, + toJSON(message) { + const obj = {}; + if (message.messageId.length !== 0) { + obj.messageId = base64FromBytes(message.messageId); + } + if (message.error !== "") { + obj.error = message.error; + } + if (message.tables?.length) { + obj.tables = message.tables.map((e) => exports.OneOffTable.toJSON(e)); + } + return obj; + }, + create(base) { + return exports.OneOffQueryResponse.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseOneOffQueryResponse(); + message.messageId = object.messageId ?? new Uint8Array(0); + message.error = object.error ?? ""; + message.tables = + object.tables?.map((e) => exports.OneOffTable.fromPartial(e)) || []; + return message; + }, +}; +function createBaseOneOffTable() { + return { tableName: "", row: [] }; +} +exports.OneOffTable = { + encode(message, writer = _m0.Writer.create()) { + if (message.tableName !== "") { + writer.uint32(18).string(message.tableName); + } + for (const v of message.row) { + writer.uint32(34).bytes(v); + } + return writer; + }, + decode(input, length) { + const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBaseOneOffTable(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 2: + if (tag !== 18) { + break; + } + message.tableName = reader.string(); + continue; + case 4: + if (tag !== 34) { + break; + } + message.row.push(reader.bytes()); + continue; + } + if ((tag & 7) === 4 || tag === 0) { + break; + } + reader.skipType(tag & 7); + } + return message; + }, + fromJSON(object) { + return { + tableName: isSet(object.tableName) ? String(object.tableName) : "", + row: Array.isArray(object?.row) + ? object.row.map((e) => bytesFromBase64(e)) + : [], + }; + }, + toJSON(message) { + const obj = {}; + if (message.tableName !== "") { + obj.tableName = message.tableName; + } + if (message.row?.length) { + obj.row = message.row.map((e) => base64FromBytes(e)); + } + return obj; + }, + create(base) { + return exports.OneOffTable.fromPartial(base ?? {}); + }, + fromPartial(object) { + const message = createBaseOneOffTable(); + message.tableName = object.tableName ?? ""; + message.row = object.row?.map((e) => e) || []; + return message; + }, +}; +const tsProtoGlobalThis = (() => { + if (typeof globalThis !== "undefined") { + return globalThis; + } + if (typeof self !== "undefined") { + return self; + } + if (typeof window !== "undefined") { + return window; + } + if (typeof global !== "undefined") { + return global; + } + throw "Unable to locate global object"; +})(); +function bytesFromBase64(b64) { + if (tsProtoGlobalThis.Buffer) { + return Uint8Array.from(tsProtoGlobalThis.Buffer.from(b64, "base64")); + } + else { + const bin = tsProtoGlobalThis.atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); + } + return arr; + } +} +function base64FromBytes(arr) { + if (tsProtoGlobalThis.Buffer) { + return tsProtoGlobalThis.Buffer.from(arr).toString("base64"); + } + else { + const bin = []; + arr.forEach((byte) => { + bin.push(String.fromCharCode(byte)); + }); + return tsProtoGlobalThis.btoa(bin.join("")); + } +} +function longToNumber(long) { + if (long.gt(Number.MAX_SAFE_INTEGER)) { + throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER"); + } + return long.toNumber(); +} +if (_m0.util.Long !== long_1.default) { + _m0.util.Long = long_1.default; + _m0.configure(); +} +function isSet(value) { + return value !== null && value !== undefined; +} diff --git a/dist/client_db.d.ts b/dist/client_db.d.ts new file mode 100644 index 0000000..c11a32e --- /dev/null +++ b/dist/client_db.d.ts @@ -0,0 +1,16 @@ +import { DatabaseTableClass } from "."; +import { Table } from "./table"; +export declare class ClientDB { + /** + * The tables in the database. + */ + tables: Map; + constructor(); + /** + * Returns the table with the given name. + * @param name The name of the table. + * @returns The table + */ + getTable(name: string): Table; + getOrCreateTable(tableName: string, pkCol: number | undefined, entityClass: DatabaseTableClass): Table; +} diff --git a/dist/client_db.js b/dist/client_db.js new file mode 100644 index 0000000..75cd3ff --- /dev/null +++ b/dist/client_db.js @@ -0,0 +1,39 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ClientDB = void 0; +const table_1 = require("./table"); +class ClientDB { + /** + * The tables in the database. + */ + tables; + constructor() { + this.tables = new Map(); + } + /** + * Returns the table with the given name. + * @param name The name of the table. + * @returns The table + */ + getTable(name) { + const table = this.tables.get(name); + // ! This should not happen as the table should be available but an exception is thrown just in case. + if (!table) { + console.error("The table has not been registered for this client. Please register the table before using it. If you have registered global tables using the SpacetimeDBClient.registerTables() or `registerTable()` method, please make sure that is executed first!"); + throw new Error(`Table ${name} does not exist`); + } + return table; + } + getOrCreateTable(tableName, pkCol, entityClass) { + let table; + if (!this.tables.has(tableName)) { + table = new table_1.Table(tableName, pkCol, entityClass); + this.tables.set(tableName, table); + } + else { + table = this.tables.get(tableName); + } + return table; + } +} +exports.ClientDB = ClientDB; diff --git a/dist/database_table.d.ts b/dist/database_table.d.ts new file mode 100644 index 0000000..75b1593 --- /dev/null +++ b/dist/database_table.d.ts @@ -0,0 +1,28 @@ +import { ClientDB } from "./client_db"; +import { ReducerEvent } from "./reducer_event"; +import { SpacetimeDBClient } from "./spacetimedb"; +export type DatabaseTableClass = { + new (...args: any[]): any; + db?: ClientDB; + tableName: string; +}; +type ThisDatabaseType = { + new (...args: any): T; + tableName: string; + getDB: () => ClientDB; +}; +export declare class DatabaseTable { + static db?: ClientDB; + static tableName: string; + static with(this: T, client: SpacetimeDBClient): T; + static getDB(): ClientDB; + static count(): number; + static all(this: ThisDatabaseType): T[]; + static onInsert(this: ThisDatabaseType, callback: (value: T, reducerEvent: ReducerEvent | undefined) => void): void; + static onUpdate(this: ThisDatabaseType, callback: (oldValue: T, newValue: T, reducerEvent: ReducerEvent | undefined) => void): void; + static onDelete(this: ThisDatabaseType, callback: (value: T, reducerEvent: ReducerEvent | undefined) => void): void; + static removeOnInsert(this: ThisDatabaseType, callback: (value: T, reducerEvent: ReducerEvent | undefined) => void): void; + static removeOnUpdate(this: ThisDatabaseType, callback: (oldValue: T, newValue: T, reducerEvent: ReducerEvent | undefined) => void): void; + static removeOnDelete(this: ThisDatabaseType, callback: (value: T, reducerEvent: ReducerEvent | undefined) => void): void; +} +export {}; diff --git a/dist/database_table.js b/dist/database_table.js new file mode 100644 index 0000000..c8d9de4 --- /dev/null +++ b/dist/database_table.js @@ -0,0 +1,44 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.DatabaseTable = void 0; +const utils_1 = require("./utils"); +class DatabaseTable { + static db; + static tableName; + static with(client) { + return (0, utils_1._tableProxy)(this, client); + } + static getDB() { + if (!this.db) { + throw "You can't query the database without creating a client first"; + } + return this.db; + } + static count() { + return this.getDB().getTable(this.tableName).count(); + } + static all() { + return this.getDB() + .getTable(this.tableName) + .getInstances(); + } + static onInsert(callback) { + this.getDB().getTable(this.tableName).onInsert(callback); + } + static onUpdate(callback) { + this.getDB().getTable(this.tableName).onUpdate(callback); + } + static onDelete(callback) { + this.getDB().getTable(this.tableName).onDelete(callback); + } + static removeOnInsert(callback) { + this.getDB().getTable(this.tableName).removeOnInsert(callback); + } + static removeOnUpdate(callback) { + this.getDB().getTable(this.tableName).removeOnUpdate(callback); + } + static removeOnDelete(callback) { + this.getDB().getTable(this.tableName).removeOnDelete(callback); + } +} +exports.DatabaseTable = DatabaseTable; diff --git a/dist/global.d.ts b/dist/global.d.ts new file mode 100644 index 0000000..24982ab --- /dev/null +++ b/dist/global.d.ts @@ -0,0 +1,12 @@ +import { ClientDB } from "./client_db"; +import { SpacetimeDBClient } from "./spacetimedb"; +export type SpacetimeDBGlobals = { + clientDB: ClientDB; + spacetimeDBClient: SpacetimeDBClient | undefined; +}; +declare global { + interface Window { + __SPACETIMEDB__: SpacetimeDBGlobals; + } + var __SPACETIMEDB__: SpacetimeDBGlobals; +} diff --git a/dist/global.js b/dist/global.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/global.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/identity.d.ts b/dist/identity.d.ts new file mode 100644 index 0000000..025b960 --- /dev/null +++ b/dist/identity.d.ts @@ -0,0 +1,23 @@ +/** + * A unique public identifier for a user connected to a database. + */ +export declare class Identity { + private data; + /** + * Creates a new `Identity`. + */ + constructor(data: string | Uint8Array); + /** + * Compare two identities for equality. + */ + isEqual(other: Identity): boolean; + /** + * Print the identity as a hexadecimal string. + */ + toHexString(): string; + toUint8Array(): Uint8Array; + /** + * Parse an Identity from a hexadecimal string. + */ + static fromString(str: string): Identity; +} diff --git a/dist/identity.js b/dist/identity.js new file mode 100644 index 0000000..84a4778 --- /dev/null +++ b/dist/identity.js @@ -0,0 +1,54 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Identity = void 0; +// Helper function convert from string to Uint8Array +function hexStringToUint8Array(str) { + let matches = str.match(/.{1,2}/g) || []; + let data = Uint8Array.from(matches.map((byte) => parseInt(byte, 16))); + return data; +} +// Helper function for converting Uint8Array to hex string +function uint8ArrayToHexString(array) { + return Array.prototype.map + .call(array, (x) => ("00" + x.toString(16)).slice(-2)) + .join(""); +} +/** + * A unique public identifier for a user connected to a database. + */ +class Identity { + data; + /** + * Creates a new `Identity`. + */ + constructor(data) { + // we get a JSON with __identity_bytes when getting a token with a JSON API + // and an Uint8Array when using BSATN + this.data = + data.constructor === Uint8Array + ? uint8ArrayToHexString(data) + : data; + } + /** + * Compare two identities for equality. + */ + isEqual(other) { + return this.toHexString() === other.toHexString(); + } + /** + * Print the identity as a hexadecimal string. + */ + toHexString() { + return this.data; + } + toUint8Array() { + return hexStringToUint8Array(this.toHexString()); + } + /** + * Parse an Identity from a hexadecimal string. + */ + static fromString(str) { + return new Identity(str); + } +} +exports.Identity = Identity; diff --git a/dist/index.d.ts b/dist/index.d.ts new file mode 100644 index 0000000..c622911 --- /dev/null +++ b/dist/index.d.ts @@ -0,0 +1,5 @@ +export * from "./spacetimedb"; +export * from "./identity"; +export * from "./address"; +export * from "./client_db"; +export * from "./message_types"; diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..6436b12 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,21 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +__exportStar(require("./spacetimedb"), exports); +__exportStar(require("./identity"), exports); +__exportStar(require("./address"), exports); +__exportStar(require("./client_db"), exports); +__exportStar(require("./message_types"), exports); diff --git a/dist/json_api.d.ts b/dist/json_api.d.ts new file mode 100644 index 0000000..faf8a4c --- /dev/null +++ b/dist/json_api.d.ts @@ -0,0 +1,39 @@ +export interface Message { + IdentityToken?: IdentityToken | undefined; + SubscriptionUpdate?: SubscriptionUpdate | undefined; + TransactionUpdate?: TransactionUpdate | undefined; +} +export interface IdentityToken { + identity: string; + token: string; + address: string; +} +export interface SubscriptionUpdate { + table_updates: TableUpdate[]; +} +export interface TableUpdate { + table_id: number; + table_name: string; + table_row_operations: TableRowOperation[]; +} +export interface TableRowOperation { + op: "insert" | "delete"; + row: any[]; +} +export interface TransactionUpdate { + event: Event; + subscription_update: SubscriptionUpdate; +} +export interface Event { + timestamp: number; + status: "committed" | "failed" | "out_of_energy"; + caller_identity: string; + caller_address: string; + function_call: FunctionCall; + energy_quanta_used: number; + message: string; +} +export interface FunctionCall { + reducer: string; + args: string; +} diff --git a/dist/json_api.js b/dist/json_api.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/json_api.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/logger.d.ts b/dist/logger.d.ts new file mode 100644 index 0000000..d9ca8ef --- /dev/null +++ b/dist/logger.d.ts @@ -0,0 +1,3 @@ +type LogLevel = "info" | "warn" | "error" | "debug"; +export declare const stdbLogger: (level: LogLevel, message: any) => void; +export {}; diff --git a/dist/logger.js b/dist/logger.js new file mode 100644 index 0000000..50d4942 --- /dev/null +++ b/dist/logger.js @@ -0,0 +1,28 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.stdbLogger = void 0; +const LogLevelIdentifierIcon = { + component: "📦", + info: "ℹ️", + warn: "⚠️", + error: "❌", + debug: "🐛", +}; +const LogStyle = { + component: "color: #fff; background-color: #8D6FDD; padding: 2px 5px; border-radius: 3px;", + info: "color: #fff; background-color: #007bff; padding: 2px 5px; border-radius: 3px;", + warn: "color: #fff; background-color: #ffc107; padding: 2px 5px; border-radius: 3px;", + error: "color: #fff; background-color: #dc3545; padding: 2px 5px; border-radius: 3px;", + debug: "color: #fff; background-color: #28a745; padding: 2px 5px; border-radius: 3px;", +}; +const LogTextStyle = { + component: "color: #8D6FDD;", + info: "color: #007bff;", + warn: "color: #ffc107;", + error: "color: #dc3545;", + debug: "color: #28a745;", +}; +const stdbLogger = (level, message) => { + console.log(`%c${LogLevelIdentifierIcon[level]} ${level.toUpperCase()}%c ${message}`, LogStyle[level], LogTextStyle[level]); +}; +exports.stdbLogger = stdbLogger; diff --git a/dist/message_types.d.ts b/dist/message_types.d.ts new file mode 100644 index 0000000..73dcc4d --- /dev/null +++ b/dist/message_types.d.ts @@ -0,0 +1,28 @@ +import { Address, Identity } from "."; +import { TableUpdate } from "./table"; +export declare class SubscriptionUpdateMessage { + tableUpdates: TableUpdate[]; + constructor(tableUpdates: TableUpdate[]); +} +export declare class TransactionUpdateEvent { + identity: Identity; + address: Address | null; + originalReducerName: string; + reducerName: string; + args: any[] | Uint8Array; + status: string; + message: string; + constructor(identity: Identity, address: Address | null, originalReducerName: string, reducerName: string, args: any[] | Uint8Array, status: string, message: string); +} +export declare class TransactionUpdateMessage { + tableUpdates: TableUpdate[]; + event: TransactionUpdateEvent; + constructor(tableUpdates: TableUpdate[], event: TransactionUpdateEvent); +} +export declare class IdentityTokenMessage { + identity: Identity; + token: string; + address: Address; + constructor(identity: Identity, token: string, address: Address); +} +export type Message = SubscriptionUpdateMessage | TransactionUpdateMessage | IdentityTokenMessage; diff --git a/dist/message_types.js b/dist/message_types.js new file mode 100644 index 0000000..65ef5c8 --- /dev/null +++ b/dist/message_types.js @@ -0,0 +1,49 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.IdentityTokenMessage = exports.TransactionUpdateMessage = exports.TransactionUpdateEvent = exports.SubscriptionUpdateMessage = void 0; +class SubscriptionUpdateMessage { + tableUpdates; + constructor(tableUpdates) { + this.tableUpdates = tableUpdates; + } +} +exports.SubscriptionUpdateMessage = SubscriptionUpdateMessage; +class TransactionUpdateEvent { + identity; + address; + originalReducerName; + reducerName; + args; + status; + message; + constructor(identity, address, originalReducerName, reducerName, args, status, message) { + this.identity = identity; + this.address = address; + this.originalReducerName = originalReducerName; + this.reducerName = reducerName; + this.args = args; + this.status = status; + this.message = message; + } +} +exports.TransactionUpdateEvent = TransactionUpdateEvent; +class TransactionUpdateMessage { + tableUpdates; + event; + constructor(tableUpdates, event) { + this.tableUpdates = tableUpdates; + this.event = event; + } +} +exports.TransactionUpdateMessage = TransactionUpdateMessage; +class IdentityTokenMessage { + identity; + token; + address; + constructor(identity, token, address) { + this.identity = identity; + this.token = token; + this.address = address; + } +} +exports.IdentityTokenMessage = IdentityTokenMessage; diff --git a/dist/operations_map.d.ts b/dist/operations_map.d.ts new file mode 100644 index 0000000..42f1cca --- /dev/null +++ b/dist/operations_map.d.ts @@ -0,0 +1,9 @@ +export default class OperationsMap { + private items; + private isEqual; + set(key: K, value: V): void; + get(key: K): V | undefined; + delete(key: K): boolean; + has(key: K): boolean; + values(): Array; +} diff --git a/dist/operations_map.js b/dist/operations_map.js new file mode 100644 index 0000000..5d03cb3 --- /dev/null +++ b/dist/operations_map.js @@ -0,0 +1,39 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class OperationsMap { + items = []; + isEqual(a, b) { + if (a && typeof a === "object" && "isEqual" in a) { + return a.isEqual(b); + } + return a === b; + } + set(key, value) { + const existingIndex = this.items.findIndex(({ key: k }) => this.isEqual(k, key)); + if (existingIndex > -1) { + this.items[existingIndex].value = value; + } + else { + this.items.push({ key, value }); + } + } + get(key) { + const item = this.items.find(({ key: k }) => this.isEqual(k, key)); + return item ? item.value : undefined; + } + delete(key) { + const existingIndex = this.items.findIndex(({ key: k }) => this.isEqual(k, key)); + if (existingIndex > -1) { + this.items.splice(existingIndex, 1); + return true; + } + return false; + } + has(key) { + return this.items.some(({ key: k }) => this.isEqual(k, key)); + } + values() { + return this.items.map((i) => i.value); + } +} +exports.default = OperationsMap; diff --git a/dist/reducer.d.ts b/dist/reducer.d.ts new file mode 100644 index 0000000..0c3850d --- /dev/null +++ b/dist/reducer.d.ts @@ -0,0 +1,15 @@ +import { SpacetimeDBClient } from "./spacetimedb"; +export type ReducerClass = { + new (...args: any[]): Reducer; + reducerName: string; +}; +export declare class Reducer { + static reducerName: string; + call(..._args: any[]): void; + on(..._args: any[]): void; + protected client: SpacetimeDBClient; + static with(client: SpacetimeDBClient): InstanceType; + protected static reducer?: any; + protected static getReducer(): InstanceType; + constructor(client: SpacetimeDBClient); +} diff --git a/dist/reducer.js b/dist/reducer.js new file mode 100644 index 0000000..51944f3 --- /dev/null +++ b/dist/reducer.js @@ -0,0 +1,32 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Reducer = void 0; +class Reducer { + static reducerName; + call(..._args) { + throw "not implemented"; + } + on(..._args) { + throw "not implemented"; + } + client; + static with(client) { + return new this(client); + } + static reducer; + static getReducer() { + if (!this.reducer && __SPACETIMEDB__.spacetimeDBClient) { + this.reducer = new this(__SPACETIMEDB__.spacetimeDBClient); + } + if (this.reducer) { + return this.reducer; + } + else { + throw "You need to instantiate a client in order to use reducers."; + } + } + constructor(client) { + this.client = client; + } +} +exports.Reducer = Reducer; diff --git a/dist/reducer_event.d.ts b/dist/reducer_event.d.ts new file mode 100644 index 0000000..cc2afdc --- /dev/null +++ b/dist/reducer_event.d.ts @@ -0,0 +1,11 @@ +import { Identity } from "./identity"; +import { Address } from "./address"; +export declare class ReducerEvent { + callerIdentity: Identity; + callerAddress: Address | null; + reducerName: string; + status: string; + message: string; + args: any; + constructor(callerIdentity: Identity, callerAddress: Address | null, reducerName: string, status: string, message: string, args: any); +} diff --git a/dist/reducer_event.js b/dist/reducer_event.js new file mode 100644 index 0000000..9008ed9 --- /dev/null +++ b/dist/reducer_event.js @@ -0,0 +1,20 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ReducerEvent = void 0; +class ReducerEvent { + callerIdentity; + callerAddress; + reducerName; + status; + message; + args; + constructor(callerIdentity, callerAddress, reducerName, status, message, args) { + this.callerIdentity = callerIdentity; + this.callerAddress = callerAddress; + this.reducerName = reducerName; + this.status = status; + this.message = message; + this.args = args; + } +} +exports.ReducerEvent = ReducerEvent; diff --git a/dist/serializer.d.ts b/dist/serializer.d.ts new file mode 100644 index 0000000..f8a2091 --- /dev/null +++ b/dist/serializer.d.ts @@ -0,0 +1,23 @@ +import { AlgebraicType, BuiltinType } from "./algebraic_type"; +export interface Serializer { + write(type: AlgebraicType, value: any): any; + args(): any; +} +export declare class JSONSerializer { + private content; + private index; + constructor(); + args(): any; + serializeBuiltinType(type: BuiltinType, value: any): any; + serializeType(type: AlgebraicType, value: any): any; + write(type: AlgebraicType, value: any): void; +} +export declare class BinarySerializer { + private writer; + constructor(); + args(): any; + getBuffer(): Uint8Array; + write(type: AlgebraicType, value: any): void; + writeBuiltinType(type: BuiltinType, value: any): void; + writeByte(byte: number): void; +} diff --git a/dist/serializer.js b/dist/serializer.js new file mode 100644 index 0000000..96ccfbb --- /dev/null +++ b/dist/serializer.js @@ -0,0 +1,187 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BinarySerializer = exports.JSONSerializer = void 0; +const algebraic_type_1 = require("./algebraic_type"); +const binary_writer_1 = __importDefault(require("./binary_writer")); +const identity_1 = require("./identity"); +class JSONSerializer { + content; + index = 0; + constructor() { + this.content = []; + } + args() { + return this.content; + } + serializeBuiltinType(type, value) { + switch (type.type) { + case algebraic_type_1.BuiltinType.Type.Array: + const returnArray = []; + for (const element of value) { + returnArray.push(this.serializeType(type.arrayType, element)); + } + return returnArray; + case algebraic_type_1.BuiltinType.Type.Map: + break; + default: + return value; + } + } + serializeType(type, value) { + switch (type.type) { + case algebraic_type_1.AlgebraicType.Type.BuiltinType: + return this.serializeBuiltinType(type.builtin, value); + case algebraic_type_1.AlgebraicType.Type.ProductType: + let serializedArray = []; + for (const element of type.product.elements) { + let serialized; + // If the value is an identity we can't use the `[]` operator, so we're + // special casing the identity type. It might be possible to define the + // `__identity_bytes` property on Identity, but I don't have time to check + // at the moment + if (value.constructor === identity_1.Identity) { + serialized = value.toHexString(); + } + else { + serialized = this.serializeType(element.algebraicType, value[element.name]); + } + serializedArray.push(serialized); + } + return serializedArray; + case algebraic_type_1.AlgebraicType.Type.SumType: + if (type.sum.variants.length == 2 && + type.sum.variants[0].name === "some" && + type.sum.variants[1].name === "none") { + return value; + } + else { + const variant = type.sum.variants.find((v) => v.name === value.tag); + if (!variant) { + throw `Can't serialize a sum type, couldn't find ${value.tag} tag`; + } + return this.serializeType(variant.algebraicType, value.value); + } + default: + break; + } + } + write(type, value) { + this.content[this.index] = this.serializeType(type, value); + this.index += 1; + } +} +exports.JSONSerializer = JSONSerializer; +class BinarySerializer { + writer; + constructor() { + this.writer = new binary_writer_1.default(1024); + } + args() { + return this.getBuffer(); + } + getBuffer() { + return this.writer.getBuffer(); + } + write(type, value) { + switch (type.type) { + case algebraic_type_1.AlgebraicType.Type.BuiltinType: + this.writeBuiltinType(type.builtin, value); + break; + case algebraic_type_1.AlgebraicType.Type.ProductType: + for (const element of type.product.elements) { + this.write(element.algebraicType, + // If the value is an Identity we have to return an Uint8Array instead of trying + // to use the `[]` operator. + value.constructor === identity_1.Identity + ? value.toUint8Array() + : value[element.name]); + } + break; + case algebraic_type_1.AlgebraicType.Type.SumType: + if (type.sum.variants.length == 2 && + type.sum.variants[0].name === "some" && + type.sum.variants[1].name === "none") { + if (value) { + this.writeByte(0); + this.write(type.sum.variants[0].algebraicType, value); + } + else { + this.writeByte(1); + } + } + else { + const index = type.sum.variants.findIndex((v) => v.name === value.tag); + if (index < 0) { + throw `Can't serialize a sum type, couldn't find ${value.tag} tag`; + } + this.writeByte(index); + this.write(type.sum.variants[index].algebraicType, value.value); + } + break; + default: + break; + } + } + writeBuiltinType(type, value) { + switch (type.type) { + case algebraic_type_1.BuiltinType.Type.Array: + const array = value; + this.writer.writeU32(array.length); + for (const element of array) { + this.write(type.arrayType, element); + } + break; + case algebraic_type_1.BuiltinType.Type.Map: + break; + case algebraic_type_1.BuiltinType.Type.String: + this.writer.writeString(value); + break; + case algebraic_type_1.BuiltinType.Type.Bool: + this.writer.writeBool(value); + break; + case algebraic_type_1.BuiltinType.Type.I8: + this.writer.writeI8(value); + break; + case algebraic_type_1.BuiltinType.Type.U8: + this.writer.writeU8(value); + break; + case algebraic_type_1.BuiltinType.Type.I16: + this.writer.writeI16(value); + break; + case algebraic_type_1.BuiltinType.Type.U16: + this.writer.writeU16(value); + break; + case algebraic_type_1.BuiltinType.Type.I32: + this.writer.writeI32(value); + break; + case algebraic_type_1.BuiltinType.Type.U32: + this.writer.writeU32(value); + break; + case algebraic_type_1.BuiltinType.Type.I64: + this.writer.writeI64(value); + break; + case algebraic_type_1.BuiltinType.Type.U64: + this.writer.writeU64(value); + break; + case algebraic_type_1.BuiltinType.Type.I128: + this.writer.writeI128(value); + break; + case algebraic_type_1.BuiltinType.Type.U128: + this.writer.writeU128(value); + break; + case algebraic_type_1.BuiltinType.Type.F32: + this.writer.writeF32(value); + break; + case algebraic_type_1.BuiltinType.Type.F64: + this.writer.writeF64(value); + break; + } + } + writeByte(byte) { + this.writer.writeU8(byte); + } +} +exports.BinarySerializer = BinarySerializer; diff --git a/dist/spacetimedb.d.ts b/dist/spacetimedb.d.ts new file mode 100644 index 0000000..2a175a8 --- /dev/null +++ b/dist/spacetimedb.d.ts @@ -0,0 +1,235 @@ +/// +import { EventEmitter } from "events"; +import WebSocket from "isomorphic-ws"; +import type { WebsocketTestAdapter } from "./websocket_test_adapter"; +import { ProductValue, AlgebraicValue, ValueAdapter, ReducerArgsAdapter } from "./algebraic_value"; +import { Serializer, BinarySerializer } from "./serializer"; +import { AlgebraicType, ProductType, ProductTypeElement, SumType, SumTypeVariant, BuiltinType } from "./algebraic_type"; +import { EventType } from "./types"; +import { Identity } from "./identity"; +import { Address } from "./address"; +import { ReducerEvent } from "./reducer_event"; +import { DatabaseTable, DatabaseTableClass } from "./database_table"; +import { Reducer, ReducerClass } from "./reducer"; +import { ClientDB } from "./client_db"; +import { SpacetimeDBGlobals } from "./global"; +export { ProductValue, AlgebraicValue, AlgebraicType, ProductType, ProductTypeElement, SumType, SumTypeVariant, BuiltinType, BinarySerializer, ReducerEvent, Reducer, ReducerClass, DatabaseTable, DatabaseTableClass, }; +export type { ValueAdapter, ReducerArgsAdapter, Serializer }; +type CreateWSFnType = (url: string, protocol: string) => WebSocket | WebsocketTestAdapter; +/** + * The database client connection to a SpacetimeDB server. + */ +export declare class SpacetimeDBClient { + /** + * The user's public identity. + */ + identity?: Identity; + /** + * The user's private authentication token. + */ + token?: string; + /** + * Reference to the database of the client. + */ + db: ClientDB; + emitter: EventEmitter; + /** + * Whether the client is connected. + */ + live: boolean; + private ws; + private manualTableSubscriptions; + private queriesQueue; + private runtime; + private createWSFn; + private protocol; + private ssl; + private clientAddress; + private static tableClasses; + private static reducerClasses; + private static getTableClass; + private static getReducerClass; + /** + * Creates a new `SpacetimeDBClient` database client and set the initial parameters. + * + * @param host The host of the SpacetimeDB server. + * @param name_or_address The name or address of the SpacetimeDB module. + * @param auth_token The credentials to use to connect to authenticate with SpacetimeDB. + * @param protocol Define how encode the messages: `"binary" | "json"`. Binary is more efficient and compact, but JSON provides human-readable debug information. + * + * @example + * + * ```ts + * const host = "ws://localhost:3000"; + * const name_or_address = "database_name" + * const auth_token = undefined; + * const protocol = "binary" + * + * var spacetimeDBClient = new SpacetimeDBClient(host, name_or_address, auth_token, protocol); + * ``` + */ + constructor(host: string, name_or_address: string, auth_token?: string, protocol?: "binary" | "json"); + private defaultCreateWebSocketFn; + /** + * Handles WebSocket onClose event. + * @param event CloseEvent object. + */ + private handleOnClose; + /** + * Handles WebSocket onError event. + * @param event ErrorEvent object. + */ + private handleOnError; + /** + * Handles WebSocket onOpen event. + */ + private handleOnOpen; + /** + * Handles WebSocket onMessage event. + * @param wsMessage MessageEvent object. + */ + private handleOnMessage; + /** + * Subscribes to a table without registering it as a component. + * + * @param table The table to subscribe to + * @param query The query to subscribe to. If not provided, the default is `SELECT * FROM {table}` + */ + registerManualTable(table: string, query?: string): void; + /** + * Unsubscribes from a table without unregistering it as a component. + * + * @param table The table to unsubscribe from + */ + removeManualTable(table: string): void; + /** + * Close the current connection. + * + * @example + * + * ```ts + * var spacetimeDBClient = new SpacetimeDBClient("ws://localhost:3000", "database_name"); + * + * spacetimeDBClient.disconnect() + * ``` + */ + disconnect(): void; + /** + * Connect to The SpacetimeDB Websocket For Your Module. By default, this will use a secure websocket connection. The parameters are optional, and if not provided, will use the values provided on construction of the client. + * + * @param host The hostname of the SpacetimeDB server. Defaults to the value passed to the `constructor`. + * @param name_or_address The name or address of the SpacetimeDB module. Defaults to the value passed to the `constructor`. + * @param auth_token The credentials to use to authenticate with SpacetimeDB. Defaults to the value passed to the `constructor`. + * + * @example + * + * ```ts + * const host = "ws://localhost:3000"; + * const name_or_address = "database_name" + * const auth_token = undefined; + * + * var spacetimeDBClient = new SpacetimeDBClient(host, name_or_address, auth_token); + * // Connect with the initial parameters + * spacetimeDBClient.connect(); + * //Set the `auth_token` + * spacetimeDBClient.connect(undefined, undefined, NEW_TOKEN); + * ``` + */ + connect(host?: string, name_or_address?: string, auth_token?: string): Promise; + private processMessage; + /** + * Register a component to be used with your SpacetimeDB module. If the websocket is already connected it will add it to the list of subscribed components + * + * @param name The name of the component to register + * @param component The component to register + */ + private registerTable; + /** + * Register a component to be used with any SpacetimeDB client. The component will be automatically registered to any + * new clients + * @param table Component to be registered + */ + static registerTable(table: DatabaseTableClass): void; + /** + * Register a list of components to be used with any SpacetimeDB client. The components will be automatically registered to any new clients + * @param tables A list of tables to register globally with SpacetimeDBClient + */ + static registerTables(...tables: DatabaseTableClass[]): void; + /** + * Register a reducer to be used with any SpacetimeDB client. The reducer will be automatically registered to any + * new clients + * @param reducer Reducer to be registered + */ + static registerReducer(reducer: ReducerClass): void; + /** + * Register a list of reducers to be used with any SpacetimeDB client. The reducers will be automatically registered to any new clients + * @param reducers A list of reducers to register globally with SpacetimeDBClient + */ + static registerReducers(...reducers: ReducerClass[]): void; + /** + * Subscribe to a set of queries, to be notified when rows which match those queries are altered. + * + * NOTE: A new call to `subscribe` will remove all previous subscriptions and replace them with the new `queries`. + * + * If any rows matched the previous subscribed queries but do not match the new queries, + * those rows will be removed from the client cache, and `{Table}.on_delete` callbacks will be invoked for them. + * + * @param queries A `SQL` query or list of queries. + * + * @example + * + * ```ts + * spacetimeDBClient.subscribe(["SELECT * FROM User","SELECT * FROM Message"]); + * ``` + */ + subscribe(queryOrQueries: string | string[]): void; + /** + * Call a reducer on your SpacetimeDB module. + * + * @param reducerName The name of the reducer to call + * @param args The arguments to pass to the reducer + */ + call(reducerName: string, serializer: Serializer): void; + on(eventName: EventType | string, callback: (...args: any[]) => void): void; + off(eventName: EventType | string, callback: (...args: any[]) => void): void; + /** + * Register a callback to be invoked upon authentication with the database. + * + * @param token The credentials to use to authenticate with SpacetimeDB. + * @param identity A unique public identifier for a client connected to a database. + * + * The callback will be invoked with the public `Identity` and private authentication `token` provided by the database to identify this connection. + * + * If credentials were supplied to connect, those passed to the callback will be equivalent to the ones used to connect. + * + * If the initial connection was anonymous, a new set of credentials will be generated by the database to identify this user. + * + * The credentials passed to the callback can be saved and used to authenticate the same user in future connections. + * + * @example + * + * ```ts + * spacetimeDBClient.onConnect((token, identity) => { + * console.log("Connected to SpacetimeDB"); + * console.log("Token", token); + * console.log("Identity", identity); + * }); + * ``` + */ + onConnect(callback: (token: string, identity: Identity, address: Address) => void): void; + /** + * Register a callback to be invoked upon an error. + * + * @example + * + * ```ts + * spacetimeDBClient.onError((...args: any[]) => { + * stdbLogger("warn","ERROR", args); + * }); + * ``` + */ + onError(callback: (...args: any[]) => void): void; + _setCreateWSFn(fn: CreateWSFnType): void; + getSerializer(): Serializer; +} +export declare const __SPACETIMEDB__: SpacetimeDBGlobals; diff --git a/dist/spacetimedb.js b/dist/spacetimedb.js new file mode 100644 index 0000000..b53b0e3 --- /dev/null +++ b/dist/spacetimedb.js @@ -0,0 +1,683 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.__SPACETIMEDB__ = exports.SpacetimeDBClient = exports.DatabaseTable = exports.Reducer = exports.ReducerEvent = exports.BinarySerializer = exports.BuiltinType = exports.SumTypeVariant = exports.SumType = exports.ProductTypeElement = exports.ProductType = exports.AlgebraicType = exports.AlgebraicValue = exports.ProductValue = void 0; +const events_1 = require("events"); +const isomorphic_ws_1 = __importDefault(require("isomorphic-ws")); +const algebraic_value_1 = require("./algebraic_value"); +Object.defineProperty(exports, "ProductValue", { enumerable: true, get: function () { return algebraic_value_1.ProductValue; } }); +Object.defineProperty(exports, "AlgebraicValue", { enumerable: true, get: function () { return algebraic_value_1.AlgebraicValue; } }); +const serializer_1 = require("./serializer"); +Object.defineProperty(exports, "BinarySerializer", { enumerable: true, get: function () { return serializer_1.BinarySerializer; } }); +const algebraic_type_1 = require("./algebraic_type"); +Object.defineProperty(exports, "AlgebraicType", { enumerable: true, get: function () { return algebraic_type_1.AlgebraicType; } }); +Object.defineProperty(exports, "ProductType", { enumerable: true, get: function () { return algebraic_type_1.ProductType; } }); +Object.defineProperty(exports, "ProductTypeElement", { enumerable: true, get: function () { return algebraic_type_1.ProductTypeElement; } }); +Object.defineProperty(exports, "SumType", { enumerable: true, get: function () { return algebraic_type_1.SumType; } }); +Object.defineProperty(exports, "SumTypeVariant", { enumerable: true, get: function () { return algebraic_type_1.SumTypeVariant; } }); +Object.defineProperty(exports, "BuiltinType", { enumerable: true, get: function () { return algebraic_type_1.BuiltinType; } }); +const identity_1 = require("./identity"); +const address_1 = require("./address"); +const reducer_event_1 = require("./reducer_event"); +Object.defineProperty(exports, "ReducerEvent", { enumerable: true, get: function () { return reducer_event_1.ReducerEvent; } }); +const Proto = __importStar(require("./client_api")); +const binary_reader_1 = __importDefault(require("./binary_reader")); +const table_1 = require("./table"); +const utils_1 = require("./utils"); +const database_table_1 = require("./database_table"); +Object.defineProperty(exports, "DatabaseTable", { enumerable: true, get: function () { return database_table_1.DatabaseTable; } }); +const reducer_1 = require("./reducer"); +Object.defineProperty(exports, "Reducer", { enumerable: true, get: function () { return reducer_1.Reducer; } }); +const client_db_1 = require("./client_db"); +const message_types_1 = require("./message_types"); +const logger_1 = require("./logger"); +const decompress_1 = __importDefault(require("brotli/decompress")); +const buffer_1 = require("buffer"); +const g = (typeof window === "undefined" ? global : window); +/** + * The database client connection to a SpacetimeDB server. + */ +class SpacetimeDBClient { + /** + * The user's public identity. + */ + identity = undefined; + /** + * The user's private authentication token. + */ + token = undefined; + /** + * Reference to the database of the client. + */ + db; + emitter; + /** + * Whether the client is connected. + */ + live; + ws; + manualTableSubscriptions = []; + queriesQueue; + runtime; + createWSFn; + protocol; + ssl = false; + clientAddress = address_1.Address.random(); + static tableClasses = new Map(); + static reducerClasses = new Map(); + static getTableClass(name) { + const tableClass = this.tableClasses.get(name); + if (!tableClass) { + throw `Could not find class \"${name}\", you need to register it with SpacetimeDBClient.registerTable() first`; + } + return tableClass; + } + static getReducerClass(name) { + const reducerName = `${name}Reducer`; + const reducerClass = this.reducerClasses.get(reducerName); + if (!reducerClass) { + (0, logger_1.stdbLogger)("warn", `Could not find class \"${name}\", you need to register it with SpacetimeDBClient.registerReducer() first`); + return; + } + return reducerClass; + } + /** + * Creates a new `SpacetimeDBClient` database client and set the initial parameters. + * + * @param host The host of the SpacetimeDB server. + * @param name_or_address The name or address of the SpacetimeDB module. + * @param auth_token The credentials to use to connect to authenticate with SpacetimeDB. + * @param protocol Define how encode the messages: `"binary" | "json"`. Binary is more efficient and compact, but JSON provides human-readable debug information. + * + * @example + * + * ```ts + * const host = "ws://localhost:3000"; + * const name_or_address = "database_name" + * const auth_token = undefined; + * const protocol = "binary" + * + * var spacetimeDBClient = new SpacetimeDBClient(host, name_or_address, auth_token, protocol); + * ``` + */ + constructor(host, name_or_address, auth_token, protocol) { + this.protocol = protocol || "binary"; + const global = g.__SPACETIMEDB__; + if (global.spacetimeDBClient) { + // If a client has been already created earlier it means the developer + // wants to create multiple clients and thus let's create a new ClientDB. + // The global ClientDB will be onl shared with the first created client + this.db = new client_db_1.ClientDB(); + } + else { + // if this is the first client let's use the global ClientDB and set this instance + // as the global instance + this.db = global.clientDB; + global.spacetimeDBClient = this; + } + // for (const [_name, reducer] of SpacetimeDBClient.reducerClasses) { + // this.registerReducer(reducer); + // } + if (SpacetimeDBClient.tableClasses.size === 0) { + (0, logger_1.stdbLogger)("warn", "No tables were automatically registered globally, if you want to automatically register tables, you need to register them with SpacetimeDBClient.registerTable() first"); + } + for (const [_name, table] of SpacetimeDBClient.tableClasses) { + this.registerTable(table); + } + this.live = false; + this.emitter = new events_1.EventEmitter(); + this.queriesQueue = []; + this.runtime = { + host, + name_or_address, + auth_token, + global, + }; + this.createWSFn = this.defaultCreateWebSocketFn; + } + async defaultCreateWebSocketFn(url, protocol) { + const headers = {}; + if (this.runtime.auth_token) { + headers["Authorization"] = `Basic ${btoa("token:" + this.runtime.auth_token)}`; + } + if (typeof window === "undefined" || !this.runtime.auth_token) { + // NodeJS environment + const ws = new isomorphic_ws_1.default(url, protocol, { + maxReceivedFrameSize: 100000000, + maxReceivedMessageSize: 100000000, + headers, + }); + return ws; + } + else { + // In the browser we first have to get a short lived token and only then connect to the websocket + let httpProtocol = this.ssl ? "https://" : "http://"; + let tokenUrl = `${httpProtocol}${this.runtime.host}/identity/websocket_token`; + const response = await fetch(tokenUrl, { method: "POST", headers }); + if (response.ok) { + const { token } = await response.json(); + url += "&token=" + btoa("token:" + token); + } + return new isomorphic_ws_1.default(url, protocol); + } + } + /** + * Handles WebSocket onClose event. + * @param event CloseEvent object. + */ + handleOnClose(event) { + (0, logger_1.stdbLogger)("warn", "Closed: " + event); + this.emitter.emit("disconnected"); + this.emitter.emit("client_error", event); + } + /** + * Handles WebSocket onError event. + * @param event ErrorEvent object. + */ + handleOnError(event) { + (0, logger_1.stdbLogger)("warn", "WS Error: " + event); + this.emitter.emit("disconnected"); + this.emitter.emit("client_error", event); + } + /** + * Handles WebSocket onOpen event. + */ + handleOnOpen() { + this.live = true; + if (this.queriesQueue.length > 0) { + this.subscribe(this.queriesQueue); + this.queriesQueue = []; + } + } + /** + * Handles WebSocket onMessage event. + * @param wsMessage MessageEvent object. + */ + handleOnMessage(wsMessage) { + this.emitter.emit("receiveWSMessage", wsMessage); + this.processMessage(wsMessage, (message) => { + if (message instanceof message_types_1.SubscriptionUpdateMessage) { + for (let tableUpdate of message.tableUpdates) { + const tableName = tableUpdate.tableName; + const entityClass = SpacetimeDBClient.getTableClass(tableName); + const table = this.db.getOrCreateTable(tableUpdate.tableName, undefined, entityClass); + table.applyOperations(this.protocol, tableUpdate.operations, undefined); + } + if (this.emitter) { + this.emitter.emit("initialStateSync"); + } + } + else if (message instanceof message_types_1.TransactionUpdateMessage) { + const reducerName = message.event.reducerName; + const reducer = reducerName + ? SpacetimeDBClient.getReducerClass(reducerName) + : undefined; + let reducerEvent; + let reducerArgs; + if (reducer && message.event.status === "committed") { + let adapter; + if (this.protocol === "binary") { + adapter = new algebraic_value_1.BinaryReducerArgsAdapter(new algebraic_value_1.BinaryAdapter(new binary_reader_1.default(message.event.args))); + } + else { + adapter = new algebraic_value_1.JSONReducerArgsAdapter(message.event.args); + } + reducerArgs = reducer.deserializeArgs(adapter); + } + reducerEvent = new reducer_event_1.ReducerEvent(message.event.identity, message.event.address, message.event.originalReducerName, message.event.status, message.event.message, reducerArgs); + for (let tableUpdate of message.tableUpdates) { + const tableName = tableUpdate.tableName; + const entityClass = SpacetimeDBClient.getTableClass(tableName); + const table = this.db.getOrCreateTable(tableUpdate.tableName, undefined, entityClass); + table.applyOperations(this.protocol, tableUpdate.operations, reducerEvent); + } + if (reducer) { + this.emitter.emit("reducer:" + reducerName, reducerEvent, ...(reducerArgs || [])); + } + } + else if (message instanceof message_types_1.IdentityTokenMessage) { + this.identity = message.identity; + if (this.runtime.auth_token) { + this.token = this.runtime.auth_token; + } + else { + this.token = message.token; + } + this.clientAddress = message.address; + this.emitter.emit("connected", this.token, this.identity, this.clientAddress); + } + }); + } + /** + * Subscribes to a table without registering it as a component. + * + * @param table The table to subscribe to + * @param query The query to subscribe to. If not provided, the default is `SELECT * FROM {table}` + */ + registerManualTable(table, query) { + this.manualTableSubscriptions.push(query ? query : `SELECT * FROM ${table}`); + this.ws.send(JSON.stringify({ + subscribe: { + query_strings: [...this.manualTableSubscriptions], + }, + })); + } + /** + * Unsubscribes from a table without unregistering it as a component. + * + * @param table The table to unsubscribe from + */ + removeManualTable(table) { + this.manualTableSubscriptions = this.manualTableSubscriptions.filter((val) => val !== table); + this.ws.send(JSON.stringify({ + subscribe: { + query_strings: this.manualTableSubscriptions.map((val) => `SELECT * FROM ${val}`), + }, + })); + } + /** + * Close the current connection. + * + * @example + * + * ```ts + * var spacetimeDBClient = new SpacetimeDBClient("ws://localhost:3000", "database_name"); + * + * spacetimeDBClient.disconnect() + * ``` + */ + disconnect() { + this.ws.close(); + } + /** + * Connect to The SpacetimeDB Websocket For Your Module. By default, this will use a secure websocket connection. The parameters are optional, and if not provided, will use the values provided on construction of the client. + * + * @param host The hostname of the SpacetimeDB server. Defaults to the value passed to the `constructor`. + * @param name_or_address The name or address of the SpacetimeDB module. Defaults to the value passed to the `constructor`. + * @param auth_token The credentials to use to authenticate with SpacetimeDB. Defaults to the value passed to the `constructor`. + * + * @example + * + * ```ts + * const host = "ws://localhost:3000"; + * const name_or_address = "database_name" + * const auth_token = undefined; + * + * var spacetimeDBClient = new SpacetimeDBClient(host, name_or_address, auth_token); + * // Connect with the initial parameters + * spacetimeDBClient.connect(); + * //Set the `auth_token` + * spacetimeDBClient.connect(undefined, undefined, NEW_TOKEN); + * ``` + */ + async connect(host, name_or_address, auth_token) { + if (this.live) { + return; + } + (0, logger_1.stdbLogger)("info", "Connecting to SpacetimeDB WS..."); + if (host) { + this.runtime.host = host; + } + if (name_or_address) { + this.runtime.name_or_address = name_or_address; + } + if (auth_token) { + // TODO: do we need both of these + this.runtime.auth_token = auth_token; + this.token = auth_token; + } + // TODO: we should probably just accept a host and an ssl boolean flag in stead of this + // whole dance + let url = `${this.runtime.host}/database/subscribe/${this.runtime.name_or_address}`; + if (!this.runtime.host.startsWith("ws://") && + !this.runtime.host.startsWith("wss://")) { + url = "ws://" + url; + } + let clientAddress = this.clientAddress.toHexString(); + url += `?client_address=${clientAddress}`; + this.ssl = url.startsWith("wss"); + this.runtime.host = this.runtime.host + .replace("ws://", "") + .replace("wss://", ""); + const stdbProtocol = this.protocol === "binary" ? "bin" : "text"; + this.ws = await this.createWSFn(url, `v1.${stdbProtocol}.spacetimedb`); + this.ws.onclose = this.handleOnClose.bind(this); + this.ws.onerror = this.handleOnError.bind(this); + this.ws.onopen = this.handleOnOpen.bind(this); + this.ws.onmessage = this.handleOnMessage.bind(this); + } + processMessage(wsMessage, callback) { + if (this.protocol === "binary") { + // Helpers for parsing message components which appear in multiple messages. + const parseTableRowOperation = (rawTableOperation) => { + const type = rawTableOperation.op === Proto.TableRowOperation_OperationType.INSERT + ? "insert" + : "delete"; + // Our SDKs are architected around having a hashable, equality-comparable key + // which uniquely identifies every row. + // This used to be a strong content-addressed hash computed by the DB, + // but the DB no longer computes those hashes, + // so now we just use the serialized row as the identifier. + const rowPk = new TextDecoder().decode(rawTableOperation.row); + return new table_1.TableOperation(type, rowPk, rawTableOperation.row); + }; + const parseTableUpdate = (rawTableUpdate) => { + const tableName = rawTableUpdate.tableName; + const operations = []; + for (const rawTableOperation of rawTableUpdate.tableRowOperations) { + operations.push(parseTableRowOperation(rawTableOperation)); + } + return new table_1.TableUpdate(tableName, operations); + }; + const parseSubscriptionUpdate = (subUpdate) => { + const tableUpdates = []; + for (const rawTableUpdate of subUpdate.tableUpdates) { + tableUpdates.push(parseTableUpdate(rawTableUpdate)); + } + return new message_types_1.SubscriptionUpdateMessage(tableUpdates); + }; + let data = wsMessage.data; + if (typeof data.arrayBuffer === "undefined") { + data = new Blob([data]); + } + data.arrayBuffer().then((data) => { + // From https://github.com/foliojs/brotli.js/issues/31 : + // use a `Buffer` rather than a `Uint8Array` because for some reason brotli requires that. + let decompressed = (0, decompress_1.default)(new buffer_1.Buffer(data)); + const message = Proto.Message.decode(new Uint8Array(decompressed)); + if (message["subscriptionUpdate"]) { + const rawSubscriptionUpdate = message.subscriptionUpdate; + const subscriptionUpdate = parseSubscriptionUpdate(rawSubscriptionUpdate); + callback(subscriptionUpdate); + } + else if (message["transactionUpdate"]) { + const txUpdate = message.transactionUpdate; + const rawSubscriptionUpdate = txUpdate.subscriptionUpdate; + if (!rawSubscriptionUpdate) { + throw new Error("Received TransactionUpdate without SubscriptionUpdate"); + } + const subscriptionUpdate = parseSubscriptionUpdate(rawSubscriptionUpdate); + const event = txUpdate.event; + if (!event) { + throw new Error("Received TransactionUpdate without Event"); + } + const functionCall = event.functionCall; + if (!functionCall) { + throw new Error("Received TransactionUpdate with Event but no FunctionCall"); + } + const identity = new identity_1.Identity(event.callerIdentity); + const address = address_1.Address.nullIfZero(event.callerAddress); + const originalReducerName = functionCall.reducer; + const reducerName = (0, utils_1.toPascalCase)(originalReducerName); + const args = functionCall.argBytes; + const status = Proto.event_StatusToJSON(event.status); + const messageStr = event.message; + const transactionUpdateEvent = new message_types_1.TransactionUpdateEvent(identity, address, originalReducerName, reducerName, args, status, messageStr); + const transactionUpdate = new message_types_1.TransactionUpdateMessage(subscriptionUpdate.tableUpdates, transactionUpdateEvent); + callback(transactionUpdate); + } + else if (message["identityToken"]) { + const identityToken = message.identityToken; + const identity = new identity_1.Identity(identityToken.identity); + const token = identityToken.token; + const address = new address_1.Address(identityToken.address); + const identityTokenMessage = new message_types_1.IdentityTokenMessage(identity, token, address); + callback(identityTokenMessage); + } + }); + } + else { + const parseTableRowOperation = (rawTableOperation) => { + const type = rawTableOperation["op"]; + // Our SDKs are architected around having a hashable, equality-comparable key + // which uniquely identifies every row. + // This used to be a strong content-addressed hash computed by the DB, + // but the DB no longer computes those hashes, + // so now we just use the serialized row as the identifier. + // + // JSON.stringify may be expensive here, but if the client cared about performance + // they'd be using the binary format anyway, so we don't care. + const rowPk = JSON.stringify(rawTableOperation.row); + return new table_1.TableOperation(type, rowPk, rawTableOperation.row); + }; + const parseTableUpdate = (rawTableUpdate) => { + const tableName = rawTableUpdate.table_name; + const operations = []; + for (const rawTableOperation of rawTableUpdate.table_row_operations) { + operations.push(parseTableRowOperation(rawTableOperation)); + } + return new table_1.TableUpdate(tableName, operations); + }; + const parseSubscriptionUpdate = (rawSubscriptionUpdate) => { + const tableUpdates = []; + for (const rawTableUpdate of rawSubscriptionUpdate.table_updates) { + tableUpdates.push(parseTableUpdate(rawTableUpdate)); + } + return new message_types_1.SubscriptionUpdateMessage(tableUpdates); + }; + const data = JSON.parse(wsMessage.data); + if (data["SubscriptionUpdate"]) { + const subscriptionUpdate = parseSubscriptionUpdate(data.SubscriptionUpdate); + callback(subscriptionUpdate); + } + else if (data["TransactionUpdate"]) { + const txUpdate = data.TransactionUpdate; + const subscriptionUpdate = parseSubscriptionUpdate(txUpdate.subscription_update); + const event = txUpdate.event; + const functionCall = event.function_call; + const identity = new identity_1.Identity(event.caller_identity); + const address = address_1.Address.fromStringOrNull(event.caller_address); + const originalReducerName = functionCall.reducer; + const reducerName = (0, utils_1.toPascalCase)(originalReducerName); + const args = JSON.parse(functionCall.args); + const status = event.status; + const message = event.message; + const transactionUpdateEvent = new message_types_1.TransactionUpdateEvent(identity, address, originalReducerName, reducerName, args, status, message); + const transactionUpdate = new message_types_1.TransactionUpdateMessage(subscriptionUpdate.tableUpdates, transactionUpdateEvent); + callback(transactionUpdate); + } + else if (data["IdentityToken"]) { + const identityToken = data.IdentityToken; + const identity = new identity_1.Identity(identityToken.identity); + const token = identityToken.token; + const address = address_1.Address.fromString(identityToken.address); + const identityTokenMessage = new message_types_1.IdentityTokenMessage(identity, token, address); + callback(identityTokenMessage); + } + } + } + /** + * Register a component to be used with your SpacetimeDB module. If the websocket is already connected it will add it to the list of subscribed components + * + * @param name The name of the component to register + * @param component The component to register + */ + registerTable(tableClass) { + this.db.getOrCreateTable(tableClass.tableName, undefined, tableClass); + // only set a default ClientDB on a table class if it's not set yet. This means + // that only the first created client will be usable without the `with` method + if (!tableClass.db) { + tableClass.db = this.db; + } + } + /** + * Register a component to be used with any SpacetimeDB client. The component will be automatically registered to any + * new clients + * @param table Component to be registered + */ + static registerTable(table) { + this.tableClasses.set(table.tableName, table); + } + /** + * Register a list of components to be used with any SpacetimeDB client. The components will be automatically registered to any new clients + * @param tables A list of tables to register globally with SpacetimeDBClient + */ + static registerTables(...tables) { + for (const table of tables) { + this.registerTable(table); + } + } + /** + * Register a reducer to be used with any SpacetimeDB client. The reducer will be automatically registered to any + * new clients + * @param reducer Reducer to be registered + */ + static registerReducer(reducer) { + this.reducerClasses.set(reducer.reducerName + "Reducer", reducer); + } + /** + * Register a list of reducers to be used with any SpacetimeDB client. The reducers will be automatically registered to any new clients + * @param reducers A list of reducers to register globally with SpacetimeDBClient + */ + static registerReducers(...reducers) { + for (const reducer of reducers) { + this.registerReducer(reducer); + } + } + /** + * Subscribe to a set of queries, to be notified when rows which match those queries are altered. + * + * NOTE: A new call to `subscribe` will remove all previous subscriptions and replace them with the new `queries`. + * + * If any rows matched the previous subscribed queries but do not match the new queries, + * those rows will be removed from the client cache, and `{Table}.on_delete` callbacks will be invoked for them. + * + * @param queries A `SQL` query or list of queries. + * + * @example + * + * ```ts + * spacetimeDBClient.subscribe(["SELECT * FROM User","SELECT * FROM Message"]); + * ``` + */ + subscribe(queryOrQueries) { + const queries = typeof queryOrQueries === "string" ? [queryOrQueries] : queryOrQueries; + if (this.live) { + const message = { subscribe: { query_strings: queries } }; + this.emitter.emit("sendWSMessage", message); + this.ws.send(JSON.stringify(message)); + } + else { + this.queriesQueue = this.queriesQueue.concat(queries); + } + } + /** + * Call a reducer on your SpacetimeDB module. + * + * @param reducerName The name of the reducer to call + * @param args The arguments to pass to the reducer + */ + call(reducerName, serializer) { + let message; + if (this.protocol === "binary") { + const pmessage = { + functionCall: { + reducer: reducerName, + argBytes: serializer.args(), + }, + }; + message = Proto.Message.encode(pmessage).finish(); + } + else { + message = JSON.stringify({ + call: { + fn: reducerName, + args: serializer.args(), + }, + }); + } + this.emitter.emit("sendWSMessage", message); + this.ws.send(message); + } + on(eventName, callback) { + this.emitter.on(eventName, callback); + } + off(eventName, callback) { + this.emitter.off(eventName, callback); + } + /** + * Register a callback to be invoked upon authentication with the database. + * + * @param token The credentials to use to authenticate with SpacetimeDB. + * @param identity A unique public identifier for a client connected to a database. + * + * The callback will be invoked with the public `Identity` and private authentication `token` provided by the database to identify this connection. + * + * If credentials were supplied to connect, those passed to the callback will be equivalent to the ones used to connect. + * + * If the initial connection was anonymous, a new set of credentials will be generated by the database to identify this user. + * + * The credentials passed to the callback can be saved and used to authenticate the same user in future connections. + * + * @example + * + * ```ts + * spacetimeDBClient.onConnect((token, identity) => { + * console.log("Connected to SpacetimeDB"); + * console.log("Token", token); + * console.log("Identity", identity); + * }); + * ``` + */ + onConnect(callback) { + this.on("connected", callback); + } + /** + * Register a callback to be invoked upon an error. + * + * @example + * + * ```ts + * spacetimeDBClient.onError((...args: any[]) => { + * stdbLogger("warn","ERROR", args); + * }); + * ``` + */ + onError(callback) { + this.on("client_error", callback); + } + _setCreateWSFn(fn) { + this.createWSFn = fn; + } + getSerializer() { + if (this.protocol === "binary") { + return new serializer_1.BinarySerializer(); + } + else { + return new serializer_1.JSONSerializer(); + } + } +} +exports.SpacetimeDBClient = SpacetimeDBClient; +g.__SPACETIMEDB__ = { + clientDB: new client_db_1.ClientDB(), + spacetimeDBClient: undefined, +}; +exports.__SPACETIMEDB__ = (typeof window === "undefined" + ? global.__SPACETIMEDB__ + : window.__SPACETIMEDB__); diff --git a/dist/table.d.ts b/dist/table.d.ts new file mode 100644 index 0000000..6c7833b --- /dev/null +++ b/dist/table.d.ts @@ -0,0 +1,118 @@ +/// +import { EventEmitter } from "events"; +import { DatabaseTable } from "./spacetimedb"; +import { ReducerEvent } from "./reducer_event"; +declare class DBOp { + type: "insert" | "delete"; + instance: any; + rowPk: string; + constructor(type: "insert" | "delete", rowPk: string, instance: any); +} +export declare class TableOperation { + /** + * The type of CRUD operation. + * + * NOTE: An update is a `delete` followed by a 'insert' internally. + */ + type: "insert" | "delete"; + rowPk: string; + row: Uint8Array | any; + constructor(type: "insert" | "delete", rowPk: string, row: Uint8Array | any); +} +export declare class TableUpdate { + tableName: string; + operations: TableOperation[]; + constructor(tableName: string, operations: TableOperation[]); +} +/** + * Builder to generate calls to query a `table` in the database + */ +export declare class Table { + name: string; + instances: Map; + emitter: EventEmitter; + private entityClass; + pkCol?: number; + /** + * @param name the table name + * @param pkCol column designated as `#[primarykey]` + * @param entityClass the entityClass + */ + constructor(name: string, pkCol: number | undefined, entityClass: any); + /** + * @returns number of entries in the table + */ + count(): number; + /** + * @returns The values of the entries in the table + */ + getInstances(): any[]; + applyOperations: (protocol: "binary" | "json", operations: TableOperation[], reducerEvent: ReducerEvent | undefined) => void; + update: (newDbOp: DBOp, oldDbOp: DBOp, reducerEvent: ReducerEvent | undefined) => void; + insert: (dbOp: DBOp, reducerEvent: ReducerEvent | undefined) => void; + delete: (dbOp: DBOp, reducerEvent: ReducerEvent | undefined) => void; + /** + * Register a callback for when a row is newly inserted into the database. + * + * ```ts + * User.onInsert((user, reducerEvent) => { + * if (reducerEvent) { + * console.log("New user on reducer", reducerEvent, user); + * } else { + * console.log("New user received during subscription update on insert", user); + * } + * }); + * ``` + * + * @param cb Callback to be called when a new row is inserted + */ + onInsert: (cb: (value: any, reducerEvent: ReducerEvent | undefined) => void) => void; + /** + * Register a callback for when a row is deleted from the database. + * + * ```ts + * User.onDelete((user, reducerEvent) => { + * if (reducerEvent) { + * console.log("Deleted user on reducer", reducerEvent, user); + * } else { + * console.log("Deleted user received during subscription update on update", user); + * } + * }); + * ``` + * + * @param cb Callback to be called when a new row is inserted + */ + onDelete: (cb: (value: any, reducerEvent: ReducerEvent | undefined) => void) => void; + /** + * Register a callback for when a row is updated into the database. + * + * ```ts + * User.onInsert((user, reducerEvent) => { + * if (reducerEvent) { + * console.log("Updated user on reducer", reducerEvent, user); + * } else { + * console.log("Updated user received during subscription update on delete", user); + * } + * }); + * ``` + * + * @param cb Callback to be called when a new row is inserted + */ + onUpdate: (cb: (value: any, oldValue: any, reducerEvent: ReducerEvent | undefined) => void) => void; + /** + * Removes the event listener for when a new row is inserted + * @param cb Callback to be called when the event listener is removed + */ + removeOnInsert: (cb: (value: any, reducerEvent: ReducerEvent | undefined) => void) => void; + /** + * Removes the event listener for when a row is deleted + * @param cb Callback to be called when the event listener is removed + */ + removeOnDelete: (cb: (value: any, reducerEvent: ReducerEvent | undefined) => void) => void; + /** + * Removes the event listener for when a row is updated + * @param cb Callback to be called when the event listener is removed + */ + removeOnUpdate: (cb: (value: any, oldValue: any, reducerEvent: ReducerEvent | undefined) => void) => void; +} +export {}; diff --git a/dist/table.js b/dist/table.js new file mode 100644 index 0000000..f681ed5 --- /dev/null +++ b/dist/table.js @@ -0,0 +1,222 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Table = exports.TableUpdate = exports.TableOperation = void 0; +const events_1 = require("events"); +const spacetimedb_1 = require("./spacetimedb"); +const operations_map_1 = __importDefault(require("./operations_map")); +const algebraic_value_1 = require("./algebraic_value"); +const binary_reader_1 = __importDefault(require("./binary_reader")); +class DBOp { + type; + instance; + rowPk; + constructor(type, rowPk, instance) { + this.type = type; + this.rowPk = rowPk; + this.instance = instance; + } +} +class TableOperation { + /** + * The type of CRUD operation. + * + * NOTE: An update is a `delete` followed by a 'insert' internally. + */ + type; + rowPk; + row; + constructor(type, rowPk, row) { + this.type = type; + this.rowPk = rowPk; + this.row = row; + } +} +exports.TableOperation = TableOperation; +class TableUpdate { + tableName; + operations; + constructor(tableName, operations) { + this.tableName = tableName; + this.operations = operations; + } +} +exports.TableUpdate = TableUpdate; +/** + * Builder to generate calls to query a `table` in the database + */ +class Table { + // TODO: most of this stuff should be probably private + name; + instances; + emitter; + entityClass; + pkCol; + /** + * @param name the table name + * @param pkCol column designated as `#[primarykey]` + * @param entityClass the entityClass + */ + constructor(name, pkCol, entityClass) { + this.name = name; + this.instances = new Map(); + this.emitter = new events_1.EventEmitter(); + this.pkCol = pkCol; + this.entityClass = entityClass; + } + /** + * @returns number of entries in the table + */ + count() { + return this.instances.size; + } + /** + * @returns The values of the entries in the table + */ + getInstances() { + return Array.from(this.instances.values()); + } + applyOperations = (protocol, operations, reducerEvent) => { + let dbOps = []; + for (let operation of operations) { + const pk = operation.rowPk; + const adapter = protocol === "binary" + ? new algebraic_value_1.BinaryAdapter(new binary_reader_1.default(operation.row)) + : new algebraic_value_1.JSONAdapter(operation.row); + const entry = spacetimedb_1.AlgebraicValue.deserialize(this.entityClass.getAlgebraicType(), adapter); + const instance = this.entityClass.fromValue(entry); + dbOps.push(new DBOp(operation.type, pk, instance)); + } + if (this.entityClass.primaryKey !== undefined) { + const pkName = this.entityClass.primaryKey; + const inserts = []; + const deleteMap = new operations_map_1.default(); + for (const dbOp of dbOps) { + if (dbOp.type === "insert") { + inserts.push(dbOp); + } + else { + deleteMap.set(dbOp.instance[pkName], dbOp); + } + } + for (const dbOp of inserts) { + const deleteOp = deleteMap.get(dbOp.instance[pkName]); + if (deleteOp) { + // the pk for updates will differ between insert/delete, so we have to + // use the instance from delete + this.update(dbOp, deleteOp, reducerEvent); + deleteMap.delete(dbOp.instance[pkName]); + } + else { + this.insert(dbOp, reducerEvent); + } + } + for (const dbOp of deleteMap.values()) { + this.delete(dbOp, reducerEvent); + } + } + else { + for (const dbOp of dbOps) { + if (dbOp.type === "insert") { + this.insert(dbOp, reducerEvent); + } + else { + this.delete(dbOp, reducerEvent); + } + } + } + }; + update = (newDbOp, oldDbOp, reducerEvent) => { + const newInstance = newDbOp.instance; + const oldInstance = oldDbOp.instance; + this.instances.delete(oldDbOp.rowPk); + this.instances.set(newDbOp.rowPk, newInstance); + this.emitter.emit("update", oldInstance, newInstance, reducerEvent); + }; + insert = (dbOp, reducerEvent) => { + this.instances.set(dbOp.rowPk, dbOp.instance); + this.emitter.emit("insert", dbOp.instance, reducerEvent); + }; + delete = (dbOp, reducerEvent) => { + this.instances.delete(dbOp.rowPk); + this.emitter.emit("delete", dbOp.instance, reducerEvent); + }; + /** + * Register a callback for when a row is newly inserted into the database. + * + * ```ts + * User.onInsert((user, reducerEvent) => { + * if (reducerEvent) { + * console.log("New user on reducer", reducerEvent, user); + * } else { + * console.log("New user received during subscription update on insert", user); + * } + * }); + * ``` + * + * @param cb Callback to be called when a new row is inserted + */ + onInsert = (cb) => { + this.emitter.on("insert", cb); + }; + /** + * Register a callback for when a row is deleted from the database. + * + * ```ts + * User.onDelete((user, reducerEvent) => { + * if (reducerEvent) { + * console.log("Deleted user on reducer", reducerEvent, user); + * } else { + * console.log("Deleted user received during subscription update on update", user); + * } + * }); + * ``` + * + * @param cb Callback to be called when a new row is inserted + */ + onDelete = (cb) => { + this.emitter.on("delete", cb); + }; + /** + * Register a callback for when a row is updated into the database. + * + * ```ts + * User.onInsert((user, reducerEvent) => { + * if (reducerEvent) { + * console.log("Updated user on reducer", reducerEvent, user); + * } else { + * console.log("Updated user received during subscription update on delete", user); + * } + * }); + * ``` + * + * @param cb Callback to be called when a new row is inserted + */ + onUpdate = (cb) => { + this.emitter.on("update", cb); + }; + /** + * Removes the event listener for when a new row is inserted + * @param cb Callback to be called when the event listener is removed + */ + removeOnInsert = (cb) => { + this.emitter.off("insert", cb); + }; + /** + * Removes the event listener for when a row is deleted + * @param cb Callback to be called when the event listener is removed + */ + removeOnDelete = (cb) => { + this.emitter.off("delete", cb); + }; + /** + * Removes the event listener for when a row is updated + * @param cb Callback to be called when the event listener is removed + */ + removeOnUpdate = (cb) => { + this.emitter.off("update", cb); + }; +} +exports.Table = Table; diff --git a/dist/tsconfig.tsbuildinfo b/dist/tsconfig.tsbuildinfo new file mode 100644 index 0000000..d9d09ae --- /dev/null +++ b/dist/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"program":{"fileNames":["../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/typescript/lib/lib.esnext.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../node_modules/typescript/lib/lib.scripthost.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/typescript/lib/lib.es2022.intl.d.ts","../node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../node_modules/typescript/lib/lib.esnext.full.d.ts","../src/address.ts","../src/algebraic_type.ts","../src/binary_reader.ts","../src/algebraic_value.ts","../src/binary_writer.ts","../node_modules/protobufjs/index.d.ts","../node_modules/protobufjs/minimal.d.ts","../node_modules/long/index.d.ts","../node_modules/long/umd/index.d.ts","../src/client_api.ts","../node_modules/isomorphic-ws/index.d.ts","../src/websocket_test_adapter.ts","../src/identity.ts","../src/serializer.ts","../src/types.ts","../src/reducer_event.ts","../src/json_api.ts","../src/operations_map.ts","../src/table.ts","../src/utils.ts","../src/database_table.ts","../src/reducer.ts","../src/message_types.ts","../src/global.ts","../src/logger.ts","../node_modules/@types/brotli/decompress.d.ts","../node_modules/buffer/index.d.ts","../src/spacetimedb.ts","../src/index.ts","../src/client_db.ts","../node_modules/@babel/types/lib/index.d.ts","../node_modules/@types/babel__generator/index.d.ts","../node_modules/@babel/parser/typings/babel-parser.d.ts","../node_modules/@types/babel__template/index.d.ts","../node_modules/@types/babel__traverse/index.d.ts","../node_modules/@types/babel__core/index.d.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/dom-events.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/readline/promises.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/test.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts","../node_modules/@types/brotli/compress.d.ts","../node_modules/@types/brotli/index.d.ts","../node_modules/@types/eslint/helpers.d.ts","../node_modules/@types/estree/index.d.ts","../node_modules/@types/json-schema/index.d.ts","../node_modules/@types/eslint/index.d.ts","../node_modules/@types/graceful-fs/index.d.ts","../node_modules/@types/istanbul-lib-coverage/index.d.ts","../node_modules/@types/istanbul-lib-report/index.d.ts","../node_modules/@types/istanbul-reports/index.d.ts","../node_modules/@jest/expect-utils/build/index.d.ts","../node_modules/chalk/index.d.ts","../node_modules/@sinclair/typebox/typebox.d.ts","../node_modules/@jest/schemas/build/index.d.ts","../node_modules/pretty-format/build/index.d.ts","../node_modules/jest-diff/build/index.d.ts","../node_modules/jest-matcher-utils/build/index.d.ts","../node_modules/expect/build/index.d.ts","../node_modules/@types/jest/index.d.ts","../node_modules/@types/minimatch/index.d.ts","../node_modules/@types/prettier/index.d.ts","../node_modules/@types/stack-utils/index.d.ts","../node_modules/@types/websocket/index.d.ts","../node_modules/@types/yargs-parser/index.d.ts","../node_modules/@types/yargs/index.d.ts"],"fileInfos":[{"version":"8730f4bf322026ff5229336391a18bcaa1f94d4f82416c8b2f3954e2ccaae2ba","affectsGlobalScope":true,"impliedFormat":1},{"version":"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","impliedFormat":1},{"version":"7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","impliedFormat":1},{"version":"8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","impliedFormat":1},{"version":"5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","impliedFormat":1},{"version":"4b421cbfb3a38a27c279dec1e9112c3d1da296f77a1a85ddadf7e7a425d45d18","impliedFormat":1},{"version":"1fc5ab7a764205c68fa10d381b08417795fc73111d6dd16b5b1ed36badb743d9","impliedFormat":1},{"version":"746d62152361558ea6d6115cf0da4dd10ede041d14882ede3568bce5dc4b4f1f","impliedFormat":1},{"version":"d11a03592451da2d1065e09e61f4e2a9bf68f780f4f6623c18b57816a9679d17","impliedFormat":1},{"version":"aea179452def8a6152f98f63b191b84e7cbd69b0e248c91e61fb2e52328abe8c","impliedFormat":1},{"version":"3aafcb693fe5b5c3bd277bd4c3a617b53db474fe498fc5df067c5603b1eebde7","affectsGlobalScope":true,"impliedFormat":1},{"version":"f3d4da15233e593eacb3965cde7960f3fddf5878528d882bcedd5cbaba0193c7","affectsGlobalScope":true,"impliedFormat":1},{"version":"7fac8cb5fc820bc2a59ae11ef1c5b38d3832c6d0dfaec5acdb5569137d09a481","affectsGlobalScope":true,"impliedFormat":1},{"version":"097a57355ded99c68e6df1b738990448e0bf170e606707df5a7c0481ff2427cd","affectsGlobalScope":true,"impliedFormat":1},{"version":"adb996790133eb33b33aadb9c09f15c2c575e71fb57a62de8bf74dbf59ec7dfb","affectsGlobalScope":true,"impliedFormat":1},{"version":"8cc8c5a3bac513368b0157f3d8b31cfdcfe78b56d3724f30f80ed9715e404af8","affectsGlobalScope":true,"impliedFormat":1},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true,"impliedFormat":1},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true,"impliedFormat":1},{"version":"5f406584aef28a331c36523df688ca3650288d14f39c5d2e555c95f0d2ff8f6f","affectsGlobalScope":true,"impliedFormat":1},{"version":"22f230e544b35349cfb3bd9110b6ef37b41c6d6c43c3314a31bd0d9652fcec72","affectsGlobalScope":true,"impliedFormat":1},{"version":"7ea0b55f6b315cf9ac2ad622b0a7813315bb6e97bf4bb3fbf8f8affbca7dc695","affectsGlobalScope":true,"impliedFormat":1},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true,"impliedFormat":1},{"version":"eb26de841c52236d8222f87e9e6a235332e0788af8c87a71e9e210314300410a","affectsGlobalScope":true,"impliedFormat":1},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true,"impliedFormat":1},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true,"impliedFormat":1},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true,"impliedFormat":1},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true,"impliedFormat":1},{"version":"81cac4cbc92c0c839c70f8ffb94eb61e2d32dc1c3cf6d95844ca099463cf37ea","affectsGlobalScope":true,"impliedFormat":1},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true,"impliedFormat":1},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true,"impliedFormat":1},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true,"impliedFormat":1},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true,"impliedFormat":1},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true,"impliedFormat":1},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true,"impliedFormat":1},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true,"impliedFormat":1},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true,"impliedFormat":1},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true,"impliedFormat":1},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true,"impliedFormat":1},{"version":"5e5e095c4470c8bab227dbbc61374878ecead104c74ab9960d3adcccfee23205","affectsGlobalScope":true,"impliedFormat":1},{"version":"09aa50414b80c023553090e2f53827f007a301bc34b0495bfb2c3c08ab9ad1eb","affectsGlobalScope":true,"impliedFormat":1},{"version":"d7f680a43f8cd12a6b6122c07c54ba40952b0c8aa140dcfcf32eb9e6cb028596","affectsGlobalScope":true,"impliedFormat":1},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true,"impliedFormat":1},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true,"impliedFormat":1},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true,"impliedFormat":1},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true,"impliedFormat":1},{"version":"2768ef564cfc0689a1b76106c421a2909bdff0acbe87da010785adab80efdd5c","affectsGlobalScope":true,"impliedFormat":1},{"version":"b248e32ca52e8f5571390a4142558ae4f203ae2f94d5bac38a3084d529ef4e58","affectsGlobalScope":true,"impliedFormat":1},{"version":"6c55633c733c8378db65ac3da7a767c3cf2cf3057f0565a9124a16a3a2019e87","affectsGlobalScope":true,"impliedFormat":1},{"version":"fb4416144c1bf0323ccbc9afb0ab289c07312214e8820ad17d709498c865a3fe","affectsGlobalScope":true,"impliedFormat":1},{"version":"5b0ca94ec819d68d33da516306c15297acec88efeb0ae9e2b39f71dbd9685ef7","affectsGlobalScope":true,"impliedFormat":1},{"version":"34c839eaaa6d78c8674ae2c37af2236dee6831b13db7b4ef4df3ec889a04d4f2","affectsGlobalScope":true,"impliedFormat":1},{"version":"34478567f8a80171f88f2f30808beb7da15eac0538ae91282dd33dce928d98ed","affectsGlobalScope":true,"impliedFormat":1},{"version":"ab7d58e6161a550ff92e5aff755dc37fe896245348332cd5f1e1203479fe0ed1","affectsGlobalScope":true,"impliedFormat":1},{"version":"6bda95ea27a59a276e46043b7065b55bd4b316c25e70e29b572958fa77565d43","affectsGlobalScope":true,"impliedFormat":1},{"version":"aedb8de1abb2ff1095c153854a6df7deae4a5709c37297f9d6e9948b6806fa66","affectsGlobalScope":true,"impliedFormat":1},{"version":"a4da0551fd39b90ca7ce5f68fb55d4dc0c1396d589b612e1902f68ee090aaada","affectsGlobalScope":true,"impliedFormat":1},{"version":"11ffe3c281f375fff9ffdde8bbec7669b4dd671905509079f866f2354a788064","affectsGlobalScope":true,"impliedFormat":1},{"version":"52d1bb7ab7a3306fd0375c8bff560feed26ed676a5b0457fa8027b563aecb9a4","affectsGlobalScope":true,"impliedFormat":1},{"version":"d96fa8a56871904776165ceb8e00bd56127e1a017bb2664cae76223b5f815141","impliedFormat":1},{"version":"e414946578fa1df057f2e5cabfc431a1c70c253c0be1f0c57f0b3007bab07610","signature":"1911e10d5667224b953924738aa33458eb3a7988ddaa821d8f5abdb4569d260d","impliedFormat":1},{"version":"12809cb09030d62c5f9df568886945a6e312a9c30e2325cd5f93361bc13e987b","signature":"706c91e11aad88bf4bf141cf023dcac463b0ceb57193b25befb6e0c6d3ac1c06","impliedFormat":1},{"version":"99f0ab7ee2746160eb4e0ed28fe26e2057cfa78faeee83f1332097b841d2dc16","signature":"6acf6467542902342a0d5e7caaecef387389d7ef30dc77bb1378fee2d692847a","impliedFormat":1},{"version":"5f5db662903bc2286ad12cfa5c530db8b7d98baac1ff54bc22856aea964fb4b5","signature":"2c62ac48e9d5a344cdd23c42262b9c1ad7633a7272eeffa6755ed3f9261fa0bc","impliedFormat":1},{"version":"830c312ffd49fff55add7a79412e5da76231da12186b40960519db0c3648baf2","signature":"20db22dd4b58d38befd33b2ab06753f8040f750454e2ad07a0ca4b041308f689","impliedFormat":1},{"version":"688c9dfd2b7114f5f01022abb5b179659f990d5af5924f185c2644ca99fe7b77","impliedFormat":1},{"version":"932cade1c5802123b5831f332ad8a6297f0f7d14d0ee04f5a774408f393e2200","impliedFormat":1},{"version":"54fee7d009c1e7b95a9cd151cff895742b036e25972e95a90ae503d613406e8c","impliedFormat":99},{"version":"c1eedeccaf93904fd835f40b8cbd0456c356151ab0455391453e0a60df53c9e2","impliedFormat":1},{"version":"c633694dd5196defc8d7002b0b56d879afa4223233e912b92b601901684f61d5","signature":"c2c797834527a07fb1fd4331d7ca5625567e6e2c206d1d9104792f74cee9246b","impliedFormat":1},{"version":"1442a75050bad91356b11dcea6dfb877154d1f2e00f863a9b17ba5e903659503","impliedFormat":1},{"version":"a2c517bcfffac79d2de2b9f7658f924be74c6b6baefc29ad8079f02c5fa65d46","signature":"76857553c99891dd41b9a8c768f170b1c8ea8b35d09ceb4886f599a9c7e4c42e","impliedFormat":1},{"version":"62ab04539339a08688ad6a779a853b9dd7eeda928515c14e86464813e656cc01","signature":"b27f4c4e2a1861395f3304472c957f405f18de1ef822014ba4b23f2d08bc4044","impliedFormat":1},{"version":"15e77ae04e03df263bdf542d192141c284d00588272b1a7e40616f0d1c5ad587","signature":"af7efbc0c5bbcca5ce22a05b3669a7645c62b555cecc2da749ddc663fff02d81","impliedFormat":1},{"version":"20fdd938e45536d3b3f920cb703cf45c18d972851cc65053e7bf672b41394b0e","signature":"8fb2aa6a22569708a3f7bd9d11f4f35f88c70ca4cf965d283d784819d9a471f9","impliedFormat":1},{"version":"88291150d431f620e6d915fb66511ecdb92822ca34ad6623041b817429383dc4","signature":"f40c2bfa143f426e58c8b029577d6aba0acd5572d4e98200332dbb96216c30a0","impliedFormat":1},{"version":"8e262eeae8a48750ad1f9fdd99fc05d973e12e50a881a32630b6251f8ca33ce6","signature":"99123cb35fef13399413923c15b2868eba1360bf9a5851cdd1de7a2cbeeb4fc4","impliedFormat":1},{"version":"76bfb45b5cffc4e3a02a98ed8803ed0d2dc9ec0df316e0c5931ca5a5cab954f3","signature":"af4dca4064db78a3b60a357e32689c2c87c6dab9a9ebf535f758c4c56f77ed28","impliedFormat":1},{"version":"73e78583365f61a32b2a559f7094515303068defb515532b841185728f6a2781","signature":"dce323a1d0c148bb262401fd77da7ceb72cd2f59c1b5706d85e50a0ff46f6dbc","impliedFormat":1},{"version":"6d49c474b21f7198d0893248f20c01390aaaa3edc574bb81204da35e1491ebd1","signature":"e2ac154a0ee8c9b68728b6880080a9053473f251ac7894859049480cc4fd4679","impliedFormat":1},{"version":"0b5ba99d60c6632a8c115cd4d208f91b9af5df804d80389bb86854efcc28648a","signature":"b058c804b58be534c7cd4d0c341571c28add8194a51e956187b76ae9e0bca004","impliedFormat":1},{"version":"21e5867b9e6684de31a4296e7000a450d8c4aea5165a516a470c95993f5fec30","signature":"760acee5abc3873ad412c4ff365da5961179e40a8abcee398fda90746a491161","impliedFormat":1},{"version":"8e20f85e62bfbc1e9cba0ad6d9b572aff06c3b211e4cf53338fa3fa881ff6e6c","signature":"096163dc93be2483547dcf5e14b66ac6fd831c58be04dd73c689b1e8151839f5","impliedFormat":1},{"version":"9399256bb56a2aba0fab96abc2d649ec540fae99a09fd43e60590df5779f65a5","signature":"d243c0777ca5a486a797a086cfd1c0c1b3092da80ce1057b428aae8cc5c8290e","affectsGlobalScope":true,"impliedFormat":1},{"version":"0c9552cacda1635f583f9acde1717b53dd5cc1397a6eb898d1a360b436c39fd1","signature":"fe4036ba9385a2294bd37f0821e23f7e1d43c6840e93e960070f481c57b1677e","impliedFormat":1},{"version":"a6f0218395ecb8e0d736e0a19524223ab7a8a7ed217c4a99c165df2532e1beec","impliedFormat":1},{"version":"4967529644e391115ca5592184d4b63980569adf60ee685f968fd59ab1557188","impliedFormat":1},{"version":"d4fbe0c1d69dad76c7a13fb8254fb5ed33c5d80a526f38423333cf6ac0a15d35","signature":"4907f5d5a522e4a83cdecf3c53b452554d80a21fdf23b01beeabdf3bafddfc18","impliedFormat":1},{"version":"cf419146068e4a4cb06d6bc6168c24305b215c27fae40562a3c06e0f92d33311","impliedFormat":1},{"version":"fc7920bd79763370985ecbf95b87ec1d7cc3c2559d125b2049b1b4f285a54bad","signature":"75b0827c3b9ecc46f499ee46d7329ae675caf057b00de45b9c967c027edb0b13","impliedFormat":1},{"version":"3078727fed04c123165efdb42deeac5dceaa42ac62216ca13cb809dc7e13415f","impliedFormat":1},{"version":"cc957354aa3c94c9961ebf46282cfde1e81d107fc5785a61f62c67f1dd3ac2eb","impliedFormat":1},{"version":"b4f76b34637d79cefad486127115fed843762c69512d7101b7096e1293699679","impliedFormat":1},{"version":"93de1c6dab503f053efe8d304cb522bb3a89feab8c98f307a674a4fae04773e9","impliedFormat":1},{"version":"dae3d1adc67ac3dbd1cd471889301339ec439837b5df565982345be20c8fca9a","impliedFormat":1},{"version":"b6ddf3a46ccfa4441d8be84d2e9bf3087573c48804196faedbd4a25b60631beb","impliedFormat":1},{"version":"7e771891adaa85b690266bc37bd6eb43bc57eecc4b54693ead36467e7369952a","impliedFormat":1},{"version":"a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a","impliedFormat":1},{"version":"57b6cb95756d1fe3bfeb20205de27b0c5406e4a86e130c6dfa6bd92af641e09d","affectsGlobalScope":true,"impliedFormat":1},{"version":"11e2d554398d2bd460e7d06b2fa5827a297c8acfbe00b4f894a224ac0862857f","impliedFormat":1},{"version":"e193e634a99c9c1d71f1c6e4e1567a4a73584328d21ea02dd5cddbaad6693f61","affectsGlobalScope":true,"impliedFormat":1},{"version":"374ca798f244e464346f14301dc2a8b4b111af1a83b49fffef5906c338a1f922","impliedFormat":1},{"version":"5a94487653355b56018122d92392beb2e5f4a6c63ba5cef83bbe1c99775ef713","impliedFormat":1},{"version":"d5135ad93b33adcce80b18f8065087934cdc1730d63db58562edcf017e1aad9b","affectsGlobalScope":true,"impliedFormat":1},{"version":"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","impliedFormat":1},{"version":"e596c9bb2f29a2699fdd4ae89139612652245192f67f45617c5a4b20832aaae9","impliedFormat":1},{"version":"bb9c4ffa5e6290c6980b63c815cdd1625876dadb2efaf77edbe82984be93e55e","impliedFormat":1},{"version":"1cdcfc1f624d6c08aa12c73935f6e13f095919cd99edf95752951796eb225729","impliedFormat":1},{"version":"216717f17c095cde1dc19375e1ab3af0a4a485355860c077a4f9d6ea59fab5b5","impliedFormat":1},{"version":"14b5aa23c5d0ae1907bc696ac7b6915d88f7d85799cc0dc2dcf98fbce2c5a67c","impliedFormat":1},{"version":"5c439dafdc09abe4d6c260a96b822fa0ba5be7203c71a63ab1f1423cd9e838ea","impliedFormat":1},{"version":"6b526a5ec4a401ca7c26cfe6a48e641d8f30af76673bad3b06a1b4504594a960","affectsGlobalScope":true,"impliedFormat":1},{"version":"816ad2e607a96de5bcac7d437f843f5afd8957f1fa5eefa6bba8e4ed7ca8fd84","affectsGlobalScope":true,"impliedFormat":1},{"version":"80473bd0dd90ca1e166514c2dfead9d5803f9c51418864ca35abbeec6e6847e1","impliedFormat":1},{"version":"1c84b46267610a34028edfd0d035509341751262bac1062857f3c8df7aff7153","impliedFormat":1},{"version":"e6c86d83bd526c8bdb5d0bf935b8e72ce983763d600743f74d812fdf4abf4df6","impliedFormat":1},{"version":"a3d541d303ee505053f5dcbf9fafb65cac3d5631037501cd616195863a6c5740","impliedFormat":1},{"version":"8d3c583a07e0c37e876908c2d5da575019f689df8d9fa4c081d99119d53dba22","impliedFormat":1},{"version":"2c828a5405191d006115ab34e191b8474bc6c86ffdc401d1a9864b1b6e088a58","impliedFormat":1},{"version":"e630e5528e899219ae319e83bef54bf3bcb91b01d76861ecf881e8e614b167f0","affectsGlobalScope":true,"impliedFormat":1},{"version":"bcebb922784739bdb34c18ee51095d25a92b560c78ccd2eaacd6bd00f7443d83","impliedFormat":1},{"version":"7ee6ed878c4528215c82b664fe0cfe80e8b4da6c0d4cc80869367868774db8b1","impliedFormat":1},{"version":"b0973c3cbcdc59b37bf477731d468696ecaf442593ec51bab497a613a580fe30","impliedFormat":1},{"version":"4989e92ba5b69b182d2caaea6295af52b7dc73a4f7a2e336a676722884e7139d","affectsGlobalScope":true,"impliedFormat":1},{"version":"0715e4cd28ad471b2a93f3e552ff51a3ae423417a01a10aa1d3bc7c6b95059d6","affectsGlobalScope":true,"impliedFormat":1},{"version":"5153a2fd150e46ce57bb3f8db1318d33f6ad3261ed70ceeff92281c0608c74a3","impliedFormat":1},{"version":"210d54cd652ec0fec8c8916e4af59bb341065576ecda039842f9ffb2e908507c","impliedFormat":1},{"version":"36b03690b628eab08703d63f04eaa89c5df202e5f1edf3989f13ad389cd2c091","impliedFormat":1},{"version":"0effadd232a20498b11308058e334d3339cc5bf8c4c858393e38d9d4c0013dcf","impliedFormat":1},{"version":"25846d43937c672bab7e8195f3d881f93495df712ee901860effc109918938cc","impliedFormat":1},{"version":"7d55d78cd47cf5280643b53434b16c2d9d11d144126932759fbdd51da525eec4","impliedFormat":1},{"version":"1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff","impliedFormat":1},{"version":"69ee23dd0d215b09907ad30d23f88b7790c93329d1faf31d7835552a10cf7cbf","impliedFormat":1},{"version":"44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","impliedFormat":1},{"version":"23b89798789dffbd437c0c423f5d02d11f9736aea73d6abf16db4f812ff36eda","impliedFormat":1},{"version":"f69ff39996a61a0dd10f4bce73272b52e8024a4d58b13ab32bf4712909d0a2b7","impliedFormat":1},{"version":"3c4ba1dd9b12ffa284b565063108f2f031d150ea15b8fafbdc17f5d2a07251f3","affectsGlobalScope":true,"impliedFormat":1},{"version":"e10177274a35a9d07c825615340b2fcde2f610f53f3fb40269fd196b4288dda6","impliedFormat":1},{"version":"c4577fb855ca259bdbf3ea663ca73988ce5f84251a92b4aef80a1f4122b6f98e","impliedFormat":1},{"version":"3c13ef48634e7b5012fcf7e8fce7496352c2d779a7201389ca96a2a81ee4314d","impliedFormat":1},{"version":"5d0a25ec910fa36595f85a67ac992d7a53dd4064a1ba6aea1c9f14ab73a023f2","impliedFormat":1},{"version":"f0900cd5d00fe1263ff41201fb8073dbeb984397e4af3b8002a5c207a30bdc33","affectsGlobalScope":true,"impliedFormat":1},{"version":"ff07a9a03c65732ccc59b3c65bc584173da093bd563a6565411c01f5703bd3cb","affectsGlobalScope":true,"impliedFormat":1},{"version":"6de4a219df57d2b27274d59b67708f13c2cbf7ed211abe57d8f9ab8b25cde776","impliedFormat":1},{"version":"0fe8985a28f82c450a04a6edf1279d7181c0893f37da7d2a27f8efd4fd5edb03","impliedFormat":1},{"version":"e59a892d87e72733e2a9ca21611b9beb52977be2696c7ba4b216cbbb9a48f5aa","impliedFormat":1},{"version":"da26af7362f53d122283bc69fed862b9a9fe27e01bc6a69d1d682e0e5a4df3e6","affectsGlobalScope":true,"impliedFormat":1},{"version":"8a300fa9b698845a1f9c41ecbe2c5966634582a8e2020d51abcace9b55aa959e","impliedFormat":1},{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true,"impliedFormat":1},{"version":"d8d555f3d607ecaa18d55de6995ea8f206342ecc93305919eac945c7c78c78c6","impliedFormat":1},{"version":"a67afbd107f07baa83e5deca88e364424d25fce827c93155e61cb2dfbd591885","impliedFormat":1},{"version":"983ecff1acbaec6c7e91a04e1406f088102c7c171adae0cca26c87e8f0612307","impliedFormat":1},{"version":"64d4b35c5456adf258d2cf56c341e203a073253f229ef3208fc0d5020253b241","affectsGlobalScope":true,"impliedFormat":1},{"version":"bee89e1eb6425eb49894f3f25e4562dc2564e84e5aa7610b7e13d8ecddf8f5db","impliedFormat":1},{"version":"dca41e86e89dfb2e85e6935260250f02eb6683b86c2fa16bec729ddd1bcd9b4b","impliedFormat":1},{"version":"894e2eb01e3ac0dda3722dc520d804faa863fd6e2938c801e4c8561e7b0c8a40","impliedFormat":1},{"version":"bf88ef4208a770ca39a844b182b3695df536326ea566893fdc5b8418702a331e","impliedFormat":1},{"version":"8b06ac3faeacb8484d84ddb44571d8f410697f98d7bfa86c0fda60373a9f5215","impliedFormat":1},{"version":"7eb06594824ada538b1d8b48c3925a83e7db792f47a081a62cf3e5c4e23cf0ee","impliedFormat":1},{"version":"f5638f7c2f12a9a1a57b5c41b3c1ea7db3876c003bab68e6a57afd6bcc169af0","impliedFormat":1},{"version":"6c1e688f95fcaf53b1e41c0fdadf2c1cfc96fa924eaf7f9fdb60f96deb0a4986","impliedFormat":1},{"version":"0d14fa22c41fdc7277e6f71473b20ebc07f40f00e38875142335d5b63cdfc9d2","impliedFormat":1},{"version":"db25694be959314fd1e868d72e567746db1db9e2001fae545d12d2a8c1bba1b8","impliedFormat":1},{"version":"43883cf3635bb1846cbdc6c363787b76227677388c74f7313e3f0edb380840fa","impliedFormat":1},{"version":"2d47012580f859dae201d2eef898a416bdae719dffc087dfd06aefe3de2f9c8d","impliedFormat":1},{"version":"3e70a7e67c2cb16f8cd49097360c0309fe9d1e3210ff9222e9dac1f8df9d4fb6","impliedFormat":1},{"version":"ab68d2a3e3e8767c3fba8f80de099a1cfc18c0de79e42cb02ae66e22dfe14a66","impliedFormat":1},{"version":"2cec1a31729b9b01e9294c33fc9425d336eff067282809761ad2e74425d6d2a5","impliedFormat":1},{"version":"458e2fd1185e659cb800ef68d01ef77de70dcab8860bedf6d94eaebe736751f1","affectsGlobalScope":true,"impliedFormat":1},{"version":"8841e2aa774b89bd23302dede20663306dc1b9902431ac64b24be8b8d0e3f649","impliedFormat":1},{"version":"bc88e4049153bc4dddb4503ed7e624eb141edfa9064b3659d6c86e900fe9e621","impliedFormat":1},{"version":"b0d10e46cfe3f6c476b69af02eaa38e4ccc7430221ce3109ae84bb9fb8282298","impliedFormat":1},{"version":"aec59f80c62291ec634283d443b27ebe6fc6cf57670057aa9a172927675bfbea","impliedFormat":1},{"version":"70e9a18da08294f75bf23e46c7d69e67634c0765d355887b9b41f0d959e1426e","impliedFormat":1},{"version":"e9eb1b173aa166892f3eddab182e49cfe59aa2e14d33aedb6b49d175ed6a3750","impliedFormat":1}],"options":{"allowSyntheticDefaultImports":true,"declaration":true,"esModuleInterop":true,"module":1,"noImplicitAny":false,"outDir":"./","skipLibCheck":true,"strict":true,"target":99},"fileIdsList":[[90,142],[142],[142,162],[90,91,92,93,94,142],[90,92,142],[85,142,149,150],[142,152,153,154],[113,142,149],[142,157],[142,158],[142,164,167],[96,142],[99,142],[100,105,133,142],[101,112,113,120,130,141,142],[101,102,112,120,142],[103,142],[104,105,113,121,142],[105,130,138,142],[106,108,112,120,142],[107,142],[108,109,142],[112,142],[110,112,142],[112,113,114,130,141,142],[112,113,114,127,130,133,142],[142,146],[108,115,120,130,141,142],[112,113,115,116,120,130,138,141,142],[115,117,130,138,141,142],[96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148],[112,118,142],[119,141,142],[108,112,120,130,142],[121,142],[122,142],[99,123,142],[124,140,142,146],[125,142],[126,142],[112,127,128,142],[127,129,142,144],[100,112,130,131,132,133,142],[100,130,132,142],[130,131,142],[133,142],[134,142],[112,136,137,142],[136,137,142],[105,120,130,138,142],[139,142],[120,140,142],[100,115,126,141,142],[105,142],[130,142,143],[142,144],[142,145],[100,105,112,114,123,130,141,142,144,146],[130,142,147],[112,115,117,120,141,142,149],[142,173],[142,160,166],[142,164],[142,161,165],[67,142],[142,163],[65,142],[61,62,142],[66,68,142],[78,88,142],[75,79,87,89,142],[87,89,142],[60,72,82,87,89,142],[87,142],[60,72,142],[61,64,72,142],[60,61,62,63,69,70,71,72,73,74,75,76,78,79,80,81,82,83,84,85,89,100,112,142],[62,63,75,77,87,112,142],[61,62],[66],[78,88],[75,87,89],[87,89],[87],[60,72],[61],[60,61,63,70,71,72,73,74,75,80,81,83,89,112],[75,87,112]],"referencedMap":[[92,1],[90,2],[160,2],[163,3],[162,2],[95,4],[91,1],[93,5],[94,1],[150,2],[85,2],[151,6],[152,2],[155,7],[153,2],[156,8],[157,2],[158,9],[159,10],[168,11],[154,2],[169,2],[96,12],[97,12],[99,13],[100,14],[101,15],[102,16],[103,17],[104,18],[105,19],[106,20],[107,21],[108,22],[109,22],[111,23],[110,24],[112,23],[113,25],[114,26],[98,27],[148,2],[115,28],[116,29],[117,30],[149,31],[118,32],[119,33],[120,34],[121,35],[122,36],[123,37],[124,38],[125,39],[126,40],[127,41],[128,41],[129,42],[130,43],[132,44],[131,45],[133,46],[134,47],[135,2],[136,48],[137,49],[138,50],[139,51],[140,52],[141,53],[142,54],[143,55],[144,56],[145,57],[146,58],[147,59],[170,2],[171,2],[172,60],[173,2],[174,61],[86,2],[161,2],[167,62],[70,2],[165,63],[166,64],[67,2],[68,65],[164,66],[65,2],[66,67],[11,2],[12,2],[16,2],[15,2],[2,2],[17,2],[18,2],[19,2],[20,2],[21,2],[22,2],[23,2],[24,2],[3,2],[4,2],[28,2],[25,2],[26,2],[27,2],[29,2],[30,2],[31,2],[5,2],[32,2],[33,2],[34,2],[35,2],[6,2],[39,2],[36,2],[37,2],[38,2],[40,2],[7,2],[41,2],[46,2],[47,2],[42,2],[43,2],[44,2],[45,2],[8,2],[51,2],[48,2],[49,2],[50,2],[52,2],[9,2],[53,2],[54,2],[55,2],[56,2],[57,2],[1,2],[10,2],[59,2],[58,2],[14,2],[13,2],[60,2],[61,2],[63,68],[62,2],[64,2],[69,69],[89,70],[80,71],[83,72],[72,2],[88,73],[76,2],[84,2],[82,70],[77,2],[81,74],[75,75],[73,76],[87,77],[78,78],[74,2],[79,74],[71,2]],"exportedModulesMap":[[92,1],[90,2],[160,2],[163,3],[162,2],[95,4],[91,1],[93,5],[94,1],[150,2],[85,2],[151,6],[152,2],[155,7],[153,2],[156,8],[157,2],[158,9],[159,10],[168,11],[154,2],[169,2],[96,12],[97,12],[99,13],[100,14],[101,15],[102,16],[103,17],[104,18],[105,19],[106,20],[107,21],[108,22],[109,22],[111,23],[110,24],[112,23],[113,25],[114,26],[98,27],[148,2],[115,28],[116,29],[117,30],[149,31],[118,32],[119,33],[120,34],[121,35],[122,36],[123,37],[124,38],[125,39],[126,40],[127,41],[128,41],[129,42],[130,43],[132,44],[131,45],[133,46],[134,47],[135,2],[136,48],[137,49],[138,50],[139,51],[140,52],[141,53],[142,54],[143,55],[144,56],[145,57],[146,58],[147,59],[170,2],[171,2],[172,60],[173,2],[174,61],[86,2],[161,2],[167,62],[70,2],[165,63],[166,64],[67,2],[68,65],[164,66],[65,2],[66,67],[11,2],[12,2],[16,2],[15,2],[2,2],[17,2],[18,2],[19,2],[20,2],[21,2],[22,2],[23,2],[24,2],[3,2],[4,2],[28,2],[25,2],[26,2],[27,2],[29,2],[30,2],[31,2],[5,2],[32,2],[33,2],[34,2],[35,2],[6,2],[39,2],[36,2],[37,2],[38,2],[40,2],[7,2],[41,2],[46,2],[47,2],[42,2],[43,2],[44,2],[45,2],[8,2],[51,2],[48,2],[49,2],[50,2],[52,2],[9,2],[53,2],[54,2],[55,2],[56,2],[57,2],[1,2],[10,2],[59,2],[58,2],[14,2],[13,2],[63,79],[69,80],[89,81],[80,82],[83,83],[88,73],[82,81],[81,84],[75,85],[73,86],[87,87],[78,88],[79,84]],"semanticDiagnosticsPerFile":[92,90,160,163,162,95,91,93,94,150,85,151,152,155,153,156,157,158,159,168,154,169,96,97,99,100,101,102,103,104,105,106,107,108,109,111,110,112,113,114,98,148,115,116,117,149,118,119,120,121,122,123,124,125,126,127,128,129,130,132,131,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,170,171,172,173,174,86,161,167,70,165,166,67,68,164,65,66,11,12,16,15,2,17,18,19,20,21,22,23,24,3,4,28,25,26,27,29,30,31,5,32,33,34,35,6,39,36,37,38,40,7,41,46,47,42,43,44,45,8,51,48,49,50,52,9,53,54,55,56,57,1,10,59,58,14,13,60,61,63,62,64,69,89,80,83,72,88,76,84,82,77,81,75,73,87,78,74,79,71]},"version":"4.9.3"} \ No newline at end of file diff --git a/dist/types.d.ts b/dist/types.d.ts new file mode 100644 index 0000000..df3a9e1 --- /dev/null +++ b/dist/types.d.ts @@ -0,0 +1 @@ +export type EventType = "update" | "insert" | "delete" | "initialStateSync" | "connected" | "disconnected" | "client_error"; diff --git a/dist/types.js b/dist/types.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/dist/types.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/dist/utils.d.ts b/dist/utils.d.ts new file mode 100644 index 0000000..44d6bdc --- /dev/null +++ b/dist/utils.d.ts @@ -0,0 +1,3 @@ +import { SpacetimeDBClient } from "./spacetimedb"; +export declare function _tableProxy(t: any, client: SpacetimeDBClient): T; +export declare function toPascalCase(s: string): string; diff --git a/dist/utils.js b/dist/utils.js new file mode 100644 index 0000000..76c2a6a --- /dev/null +++ b/dist/utils.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toPascalCase = exports._tableProxy = void 0; +// Helper function for creating a proxy for a table class +function _tableProxy(t, client) { + return new Proxy(t, { + get: (target, prop) => { + if (typeof target[prop] === "function") { + return (...args) => { + const originalDb = t.db; + t.db = client.db; + const result = t[prop](...args); + t.db = originalDb; + return result; + }; + } + else { + return t[prop]; + } + }, + }); +} +exports._tableProxy = _tableProxy; +function toPascalCase(s) { + const str = s.replace(/([-_][a-z])/gi, ($1) => { + return $1.toUpperCase().replace("-", "").replace("_", ""); + }); + return str.charAt(0).toUpperCase() + str.slice(1); +} +exports.toPascalCase = toPascalCase; diff --git a/dist/websocket_test_adapter.d.ts b/dist/websocket_test_adapter.d.ts new file mode 100644 index 0000000..0f613a7 --- /dev/null +++ b/dist/websocket_test_adapter.d.ts @@ -0,0 +1,15 @@ +declare class WebsocketTestAdapter { + onclose: any; + onopen: Function; + onmessage: any; + onerror: any; + messageQueue: any[]; + closed: boolean; + constructor(); + send(message: any): void; + close(): void; + acceptConnection(): void; + sendToClient(message: any): void; +} +export type { WebsocketTestAdapter }; +export default WebsocketTestAdapter; diff --git a/dist/websocket_test_adapter.js b/dist/websocket_test_adapter.js new file mode 100644 index 0000000..857a782 --- /dev/null +++ b/dist/websocket_test_adapter.js @@ -0,0 +1,30 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class WebsocketTestAdapter { + onclose; + onopen; + onmessage; + onerror; + messageQueue; + closed; + constructor() { + this.messageQueue = []; + this.closed = false; + } + send(message) { + this.messageQueue.push(message); + } + close() { + this.closed = true; + } + acceptConnection() { + this.onopen(); + } + sendToClient(message) { + if (typeof message.data !== 'string') { + message.data = JSON.stringify(message.data); + } + this.onmessage(message); + } +} +exports.default = WebsocketTestAdapter;