Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"@std/fmt": "jsr:@std/fmt@^1.0.8",
"@std/fs": "jsr:@std/fs@^1.0.19",
"@std/uuid": "jsr:@std/uuid@^1.0.9",
"@unyt/speck": "jsr:@unyt/speck@^0.0.10"
"@unyt/speck": "jsr:@unyt/speck@^0.0.10",
"datex-core-js/": "./src/"
},
"test": {
"exclude": [
Expand Down
2 changes: 1 addition & 1 deletion rs-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ panic = "abort"

[dependencies]
log = { version = "0.4", features = ["std", "serde"] }
datex-core = { version = "0.0.7", git = "https://github.com/unyt-org/datex-core", branch = "release/0.0.7", default-features = false, features = [
datex-core = { version = "0.0.7", git = "https://github.com/unyt-org/datex-core", branch = "feat/variant-access", default-features = false, features = [
"std",
"wasm_logger",
"wasm_runtime",
Expand Down
16 changes: 10 additions & 6 deletions rs-lib/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::borrow::Cow;
use crate::crypto::crypto_js::CryptoJS;
use crate::js_utils::{js_array, js_error};
use crate::network::com_hub::JSComHub;
Expand Down Expand Up @@ -468,8 +469,11 @@ impl RuntimeDIFHandle {
let cb = callback.clone();
let observe_options: ObserveOptions =
from_value(observe_options).map_err(js_error)?;
let observer = move |update: &DIFUpdate| {
let js_value = to_js_value(update).unwrap();
let observer = move |update_data: &DIFUpdateData, source_id: TransceiverId| {
let js_value = to_js_value(&DIFUpdate {
source_id,
data: Cow::Borrowed(update_data),
}).unwrap();
let _ = cb.call1(&JsValue::NULL, &js_value);
};
self.internal
Expand Down Expand Up @@ -514,7 +518,7 @@ impl RuntimeDIFHandle {
let address = Self::js_value_to_pointer_address(address)?;
let dif_update_data: DIFUpdateData =
from_value(update).map_err(js_error)?;
DIFInterface::update(self, transceiver_id, address, dif_update_data)
DIFInterface::update(self, transceiver_id, address, &dif_update_data)
.map_err(js_error)
}

Expand Down Expand Up @@ -598,7 +602,7 @@ impl DIFInterface for RuntimeDIFHandle {
&self,
source_id: TransceiverId,
address: PointerAddress,
update: DIFUpdateData,
update: &DIFUpdateData,
) -> Result<(), DIFUpdateError> {
self.internal.update(source_id, address, update)
}
Expand Down Expand Up @@ -637,12 +641,12 @@ impl DIFInterface for RuntimeDIFHandle {
.create_pointer(value, allowed_type, mutability)
}

fn observe_pointer<F: Fn(&DIFUpdate) + 'static>(
fn observe_pointer(
&self,
transceiver_id: TransceiverId,
address: PointerAddress,
options: ObserveOptions,
observer: F,
observer: impl Fn(&DIFUpdateData, TransceiverId) + 'static,
) -> Result<u32, DIFObserveError> {
self.internal.observe_pointer(
transceiver_id,
Expand Down
84 changes: 42 additions & 42 deletions src/datex-core/datex_core_js.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,31 @@
// deno-lint-ignore-file
// deno-fmt-ignore-file

export function create_runtime(config: string, debug_flags: any): JSRuntime;
/**
* Executes a Datex script and returns the result as a string.
*/
export function execute(datex_script: string, formatted: boolean): string;
/**
* Executes a Datex script and returns true when execution was successful.
* Does not return the result of the script, but only indicates success or failure.
*/
export function execute_internal(datex_script: string): boolean;
/**
* Executes a Datex script and returns the result as a string.
*/
export function execute(datex_script: string, formatted: boolean): string;
export type BaseInterfaceSetupData = InterfaceProperties;

export interface SerialInterfaceSetupData {
port_name: string | undefined;
baud_rate: number;
}

export interface WebRTCInterfaceSetupData {
peer_endpoint: string;
ice_servers: RTCIceServer[] | undefined;
}

export interface WebSocketClientInterfaceSetupData {
address: string;
}

export interface WebSocketServerInterfaceSetupData {
port: number;
/**
* if true, the server will use wss (secure WebSocket). Defaults to true.
*/
secure: boolean | undefined;
}

export function create_runtime(config: string, debug_flags: any): JSRuntime;
export interface RTCIceServer {
urls: string[];
username: string | undefined;
credential: string | undefined;
}

export type ReconnectionConfig = "NoReconnect" | "InstantReconnect" | {
ReconnectWithTimeout: { timeout: { secs: number; nanos: number } };
} | {
ReconnectWithTimeoutAndAttempts: {
timeout: { secs: number; nanos: number };
attempts: number;
};
};

export interface InterfaceProperties {
/**
* the type of the interface, by which it is identified
Expand Down Expand Up @@ -104,17 +89,32 @@ export interface InterfaceProperties {
reconnect_attempts: number | undefined;
}

export type ReconnectionConfig = "NoReconnect" | "InstantReconnect" | {
ReconnectWithTimeout: { timeout: { secs: number; nanos: number } };
} | {
ReconnectWithTimeoutAndAttempts: {
timeout: { secs: number; nanos: number };
attempts: number;
};
};

export type InterfaceDirection = "In" | "Out" | "InOut";

export type BaseInterfaceSetupData = InterfaceProperties;

export interface WebSocketServerInterfaceSetupData {
port: number;
/**
* if true, the server will use wss (secure WebSocket). Defaults to true.
*/
secure: boolean | undefined;
}

export interface WebSocketClientInterfaceSetupData {
address: string;
}

export interface SerialInterfaceSetupData {
port_name: string | undefined;
baud_rate: number;
}

export interface WebRTCInterfaceSetupData {
peer_endpoint: string;
ice_servers: RTCIceServer[] | undefined;
}

export class BaseJSInterface {
private constructor();
free(): void;
Expand Down Expand Up @@ -144,6 +144,10 @@ export class JSComHub {
register_outgoing_block_interceptor(callback: Function): void;
register_default_interface_factories(): void;
update(): Promise<void>;
websocket_server_interface_add_socket(
interface_uuid: string,
websocket: WebSocket,
): string;
webrtc_interface_set_answer(
interface_uuid: string,
answer: Uint8Array,
Expand All @@ -162,10 +166,6 @@ export class JSComHub {
interface_uuid: string,
on_ice_candidate: Function,
): void;
websocket_server_interface_add_socket(
interface_uuid: string,
websocket: WebSocket,
): string;
base_interface_on_send(uuid: string, func: Function): void;
base_interface_receive(
uuid: string,
Expand Down
38 changes: 0 additions & 38 deletions src/dif/builders.ts

This file was deleted.

85 changes: 55 additions & 30 deletions src/dif/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@ export type DIFValue = {
type?: DIFTypeContainer;
value: DIFRepresentationValue;
};
/**
* A DATEX value or pointer address representation in the DIF format.
*/
export type DIFContainer = DIFValue | DIFPointerAddress;

/**
* Mapping of DIF type kinds.
*/
export const DIFTypeKinds = {
Structural: 0,
Reference: 1,
Intersection: 2,
Union: 3,
Unit: 4,
Function: 5,
export const DIFTypeKind = {
Structural: "structural",
Reference: "reference",
Intersection: "intersection",
Union: "union",
Unit: "unit",
Function: "function",
MarkedType: "marked-type",
} as const;
/** A DIF type kind. */
export type DIFTypeKind = typeof DIFTypeKinds[keyof typeof DIFTypeKinds];
export type DIFTypeKind = typeof DIFTypeKind[keyof typeof DIFTypeKind];

/**
* Representation of reference mutability (mutable or immutable) in DIF.
Expand All @@ -49,13 +46,12 @@ export type DIFReferenceMutability =

/** A DIF type definition based on its kind. */
export type DIFTypeDefinition<Kind extends DIFTypeKind = DIFTypeKind> =
Kind extends typeof DIFTypeKinds.Structural ? DIFValue
: Kind extends typeof DIFTypeKinds.Reference ? DIFPointerAddress
: Kind extends typeof DIFTypeKinds.Intersection
? Array<DIFTypeContainer>
: Kind extends typeof DIFTypeKinds.Union ? Array<DIFTypeContainer>
: Kind extends typeof DIFTypeKinds.Unit ? null
: Kind extends typeof DIFTypeKinds.Function ? unknown // TODO
Kind extends typeof DIFTypeKind.Structural ? DIFValue
: Kind extends typeof DIFTypeKind.Reference ? DIFPointerAddress
: Kind extends typeof DIFTypeKind.Intersection ? Array<DIFTypeContainer>
: Kind extends typeof DIFTypeKind.Union ? Array<DIFTypeContainer>
: Kind extends typeof DIFTypeKind.Unit ? null
: Kind extends typeof DIFTypeKind.Function ? unknown // TODO
: never;

/** A DIF type representation. */
Expand Down Expand Up @@ -108,25 +104,54 @@ export type DIFProperty =
*/
export const DIFUpdateKind = {
Replace: "replace",
Push: "push",
Append: "append",
Set: "set",
Remove: "remove",
Delete: "delete",
Clear: "clear",
ListSplice: "list_splice",
} as const;
/** A DIF update kind. */
export type DIFUpdateKind = typeof DIFUpdateKind[keyof typeof DIFUpdateKind];

/** Different kinds of updates that can be applied to a DIF value. */
export type DIFUpdateData =
| { kind: typeof DIFUpdateKind.Replace; value: DIFValueContainer }
| { kind: typeof DIFUpdateKind.Push; value: DIFValueContainer }
| { kind: typeof DIFUpdateKind.Remove; key: DIFProperty }
| {
kind: typeof DIFUpdateKind.Set;
key: DIFProperty;
export type DIFUpdateBaseData<Kind extends DIFUpdateKind> = {
kind: Kind;
};
export type DIFUpdateDataReplace =
& DIFUpdateBaseData<typeof DIFUpdateKind.Replace>
& {
value: DIFValueContainer;
}
| { kind: typeof DIFUpdateKind.Clear };
};
export type DIFUpdateDataPush =
& DIFUpdateBaseData<typeof DIFUpdateKind.Append>
& {
value: DIFValueContainer;
};
export type DIFUpdateDataDelete =
& DIFUpdateBaseData<typeof DIFUpdateKind.Delete>
& {
key: DIFProperty;
};
export type DIFUpdateDataSet = DIFUpdateBaseData<typeof DIFUpdateKind.Set> & {
key: DIFProperty;
value: DIFValueContainer;
};
export type DIFUpdateDataClear = DIFUpdateBaseData<typeof DIFUpdateKind.Clear>;
export type DIFUpdateDataListSplice =
& DIFUpdateBaseData<typeof DIFUpdateKind.ListSplice>
& {
start: number;
delete_count: number;
items: DIFValueContainer[];
};

export type DIFUpdateData =
| DIFUpdateDataReplace
| DIFUpdateDataPush
| DIFUpdateDataDelete
| DIFUpdateDataSet
| DIFUpdateDataClear
| DIFUpdateDataListSplice;

/** A DIF update struct, associating a source ID with update data. */
export type DIFUpdate = {
Expand Down
Loading
Loading