tjs-lang 0.6.26 → 0.6.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/docs.json +1 -1
- package/dist/bin/benchmarks.d.ts +9 -0
- package/dist/bin/dev.d.ts +1 -0
- package/dist/bin/docs.d.ts +1 -0
- package/dist/bin/select-local-models.d.ts +1 -0
- package/dist/examples/modules/dist/main.d.ts +34 -0
- package/dist/examples/modules/dist/math.d.ts +120 -0
- package/dist/index.js +423 -0
- package/dist/index.js.map +45 -0
- package/dist/scripts/build-demo.d.ts +2 -0
- package/dist/scripts/build.d.ts +11 -0
- package/dist/scripts/seed-blog-rules.d.ts +2 -0
- package/dist/scripts/seed-stored-function.d.ts +2 -0
- package/dist/src/atoms/batteries.d.ts +4 -0
- package/dist/src/atoms/browser.d.ts +4 -0
- package/dist/src/atoms/index.d.ts +4 -0
- package/dist/src/batteries/audit.d.ts +9 -0
- package/dist/src/batteries/index.d.ts +28 -0
- package/dist/src/batteries/llm.d.ts +18 -0
- package/dist/src/batteries/models.d.ts +19 -0
- package/dist/src/batteries/store.d.ts +13 -0
- package/dist/src/builder.d.ts +127 -0
- package/dist/src/bun-plugin/tjs-plugin.d.ts +12 -0
- package/dist/src/cli/commands/check.d.ts +4 -0
- package/dist/src/cli/commands/convert.d.ts +20 -0
- package/dist/src/cli/commands/emit.d.ts +34 -0
- package/dist/src/cli/commands/run.d.ts +6 -0
- package/dist/src/cli/commands/test.d.ts +21 -0
- package/dist/src/cli/commands/types.d.ts +4 -0
- package/dist/src/cli/create-app.d.ts +9 -0
- package/dist/src/cli/playground.d.ts +9 -0
- package/dist/src/cli/tjs.d.ts +15 -0
- package/dist/src/cli/tjsx.d.ts +16 -0
- package/dist/src/index.d.ts +11 -0
- package/dist/src/inference.types.d.ts +1 -0
- package/dist/src/lang/core.d.ts +56 -0
- package/dist/src/lang/docs.d.ts +69 -0
- package/dist/src/lang/emitters/ast.d.ts +24 -0
- package/dist/src/lang/emitters/dts.d.ts +48 -0
- package/dist/src/lang/emitters/from-ts.d.ts +94 -0
- package/dist/src/lang/emitters/js-tests.d.ts +70 -0
- package/dist/src/lang/emitters/js-wasm.d.ts +15 -0
- package/dist/src/lang/emitters/js.d.ts +175 -0
- package/dist/src/lang/eval.d.ts +63 -0
- package/dist/src/lang/index.d.ts +216 -0
- package/dist/src/lang/inference.d.ts +40 -0
- package/dist/src/lang/linter.d.ts +53 -0
- package/dist/src/lang/metadata-cache.d.ts +172 -0
- package/dist/src/lang/parser-params.d.ts +37 -0
- package/dist/src/lang/parser-transforms.d.ts +281 -0
- package/dist/src/lang/parser-types.d.ts +175 -0
- package/dist/src/lang/parser.d.ts +56 -0
- package/dist/src/lang/runtime.d.ts +488 -0
- package/dist/src/lang/schema.d.ts +35 -0
- package/dist/src/lang/tests.d.ts +94 -0
- package/dist/src/lang/transpiler.d.ts +25 -0
- package/dist/src/lang/types.d.ts +147 -0
- package/dist/src/lang/wasm.d.ts +83 -0
- package/dist/src/rbac/index.d.ts +85 -0
- package/dist/src/rbac/rules.d.ts +184 -0
- package/dist/src/runtime.d.ts +4 -0
- package/dist/src/store/index.d.ts +3 -0
- package/dist/src/store/indexeddb.d.ts +6 -0
- package/dist/src/store/interface.d.ts +90 -0
- package/dist/src/store/memory.d.ts +10 -0
- package/dist/src/test-examples.d.ts +41 -0
- package/dist/src/test-utils.d.ts +86 -0
- package/dist/src/transpiler/index.d.ts +6 -0
- package/dist/src/transpiler/parser.d.ts +4 -0
- package/dist/src/transpiler/transformer.d.ts +4 -0
- package/dist/src/transpiler/type-system/inference.d.ts +1 -0
- package/dist/src/transpiler/types.d.ts +4 -0
- package/dist/src/types/LegalDate.d.ts +241 -0
- package/dist/src/types/Timestamp.d.ts +233 -0
- package/dist/src/types/Type.d.ts +234 -0
- package/dist/src/types/index.d.ts +8 -0
- package/dist/src/vm/atoms/batteries.d.ts +6 -0
- package/dist/src/vm/atoms/browser.d.ts +18 -0
- package/dist/src/vm/atoms/index.d.ts +10 -0
- package/dist/src/vm/index.d.ts +12 -0
- package/dist/src/vm/runtime.d.ts +333 -0
- package/dist/src/vm/vm.d.ts +28 -0
- package/dist/src/vm.d.ts +4 -0
- package/dist/test-preprocess.d.ts +1 -0
- package/dist/tjs-batteries.js +4 -0
- package/dist/tjs-batteries.js.map +15 -0
- package/dist/tjs-full.js +423 -0
- package/dist/tjs-full.js.map +45 -0
- package/dist/tjs-src/runtime.d.ts +1 -0
- package/dist/tjs-transpiler.js +3 -0
- package/dist/tjs-transpiler.js.map +11 -0
- package/dist/tjs-vm.js +54 -0
- package/dist/tjs-vm.js.map +22 -0
- package/package.json +1 -1
- package/src/cli/tjs.ts +1 -1
- package/src/lang/emitters/js.ts +3 -0
- package/src/lang/parser-transforms.ts +6 -0
- package/src/lang/roundtrip.test.ts +1 -1
- package/src/lang/runtime.ts +18 -1
- package/src/lang/wasm.ts +1 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the Agent99 JavaScript transpiler
|
|
3
|
+
*/
|
|
4
|
+
import type { Node } from 'acorn';
|
|
5
|
+
import type { SeqNode } from '../builder';
|
|
6
|
+
/** Represents a type extracted from value patterns */
|
|
7
|
+
export interface TypeDescriptor {
|
|
8
|
+
kind: 'string' | 'number' | 'integer' | 'non-negative-integer' | 'boolean' | 'null' | 'undefined' | 'array' | 'object' | 'union' | 'any';
|
|
9
|
+
nullable?: boolean;
|
|
10
|
+
/** For arrays: the element type */
|
|
11
|
+
items?: TypeDescriptor;
|
|
12
|
+
/** For objects: the shape */
|
|
13
|
+
shape?: Record<string, TypeDescriptor>;
|
|
14
|
+
/** For unions: the member types */
|
|
15
|
+
members?: TypeDescriptor[];
|
|
16
|
+
/** For destructured parameters: full parameter descriptors */
|
|
17
|
+
destructuredParams?: Record<string, ParameterDescriptor>;
|
|
18
|
+
}
|
|
19
|
+
/** Describes a function parameter */
|
|
20
|
+
export interface ParameterDescriptor {
|
|
21
|
+
name: string;
|
|
22
|
+
type: TypeDescriptor;
|
|
23
|
+
required: boolean;
|
|
24
|
+
default?: any;
|
|
25
|
+
/** The example value used to infer the type (for autocomplete) */
|
|
26
|
+
example?: any;
|
|
27
|
+
description?: string;
|
|
28
|
+
/** Source location for error reporting */
|
|
29
|
+
loc?: {
|
|
30
|
+
start: number;
|
|
31
|
+
end: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Describes a function's complete signature */
|
|
35
|
+
export interface FunctionSignature {
|
|
36
|
+
name: string;
|
|
37
|
+
description?: string;
|
|
38
|
+
parameters: Record<string, ParameterDescriptor>;
|
|
39
|
+
returns?: TypeDescriptor;
|
|
40
|
+
}
|
|
41
|
+
/** Options for the transpile function */
|
|
42
|
+
export interface TranspileOptions {
|
|
43
|
+
/** Include source locations in output AST */
|
|
44
|
+
sourceMaps?: boolean;
|
|
45
|
+
/** Atom registry for validation (optional) */
|
|
46
|
+
atoms?: Record<string, {
|
|
47
|
+
op: string;
|
|
48
|
+
}>;
|
|
49
|
+
/** Filename for error messages */
|
|
50
|
+
filename?: string;
|
|
51
|
+
/** Whether to use strict type checking */
|
|
52
|
+
strict?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Result of transpilation */
|
|
55
|
+
export interface TranspileResult {
|
|
56
|
+
/** The Agent99 AST */
|
|
57
|
+
ast: SeqNode;
|
|
58
|
+
/** The function signature with types */
|
|
59
|
+
signature: FunctionSignature;
|
|
60
|
+
/** Source map (if enabled) */
|
|
61
|
+
sourceMap?: SourceMap;
|
|
62
|
+
/** Warnings (non-fatal issues) */
|
|
63
|
+
warnings: TranspileWarning[];
|
|
64
|
+
}
|
|
65
|
+
/** A non-fatal warning during transpilation */
|
|
66
|
+
export interface TranspileWarning {
|
|
67
|
+
message: string;
|
|
68
|
+
line: number;
|
|
69
|
+
column: number;
|
|
70
|
+
source?: string;
|
|
71
|
+
}
|
|
72
|
+
/** Source map for debugging */
|
|
73
|
+
export interface SourceMap {
|
|
74
|
+
version: 3;
|
|
75
|
+
file: string;
|
|
76
|
+
sources: string[];
|
|
77
|
+
mappings: string;
|
|
78
|
+
}
|
|
79
|
+
/** Base class for transpiler errors with source location */
|
|
80
|
+
export declare class TranspileError extends Error {
|
|
81
|
+
line: number;
|
|
82
|
+
column: number;
|
|
83
|
+
source?: string;
|
|
84
|
+
filename?: string;
|
|
85
|
+
constructor(message: string, location: {
|
|
86
|
+
line: number;
|
|
87
|
+
column: number;
|
|
88
|
+
}, source?: string, filename?: string);
|
|
89
|
+
}
|
|
90
|
+
/** Syntax error during parsing */
|
|
91
|
+
export declare class SyntaxError extends TranspileError {
|
|
92
|
+
constructor(message: string, location: {
|
|
93
|
+
line: number;
|
|
94
|
+
column: number;
|
|
95
|
+
}, source?: string, filename?: string);
|
|
96
|
+
/**
|
|
97
|
+
* Format the error with source context for better debugging
|
|
98
|
+
* Shows the problematic line with a caret pointing to the error location
|
|
99
|
+
*/
|
|
100
|
+
formatWithContext(contextLines?: number): string;
|
|
101
|
+
}
|
|
102
|
+
/** Type error during transpilation or runtime */
|
|
103
|
+
export declare class TypeError extends TranspileError {
|
|
104
|
+
expected?: string;
|
|
105
|
+
received?: string;
|
|
106
|
+
suggestion?: string;
|
|
107
|
+
constructor(message: string, location: {
|
|
108
|
+
line: number;
|
|
109
|
+
column: number;
|
|
110
|
+
}, options?: {
|
|
111
|
+
expected?: string;
|
|
112
|
+
received?: string;
|
|
113
|
+
suggestion?: string;
|
|
114
|
+
source?: string;
|
|
115
|
+
filename?: string;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Context passed through the transformer */
|
|
119
|
+
export interface TransformContext {
|
|
120
|
+
/** Current scope depth */
|
|
121
|
+
depth: number;
|
|
122
|
+
/** Variables declared in current scope with their types */
|
|
123
|
+
locals: Map<string, TypeDescriptor>;
|
|
124
|
+
/** Parent scope's context (for scope chain) */
|
|
125
|
+
parent?: TransformContext;
|
|
126
|
+
/** Function parameters */
|
|
127
|
+
parameters: Map<string, ParameterDescriptor>;
|
|
128
|
+
/** Registered atom names */
|
|
129
|
+
atoms: Set<string>;
|
|
130
|
+
/** Accumulated warnings */
|
|
131
|
+
warnings: TranspileWarning[];
|
|
132
|
+
/** Source code for error messages */
|
|
133
|
+
source: string;
|
|
134
|
+
/** Filename */
|
|
135
|
+
filename: string;
|
|
136
|
+
/** Options */
|
|
137
|
+
options: TranspileOptions;
|
|
138
|
+
}
|
|
139
|
+
/** Create a child context for nested scopes */
|
|
140
|
+
export declare function createChildContext(parent: TransformContext): TransformContext;
|
|
141
|
+
/** Look up a variable in the scope chain */
|
|
142
|
+
export declare function lookupVariable(name: string, ctx: TransformContext): TypeDescriptor | undefined;
|
|
143
|
+
/** Extract location from an Acorn node */
|
|
144
|
+
export declare function getLocation(node: Node): {
|
|
145
|
+
line: number;
|
|
146
|
+
column: number;
|
|
147
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TJS to WebAssembly Compiler
|
|
3
|
+
*
|
|
4
|
+
* Compiles a subset of TJS to WebAssembly for performance-critical code.
|
|
5
|
+
*
|
|
6
|
+
* Supported features:
|
|
7
|
+
* - Numeric operations (+, -, *, /, %)
|
|
8
|
+
* - Typed arrays (Float32Array, Float64Array, Int32Array, Uint8Array)
|
|
9
|
+
* - For loops with numeric bounds
|
|
10
|
+
* - Math functions (sin, cos, sqrt, abs, floor, ceil, min, max)
|
|
11
|
+
* - Basic conditionals (if/else)
|
|
12
|
+
* - Variable declarations (let)
|
|
13
|
+
*
|
|
14
|
+
* The goal is to enable real-world WASM acceleration for hot paths like
|
|
15
|
+
* audio processing, image manipulation, and physics simulations.
|
|
16
|
+
*/
|
|
17
|
+
import type { WasmBlock } from './parser';
|
|
18
|
+
/** Compile result */
|
|
19
|
+
export interface WasmCompileResult {
|
|
20
|
+
/** The compiled WebAssembly module bytes */
|
|
21
|
+
bytes: Uint8Array;
|
|
22
|
+
/** Any warnings during compilation */
|
|
23
|
+
warnings: string[];
|
|
24
|
+
/** Whether compilation succeeded */
|
|
25
|
+
success: boolean;
|
|
26
|
+
/** Error message if compilation failed */
|
|
27
|
+
error?: string;
|
|
28
|
+
/** Whether the module needs imported memory */
|
|
29
|
+
needsMemory?: boolean;
|
|
30
|
+
/** WAT text representation (for debugging) */
|
|
31
|
+
wat?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Compile a WASM block to WebAssembly
|
|
35
|
+
*/
|
|
36
|
+
export declare function compileToWasm(block: WasmBlock): WasmCompileResult;
|
|
37
|
+
/**
|
|
38
|
+
* Instantiate a compiled WASM module
|
|
39
|
+
*/
|
|
40
|
+
export declare function instantiateWasm(bytes: Uint8Array, memory?: WebAssembly.Memory): Promise<WebAssembly.Instance>;
|
|
41
|
+
/**
|
|
42
|
+
* Create a callable function from a WASM block with typed array support
|
|
43
|
+
*/
|
|
44
|
+
export declare function createWasmFunction(block: WasmBlock): Promise<{
|
|
45
|
+
fn: (...args: any[]) => any;
|
|
46
|
+
memory?: WebAssembly.Memory;
|
|
47
|
+
success: boolean;
|
|
48
|
+
error?: string;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Compile and register a WASM block globally
|
|
52
|
+
*/
|
|
53
|
+
export declare function registerWasmBlock(block: WasmBlock): Promise<boolean>;
|
|
54
|
+
/**
|
|
55
|
+
* Compile all WASM blocks from a preprocessed source
|
|
56
|
+
*/
|
|
57
|
+
export declare function compileWasmBlocks(blocks: WasmBlock[]): Promise<{
|
|
58
|
+
compiled: number;
|
|
59
|
+
failed: number;
|
|
60
|
+
errors: string[];
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Compiled WASM data that can be serialized and passed to an iframe
|
|
64
|
+
*/
|
|
65
|
+
export interface CompiledWasmData {
|
|
66
|
+
id: string;
|
|
67
|
+
bytes: number[];
|
|
68
|
+
captures: string[];
|
|
69
|
+
needsMemory: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Compile WASM blocks and return serializable data for iframe instantiation
|
|
73
|
+
*/
|
|
74
|
+
export declare function compileWasmBlocksForIframe(blocks: WasmBlock[]): Promise<{
|
|
75
|
+
compiled: CompiledWasmData[];
|
|
76
|
+
failed: number;
|
|
77
|
+
errors: string[];
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Generate JavaScript code that instantiates compiled WASM in an iframe
|
|
81
|
+
* This code should be injected into the iframe's script
|
|
82
|
+
*/
|
|
83
|
+
export declare function generateWasmInstantiationCode(compiledBlocks: CompiledWasmData[]): string;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Store } from '../store/interface';
|
|
2
|
+
export { evaluateAccessShortcut, selectAccessRule, validateSchema, interpretRuleResult, hasRoleLevel, buildRuleContext, } from './rules.js';
|
|
3
|
+
/**
|
|
4
|
+
* Security rule definition
|
|
5
|
+
*/
|
|
6
|
+
export interface SecurityRule {
|
|
7
|
+
/** Rule for read operations */
|
|
8
|
+
read?: string | {
|
|
9
|
+
code: string;
|
|
10
|
+
fuel?: number;
|
|
11
|
+
};
|
|
12
|
+
/** Rule for write operations (fallback for create/update) */
|
|
13
|
+
write?: string | {
|
|
14
|
+
code: string;
|
|
15
|
+
fuel?: number;
|
|
16
|
+
};
|
|
17
|
+
/** Rule for create operations */
|
|
18
|
+
create?: string | {
|
|
19
|
+
code: string;
|
|
20
|
+
fuel?: number;
|
|
21
|
+
};
|
|
22
|
+
/** Rule for update operations */
|
|
23
|
+
update?: string | {
|
|
24
|
+
code: string;
|
|
25
|
+
fuel?: number;
|
|
26
|
+
};
|
|
27
|
+
/** Rule for delete operations */
|
|
28
|
+
delete?: string | {
|
|
29
|
+
code: string;
|
|
30
|
+
fuel?: number;
|
|
31
|
+
};
|
|
32
|
+
/** Legacy: single code rule for all operations */
|
|
33
|
+
code?: string;
|
|
34
|
+
/** Schema validation for writes */
|
|
35
|
+
schema?: {
|
|
36
|
+
required?: string[];
|
|
37
|
+
properties?: Record<string, {
|
|
38
|
+
type: string;
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
41
|
+
/** Max fuel for AJS evaluation */
|
|
42
|
+
fuel?: number;
|
|
43
|
+
/** Timeout for AJS evaluation */
|
|
44
|
+
timeoutMs?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Access check options
|
|
48
|
+
*/
|
|
49
|
+
export interface CheckOptions {
|
|
50
|
+
uid?: string | null;
|
|
51
|
+
roles?: string[];
|
|
52
|
+
method: 'read' | 'write' | 'delete';
|
|
53
|
+
collection: string;
|
|
54
|
+
docId?: string | null;
|
|
55
|
+
doc?: Record<string, any> | null;
|
|
56
|
+
newData?: Record<string, any> | null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Access check result
|
|
60
|
+
*/
|
|
61
|
+
export interface CheckResult {
|
|
62
|
+
allowed: boolean;
|
|
63
|
+
reason?: string;
|
|
64
|
+
ruleType: 'shortcut' | 'schema' | 'code' | 'default' | 'error';
|
|
65
|
+
evalTimeMs: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* RBAC instance with store backend
|
|
69
|
+
*/
|
|
70
|
+
export interface RBAC {
|
|
71
|
+
/** Check if an operation is allowed */
|
|
72
|
+
check(options: CheckOptions): Promise<CheckResult>;
|
|
73
|
+
/** Set a security rule for a collection */
|
|
74
|
+
setRule(collection: string, rule: SecurityRule): Promise<void>;
|
|
75
|
+
/** Get the security rule for a collection */
|
|
76
|
+
getRule(collection: string): Promise<SecurityRule | null>;
|
|
77
|
+
/** Delete a security rule */
|
|
78
|
+
deleteRule(collection: string): Promise<void>;
|
|
79
|
+
/** Load user roles from store */
|
|
80
|
+
loadUserRoles(uid: string): Promise<string[]>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create an RBAC instance with a store backend
|
|
84
|
+
*/
|
|
85
|
+
export declare function createRBAC(store: Store): RBAC;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
export function evaluateAccessShortcut(accessRule: any, context: any): {
|
|
2
|
+
allowed: boolean;
|
|
3
|
+
reason: string;
|
|
4
|
+
} | {
|
|
5
|
+
allowed: boolean;
|
|
6
|
+
reason?: undefined;
|
|
7
|
+
} | null;
|
|
8
|
+
export namespace evaluateAccessShortcut {
|
|
9
|
+
namespace __tjs {
|
|
10
|
+
namespace params {
|
|
11
|
+
namespace accessRule {
|
|
12
|
+
namespace type {
|
|
13
|
+
let kind: string;
|
|
14
|
+
}
|
|
15
|
+
let required: boolean;
|
|
16
|
+
}
|
|
17
|
+
namespace context {
|
|
18
|
+
export namespace type_1 {
|
|
19
|
+
let kind_1: string;
|
|
20
|
+
export { kind_1 as kind };
|
|
21
|
+
}
|
|
22
|
+
export { type_1 as type };
|
|
23
|
+
let required_1: boolean;
|
|
24
|
+
export { required_1 as required };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let unsafe: boolean;
|
|
28
|
+
let source: string;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function selectAccessRule(rule: any, context: any): any;
|
|
32
|
+
export namespace selectAccessRule {
|
|
33
|
+
export namespace __tjs_1 {
|
|
34
|
+
export namespace params_1 {
|
|
35
|
+
export namespace rule {
|
|
36
|
+
export namespace type_2 {
|
|
37
|
+
let kind_2: string;
|
|
38
|
+
export { kind_2 as kind };
|
|
39
|
+
}
|
|
40
|
+
export { type_2 as type };
|
|
41
|
+
let required_2: boolean;
|
|
42
|
+
export { required_2 as required };
|
|
43
|
+
}
|
|
44
|
+
export namespace context_1 {
|
|
45
|
+
export namespace type_3 {
|
|
46
|
+
let kind_3: string;
|
|
47
|
+
export { kind_3 as kind };
|
|
48
|
+
}
|
|
49
|
+
export { type_3 as type };
|
|
50
|
+
let required_3: boolean;
|
|
51
|
+
export { required_3 as required };
|
|
52
|
+
}
|
|
53
|
+
export { context_1 as context };
|
|
54
|
+
}
|
|
55
|
+
export { params_1 as params };
|
|
56
|
+
let unsafe_1: boolean;
|
|
57
|
+
export { unsafe_1 as unsafe };
|
|
58
|
+
let source_1: string;
|
|
59
|
+
export { source_1 as source };
|
|
60
|
+
}
|
|
61
|
+
export { __tjs_1 as __tjs };
|
|
62
|
+
}
|
|
63
|
+
export function validateSchema(schema: any, data: any): {
|
|
64
|
+
valid: boolean;
|
|
65
|
+
errors: string[];
|
|
66
|
+
};
|
|
67
|
+
export namespace validateSchema {
|
|
68
|
+
export namespace __tjs_2 {
|
|
69
|
+
export namespace params_2 {
|
|
70
|
+
namespace schema {
|
|
71
|
+
export namespace type_4 {
|
|
72
|
+
let kind_4: string;
|
|
73
|
+
export { kind_4 as kind };
|
|
74
|
+
}
|
|
75
|
+
export { type_4 as type };
|
|
76
|
+
let required_4: boolean;
|
|
77
|
+
export { required_4 as required };
|
|
78
|
+
}
|
|
79
|
+
namespace data {
|
|
80
|
+
export namespace type_5 {
|
|
81
|
+
let kind_5: string;
|
|
82
|
+
export { kind_5 as kind };
|
|
83
|
+
}
|
|
84
|
+
export { type_5 as type };
|
|
85
|
+
let required_5: boolean;
|
|
86
|
+
export { required_5 as required };
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export { params_2 as params };
|
|
90
|
+
let unsafe_2: boolean;
|
|
91
|
+
export { unsafe_2 as unsafe };
|
|
92
|
+
let source_2: string;
|
|
93
|
+
export { source_2 as source };
|
|
94
|
+
}
|
|
95
|
+
export { __tjs_2 as __tjs };
|
|
96
|
+
}
|
|
97
|
+
export function interpretRuleResult(result: any): {
|
|
98
|
+
allowed: boolean;
|
|
99
|
+
reason: any;
|
|
100
|
+
};
|
|
101
|
+
export namespace interpretRuleResult {
|
|
102
|
+
export namespace __tjs_3 {
|
|
103
|
+
export namespace params_3 {
|
|
104
|
+
namespace result {
|
|
105
|
+
export namespace type_6 {
|
|
106
|
+
let kind_6: string;
|
|
107
|
+
export { kind_6 as kind };
|
|
108
|
+
}
|
|
109
|
+
export { type_6 as type };
|
|
110
|
+
let required_6: boolean;
|
|
111
|
+
export { required_6 as required };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export { params_3 as params };
|
|
115
|
+
let unsafe_3: boolean;
|
|
116
|
+
export { unsafe_3 as unsafe };
|
|
117
|
+
let source_3: string;
|
|
118
|
+
export { source_3 as source };
|
|
119
|
+
}
|
|
120
|
+
export { __tjs_3 as __tjs };
|
|
121
|
+
}
|
|
122
|
+
export function hasRoleLevel(userRoles: any, requiredRole: any): boolean;
|
|
123
|
+
export namespace hasRoleLevel {
|
|
124
|
+
export namespace __tjs_4 {
|
|
125
|
+
export namespace params_4 {
|
|
126
|
+
namespace userRoles {
|
|
127
|
+
export namespace type_7 {
|
|
128
|
+
let kind_7: string;
|
|
129
|
+
export { kind_7 as kind };
|
|
130
|
+
}
|
|
131
|
+
export { type_7 as type };
|
|
132
|
+
let required_7: boolean;
|
|
133
|
+
export { required_7 as required };
|
|
134
|
+
}
|
|
135
|
+
namespace requiredRole {
|
|
136
|
+
export namespace type_8 {
|
|
137
|
+
let kind_8: string;
|
|
138
|
+
export { kind_8 as kind };
|
|
139
|
+
}
|
|
140
|
+
export { type_8 as type };
|
|
141
|
+
let required_8: boolean;
|
|
142
|
+
export { required_8 as required };
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export { params_4 as params };
|
|
146
|
+
let unsafe_4: boolean;
|
|
147
|
+
export { unsafe_4 as unsafe };
|
|
148
|
+
let source_4: string;
|
|
149
|
+
export { source_4 as source };
|
|
150
|
+
}
|
|
151
|
+
export { __tjs_4 as __tjs };
|
|
152
|
+
}
|
|
153
|
+
export function buildRuleContext(options: any): {
|
|
154
|
+
_uid: any;
|
|
155
|
+
_roles: any;
|
|
156
|
+
_isAdmin: any;
|
|
157
|
+
_isAuthor: any;
|
|
158
|
+
_method: any;
|
|
159
|
+
_collection: any;
|
|
160
|
+
_docId: any;
|
|
161
|
+
doc: any;
|
|
162
|
+
newData: any;
|
|
163
|
+
};
|
|
164
|
+
export namespace buildRuleContext {
|
|
165
|
+
export namespace __tjs_5 {
|
|
166
|
+
export namespace params_5 {
|
|
167
|
+
namespace options {
|
|
168
|
+
export namespace type_9 {
|
|
169
|
+
let kind_9: string;
|
|
170
|
+
export { kind_9 as kind };
|
|
171
|
+
}
|
|
172
|
+
export { type_9 as type };
|
|
173
|
+
let required_9: boolean;
|
|
174
|
+
export { required_9 as required };
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
export { params_5 as params };
|
|
178
|
+
let unsafe_5: boolean;
|
|
179
|
+
export { unsafe_5 as unsafe };
|
|
180
|
+
let source_5: string;
|
|
181
|
+
export { source_5 as source };
|
|
182
|
+
}
|
|
183
|
+
export { __tjs_5 as __tjs };
|
|
184
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where clause for queries
|
|
3
|
+
*/
|
|
4
|
+
export interface WhereClause {
|
|
5
|
+
field: string;
|
|
6
|
+
op: '==' | '!=' | '<' | '<=' | '>' | '>=' | 'in' | 'not-in' | 'array-contains';
|
|
7
|
+
value: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Query constraints
|
|
11
|
+
*/
|
|
12
|
+
export interface QueryConstraints {
|
|
13
|
+
where?: WhereClause[];
|
|
14
|
+
orderBy?: string;
|
|
15
|
+
orderDirection?: 'asc' | 'desc';
|
|
16
|
+
limit?: number;
|
|
17
|
+
offset?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Document with ID
|
|
21
|
+
*/
|
|
22
|
+
export interface Doc<T = Record<string, any>> {
|
|
23
|
+
id: string;
|
|
24
|
+
data: T;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result of a write operation
|
|
28
|
+
*/
|
|
29
|
+
export interface WriteResult {
|
|
30
|
+
success: boolean;
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Abstract store interface
|
|
35
|
+
*
|
|
36
|
+
* All methods are async to support both sync (IndexedDB) and
|
|
37
|
+
* async (Firestore, Postgres) backends.
|
|
38
|
+
*/
|
|
39
|
+
export interface Store {
|
|
40
|
+
/**
|
|
41
|
+
* Get a document by ID
|
|
42
|
+
* Returns null if not found
|
|
43
|
+
*/
|
|
44
|
+
get(collection: string, id: string): Promise<Record<string, any> | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Set a document (create or update)
|
|
47
|
+
* If merge is true, only updates provided fields
|
|
48
|
+
*/
|
|
49
|
+
set(collection: string, id: string, data: Record<string, any>, options?: {
|
|
50
|
+
merge?: boolean;
|
|
51
|
+
}): Promise<WriteResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Delete a document
|
|
54
|
+
*/
|
|
55
|
+
delete(collection: string, id: string): Promise<WriteResult>;
|
|
56
|
+
/**
|
|
57
|
+
* Query documents in a collection
|
|
58
|
+
*/
|
|
59
|
+
query(collection: string, constraints?: QueryConstraints): Promise<Doc[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Check if a document exists
|
|
62
|
+
*/
|
|
63
|
+
exists(collection: string, id: string): Promise<boolean>;
|
|
64
|
+
/**
|
|
65
|
+
* Generate a unique ID for a new document
|
|
66
|
+
*/
|
|
67
|
+
generateId(collection: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Batch write operations (atomic)
|
|
70
|
+
* Optional - not all backends support transactions
|
|
71
|
+
*/
|
|
72
|
+
batch?(operations: Array<{
|
|
73
|
+
type: 'set';
|
|
74
|
+
collection: string;
|
|
75
|
+
id: string;
|
|
76
|
+
data: Record<string, any>;
|
|
77
|
+
} | {
|
|
78
|
+
type: 'delete';
|
|
79
|
+
collection: string;
|
|
80
|
+
id: string;
|
|
81
|
+
}>): Promise<WriteResult>;
|
|
82
|
+
/**
|
|
83
|
+
* Clear all data (for testing)
|
|
84
|
+
*/
|
|
85
|
+
clear?(): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Factory function type for creating stores
|
|
89
|
+
*/
|
|
90
|
+
export type StoreFactory = () => Store | Promise<Store>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Store } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* Create an in-memory store
|
|
4
|
+
*/
|
|
5
|
+
export declare function createMemoryStore(): Store;
|
|
6
|
+
export declare function getMemoryStore(): Store;
|
|
7
|
+
/**
|
|
8
|
+
* Reset the default store (for tests)
|
|
9
|
+
*/
|
|
10
|
+
export declare function resetMemoryStore(): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for loading and testing playground example markdown files.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* import { loadExample, loadExamples } from './test-examples'
|
|
6
|
+
*
|
|
7
|
+
* const ex = loadExample('guides/examples/tjs/wasm-starfield.md')
|
|
8
|
+
* // ex.code — the source code from the first code block
|
|
9
|
+
* // ex.language — 'tjs', 'ajs', 'javascript', etc.
|
|
10
|
+
* // ex.title — from the markdown # heading
|
|
11
|
+
* // ex.metadata — parsed JSON from <!--{...}--> comment
|
|
12
|
+
*
|
|
13
|
+
* const all = loadExamples('guides/examples/tjs')
|
|
14
|
+
* // array of all examples in that directory
|
|
15
|
+
*/
|
|
16
|
+
export interface ExampleFile {
|
|
17
|
+
/** Absolute or relative path to the source .md file */
|
|
18
|
+
path: string;
|
|
19
|
+
/** Title from the first # heading */
|
|
20
|
+
title: string;
|
|
21
|
+
/** Description — first paragraph between title and code block */
|
|
22
|
+
description: string;
|
|
23
|
+
/** Source code from the first fenced code block */
|
|
24
|
+
code: string;
|
|
25
|
+
/** Language tag from the code fence (e.g. 'tjs', 'ajs', 'javascript') */
|
|
26
|
+
language: string;
|
|
27
|
+
/** Parsed metadata from the <!--{...}--> comment, if present */
|
|
28
|
+
metadata: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Load a single example from a markdown file.
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadExample(filePath: string): ExampleFile;
|
|
34
|
+
/**
|
|
35
|
+
* Load all .md examples from a directory.
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadExamples(dirPath: string): ExampleFile[];
|
|
38
|
+
/**
|
|
39
|
+
* Parse example content from markdown source.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseExample(content: string, filePath?: string): ExampleFile;
|