diff --git a/functions.ts b/functions.ts index 7478ad24..5d1e050c 100644 --- a/functions.ts +++ b/functions.ts @@ -8,7 +8,7 @@ import { AsyncTransformFunction, CollapsedValue, CollapsedValueAdvanced, Decorat import { Datex } from "./mod.ts"; import { PointerError } from "./types/errors.ts"; import { IterableHandler } from "./utils/iterable-handler.ts"; -import { RestrictSameType } from "./runtime/pointers.ts"; +import { MinimalJSRefWithIndirectRef, RestrictSameType } from "./runtime/pointers.ts"; /** @@ -23,13 +23,13 @@ import { RestrictSameType } from "./runtime/pointers.ts"; * y.val // 10 * ``` */ -export function always(transform:SmartTransformFunction, options?: SmartTransformOptions): MinimalJSRef // return signature from Value.collapseValue(Pointer.smartTransform()) +export function always(transform:SmartTransformFunction, options?: SmartTransformOptions): MinimalJSRefWithIndirectRef // return signature from Value.collapseValue(Pointer.smartTransform()) /** * Shortcut for datex `always (...)` * @param script * @param vars */ -export function always(script:TemplateStringsArray, ...vars:any[]): Promise> +export function always(script:TemplateStringsArray, ...vars:any[]): Promise> export function always(scriptOrJSTransform:TemplateStringsArray|SmartTransformFunction, ...vars:any[]) { // js function if (typeof scriptOrJSTransform == "function") { @@ -64,7 +64,7 @@ export function always(scriptOrJSTransform:TemplateStringsArray|SmartTransformFu * } * ``` */ -export async function asyncAlways(transform:SmartTransformFunction, options?: SmartTransformOptions): Promise> { // return signature from Value.collapseValue(Pointer.smartTransform()) +export async function asyncAlways(transform:SmartTransformFunction, options?: SmartTransformOptions): Promise> { // return signature from Value.collapseValue(Pointer.smartTransform()) // make sure handler is not an async function if (transform.constructor.name == "AsyncFunction") { throw new Error("asyncAlways cannot be used with async functions, but with functions returning a Promise") diff --git a/runtime/pointers.ts b/runtime/pointers.ts index 660b56a4..a35bf19f 100644 --- a/runtime/pointers.ts +++ b/runtime/pointers.ts @@ -840,7 +840,8 @@ export type AnyObjectRef = {$: Record, $$: Record> = +// if a value is a object ref, it is converted to a Pointer +export type MinimalJSRefWithIndirectRef> = _C extends symbol ? symbol : ( _C extends WrappedPointerValue ? PointerWithPrimitive<_C>: // keep pointer reference @@ -849,6 +850,13 @@ export type MinimalJSRef> = ObjectRef<_C> // collapsed object ) +export type MinimalJSRef> = + _C extends symbol ? symbol : ( + _C extends WrappedPointerValue ? + PointerWithPrimitive<_C>: // keep pointer reference + ObjectRef<_C> // collapsed object + ) + // return Pointer&T for primitives (excluding boolean) and Pointer otherwise export type PointerWithPrimitive = T extends WrappedPointerValue ? T extends primitive ?