Skip to content

Commit

Permalink
Merge pull request #67 from unyt-org/fix-cleanup
Browse files Browse the repository at this point in the history
Fix cleanup
  • Loading branch information
jonasstrehle authored Jan 30, 2024
2 parents 884409e + bc208b9 commit 911d75d
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 177 deletions.
16 changes: 8 additions & 8 deletions datex_short.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// shortcut functions
// import { Datex } from "./datex.ts";
import { baseURL, Runtime, PrecompiledDXB, Type, Pointer, Ref, PointerProperty, primitive, any_class, Target, IdEndpoint, TransformFunctionInputs, AsyncTransformFunction, TransformFunction, TextRef, Markdown, DecimalRef, BooleanRef, IntegerRef, MinimalJSRef, RefOrValue, PartialRefOrValueObject, datex_meta, ObjectWithDatexValues, Compiler, endpoint_by_endpoint_name, endpoint_name, Storage, compiler_scope, datex_scope, DatexResponse, target_clause, ValueError, logger, Class, getUnknownMeta, Endpoint, INSERT_MARK, CollapsedValueAdvanced, CollapsedValue, SmartTransformFunction, compiler_options, activePlugins, METADATA, handleDecoratorArgs, RefOrValueObject, PointerPropertyParent, InferredPointerProperty, RefLike } from "./datex_all.ts";
import { baseURL, Runtime, PrecompiledDXB, Type, Pointer, Ref, PointerProperty, primitive, any_class, Target, IdEndpoint, TransformFunctionInputs, AsyncTransformFunction, TransformFunction, Markdown, MinimalJSRef, RefOrValue, PartialRefOrValueObject, datex_meta, ObjectWithDatexValues, Compiler, endpoint_by_endpoint_name, endpoint_name, Storage, compiler_scope, datex_scope, DatexResponse, target_clause, ValueError, logger, Class, getUnknownMeta, Endpoint, INSERT_MARK, CollapsedValueAdvanced, CollapsedValue, SmartTransformFunction, compiler_options, activePlugins, METADATA, handleDecoratorArgs, RefOrValueObject, PointerPropertyParent, InferredPointerProperty, RefLike } from "./datex_all.ts";

/** make decorators global */
import { assert as _assert, property as _property, sync as _sync, endpoint as _endpoint, template as _template, jsdoc as _jsdoc} from "./datex_all.ts";
Expand Down Expand Up @@ -357,25 +357,25 @@ export function val<T>(val: RefOrValue<T>):T { // TODO: return inferred type in


// generate primitive pointers
export function decimal(value:RefOrValue<number|bigint|string> = 0): DecimalRef {
export function decimal(value:RefOrValue<number|bigint|string> = 0): Pointer<number> {
if (value instanceof Ref) value = value.val; // collapse
return Pointer.create(undefined, Number(value)) // adds pointer or returns existing pointer
}
export function integer(value:RefOrValue<bigint|number|string> = 0n): IntegerRef {
export function integer(value:RefOrValue<bigint|number|string> = 0n): Pointer<bigint> {
if (value instanceof Ref) value = value.val; // collapse
return Pointer.create(undefined, BigInt(Math.floor(Number(value)))) // adds pointer or returns existing pointer
}
export function text(string:TemplateStringsArray, ...vars:any[]):Promise<TextRef>
export function text(value?:RefOrValue<any>): TextRef
export function text(value:RefOrValue<string>|TemplateStringsArray = "", ...vars:any[]): TextRef|Promise<TextRef> {
export function text(string:TemplateStringsArray, ...vars:any[]):Promise<Pointer<string>>
export function text(value?:RefOrValue<any>): Pointer<string>
export function text(value:RefOrValue<string>|TemplateStringsArray = "", ...vars:any[]): Pointer<string>|Promise<Pointer<string>> {
if (value instanceof Ref) value = value.val; // collapse
// template transform
if (value instanceof Array) {
return <Promise<TextRef<string>>>_datex(`always '${value.raw.map(s=>s.replace(/\(/g, '\\(').replace(/\'/g, "\\'")).join(INSERT_MARK)}'`, vars)
return <Promise<Pointer<string>>>_datex(`always '${value.raw.map(s=>s.replace(/\(/g, '\\(').replace(/\'/g, "\\'")).join(INSERT_MARK)}'`, vars)
}
else return Pointer.create(undefined, String(value)) // adds pointer or returns existing pointer
}
export function boolean(value:RefOrValue<boolean> = false): BooleanRef {
export function boolean(value:RefOrValue<boolean> = false): Pointer<boolean> {
if (value instanceof Ref) value = value.val; // collapse
return Pointer.create(undefined, Boolean(value)) // adds pointer or returns existing pointer
}
Expand Down
8 changes: 4 additions & 4 deletions functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/


import { AsyncTransformFunction, BooleanRef, CollapsedValue, CollapsedValueAdvanced, Decorators, INSERT_MARK, METADATA, MaybeObjectRef, MinimalJSRef, Pointer, Ref, RefLike, RefOrValue, Runtime, SmartTransformFunction, SmartTransformOptions, TransformFunction, TransformFunctionInputs, handleDecoratorArgs, logger, primitive } from "./datex_all.ts";
import { AsyncTransformFunction, CollapsedValue, CollapsedValueAdvanced, Decorators, INSERT_MARK, METADATA, MaybeObjectRef, MinimalJSRef, Pointer, Ref, RefLike, RefOrValue, Runtime, SmartTransformFunction, SmartTransformOptions, TransformFunction, TransformFunctionInputs, handleDecoratorArgs, logger, primitive } from "./datex_all.ts";
import { Datex } from "./mod.ts";
import { PointerError } from "./types/errors.ts";
import { IterableHandler } from "./utils/iterable-handler.ts";
Expand Down Expand Up @@ -333,7 +333,7 @@ export function selectProperty<K extends string|number, V>(property:RefLike<K>,
* @param value
* @returns
*/
export function not(value:RefOrValue<boolean>): BooleanRef {
export function not(value:RefOrValue<boolean>): Pointer<boolean> {
return transform([value], v=>!v);
}

Expand All @@ -342,7 +342,7 @@ export function not(value:RefOrValue<boolean>): BooleanRef {
* @param values
* @returns
*/
export function and(...values:RefOrValue<boolean>[]): BooleanRef {
export function and(...values:RefOrValue<boolean>[]): Pointer<boolean> {
return transform(values, (...values)=>{
for (const v of values) {
if (!v) return false;
Expand All @@ -356,7 +356,7 @@ export function and(...values:RefOrValue<boolean>[]): BooleanRef {
* @param values
* @returns
*/
export function or(...values:RefOrValue<boolean>[]): BooleanRef {
export function or(...values:RefOrValue<boolean>[]): Pointer<boolean> {
return transform(values, (...values)=>{
for (const v of values) {
if (v) return true;
Expand Down
4 changes: 2 additions & 2 deletions runtime/lazy-pointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class LazyPointer<T> {
Pointer.onPointerForIdAdded(this.id, p => callback(Pointer.collapseValue(p) as MinimalJSRef<T>, p))
}

static withVal(val:any, callback:(val:MinimalJSRef<unknown>)=>void) {
static withVal<T>(val:MinimalJSRef<T>, callback:(val:MinimalJSRef<T>)=>void) {
if (val instanceof LazyPointer) val.onLoad(callback);
else callback(val, val);
else callback(val);
}
}
Loading

0 comments on commit 911d75d

Please sign in to comment.