@tsonic/js 0.1.2
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/LICENSE +21 -0
- package/README.md +102 -0
- package/__build/scripts/generate.sh +116 -0
- package/families.json +1 -0
- package/index/bindings.json +12273 -0
- package/index/internal/index.d.ts +735 -0
- package/index/internal/metadata.json +7741 -0
- package/index.d.ts +58 -0
- package/index.js +9 -0
- package/package.json +25 -0
- package/tsconfig.json +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 tsoniclang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# @tsonic/js
|
|
2
|
+
|
|
3
|
+
TypeScript type definitions for the JavaScript Runtime (JSRuntime) library.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **JavaScript-like APIs for .NET** - Array, Map, Set, Date, Math, JSON, and more
|
|
8
|
+
- **Global functions** - `parseInt`, `parseFloat`, `encodeURI`, etc. as top-level exports
|
|
9
|
+
- **camelCase members** - TypeScript-friendly naming conventions
|
|
10
|
+
- **Primitive aliases** - `int`, `long`, etc. via `@tsonic/core`
|
|
11
|
+
- **Full type safety** - Complete TypeScript declarations
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @tsonic/js @tsonic/dotnet @tsonic/core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Global Functions
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { parseInt, parseFloat, isNaN, encodeURIComponent } from "@tsonic/js";
|
|
25
|
+
|
|
26
|
+
const num = parseInt("42", 10);
|
|
27
|
+
const float = parseFloat("3.14");
|
|
28
|
+
const encoded = encodeURIComponent("hello world");
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Array Operations
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { JSArray } from "@tsonic/js";
|
|
35
|
+
|
|
36
|
+
const arr = new JSArray<number>();
|
|
37
|
+
arr.push(1, 2, 3);
|
|
38
|
+
const mapped = arr.map(x => x * 2);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Map and Set
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { Map, Set } from "@tsonic/js";
|
|
45
|
+
|
|
46
|
+
const map = new Map<string, number>();
|
|
47
|
+
map.set_("key", 42);
|
|
48
|
+
|
|
49
|
+
const set = new Set<string>();
|
|
50
|
+
set.add("value");
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Date and Math
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { Date, Math } from "@tsonic/js";
|
|
57
|
+
|
|
58
|
+
const now = new Date();
|
|
59
|
+
const random = Math.random();
|
|
60
|
+
const max = Math.max(1, 2, 3);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### JSON
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { JSON } from "@tsonic/js";
|
|
67
|
+
|
|
68
|
+
const obj = JSON.parse('{"key": "value"}');
|
|
69
|
+
const str = JSON.stringify(obj);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Naming Conventions
|
|
73
|
+
|
|
74
|
+
- **Types**: PascalCase (matches .NET)
|
|
75
|
+
- **Members**: camelCase (TypeScript convention)
|
|
76
|
+
- **Global functions**: camelCase (JavaScript convention)
|
|
77
|
+
|
|
78
|
+
Some members use a `_` suffix when they would otherwise conflict with a TypeScript keyword
|
|
79
|
+
(for example: `Map.get_()` / `Map.set_()` / `Map.delete_()`).
|
|
80
|
+
|
|
81
|
+
## Development
|
|
82
|
+
|
|
83
|
+
### Regenerating Types
|
|
84
|
+
|
|
85
|
+
To regenerate TypeScript declarations:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
./__build/scripts/generate.sh
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Prerequisites:**
|
|
92
|
+
- .NET 10 SDK installed
|
|
93
|
+
- `tsbindgen` repository at `../tsbindgen`
|
|
94
|
+
- `js-runtime` repository at `../js-runtime` (built with `dotnet build -c Release`)
|
|
95
|
+
|
|
96
|
+
**Environment variables:**
|
|
97
|
+
- `DOTNET_VERSION` - .NET runtime version (default: `10.0.0`)
|
|
98
|
+
- `DOTNET_HOME` - .NET installation directory (default: `$HOME/.dotnet`)
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
MIT
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Generate TypeScript declarations for @tsonic/js (JSRuntime library)
|
|
3
|
+
#
|
|
4
|
+
# This script regenerates all TypeScript type declarations from the
|
|
5
|
+
# Tsonic.JSRuntime.dll assembly using tsbindgen.
|
|
6
|
+
#
|
|
7
|
+
# Prerequisites:
|
|
8
|
+
# - .NET 10 SDK installed
|
|
9
|
+
# - tsbindgen repository cloned at ../tsbindgen (sibling directory)
|
|
10
|
+
# - js-runtime repository cloned at ../js-runtime (sibling directory)
|
|
11
|
+
#
|
|
12
|
+
# Usage:
|
|
13
|
+
# ./__build/scripts/generate.sh
|
|
14
|
+
|
|
15
|
+
set -e
|
|
16
|
+
|
|
17
|
+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
18
|
+
PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
19
|
+
TSBINDGEN_DIR="$PROJECT_DIR/../tsbindgen"
|
|
20
|
+
JS_RUNTIME_DIR="$PROJECT_DIR/../js-runtime"
|
|
21
|
+
DOTNET_LIB="$PROJECT_DIR/../dotnet"
|
|
22
|
+
CORE_LIB="$PROJECT_DIR/../core"
|
|
23
|
+
|
|
24
|
+
# .NET runtime path (needed for BCL type resolution)
|
|
25
|
+
DOTNET_VERSION="${DOTNET_VERSION:-10.0.0}"
|
|
26
|
+
DOTNET_HOME="${DOTNET_HOME:-$HOME/.dotnet}"
|
|
27
|
+
DOTNET_RUNTIME_PATH="$DOTNET_HOME/shared/Microsoft.NETCore.App/$DOTNET_VERSION"
|
|
28
|
+
|
|
29
|
+
# Tsonic.JSRuntime.dll path
|
|
30
|
+
JSRUNTIME_DLL="$JS_RUNTIME_DIR/artifacts/bin/Tsonic.JSRuntime/Release/net10.0/Tsonic.JSRuntime.dll"
|
|
31
|
+
|
|
32
|
+
echo "================================================================"
|
|
33
|
+
echo "Generating @tsonic/js TypeScript Declarations"
|
|
34
|
+
echo "================================================================"
|
|
35
|
+
echo ""
|
|
36
|
+
echo "Configuration:"
|
|
37
|
+
echo " JSRuntime.dll: $JSRUNTIME_DLL"
|
|
38
|
+
echo " .NET Runtime: $DOTNET_RUNTIME_PATH"
|
|
39
|
+
echo " BCL Library: $DOTNET_LIB (external reference)"
|
|
40
|
+
echo " tsbindgen: $TSBINDGEN_DIR"
|
|
41
|
+
echo " Output: $PROJECT_DIR"
|
|
42
|
+
echo " Naming: JS (camelCase)"
|
|
43
|
+
echo ""
|
|
44
|
+
|
|
45
|
+
# Verify prerequisites
|
|
46
|
+
if [ ! -f "$JSRUNTIME_DLL" ]; then
|
|
47
|
+
echo "ERROR: Tsonic.JSRuntime.dll not found at $JSRUNTIME_DLL"
|
|
48
|
+
echo "Build it first: cd ../js-runtime && dotnet build -c Release"
|
|
49
|
+
exit 1
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
if [ ! -d "$DOTNET_RUNTIME_PATH" ]; then
|
|
53
|
+
echo "ERROR: .NET runtime not found at $DOTNET_RUNTIME_PATH"
|
|
54
|
+
echo "Set DOTNET_HOME or DOTNET_VERSION environment variables"
|
|
55
|
+
exit 1
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
if [ ! -d "$TSBINDGEN_DIR" ]; then
|
|
59
|
+
echo "ERROR: tsbindgen not found at $TSBINDGEN_DIR"
|
|
60
|
+
echo "Clone it: git clone https://github.com/tsoniclang/tsbindgen ../tsbindgen"
|
|
61
|
+
exit 1
|
|
62
|
+
fi
|
|
63
|
+
|
|
64
|
+
if [ ! -d "$DOTNET_LIB" ]; then
|
|
65
|
+
echo "ERROR: @tsonic/dotnet not found at $DOTNET_LIB"
|
|
66
|
+
echo "Clone it: git clone https://github.com/tsoniclang/dotnet ../dotnet"
|
|
67
|
+
exit 1
|
|
68
|
+
fi
|
|
69
|
+
|
|
70
|
+
if [ ! -d "$CORE_LIB" ]; then
|
|
71
|
+
echo "ERROR: @tsonic/core not found at $CORE_LIB"
|
|
72
|
+
echo "Clone it: git clone https://github.com/tsoniclang/core ../core"
|
|
73
|
+
exit 1
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
# Clean output directory (keep config files)
|
|
77
|
+
echo "[1/3] Cleaning output directory..."
|
|
78
|
+
cd "$PROJECT_DIR"
|
|
79
|
+
|
|
80
|
+
# Remove all namespace directories (but keep config files, __build, node_modules, .git)
|
|
81
|
+
find . -maxdepth 1 -type d \
|
|
82
|
+
! -name '.' \
|
|
83
|
+
! -name '.git' \
|
|
84
|
+
! -name '.tests' \
|
|
85
|
+
! -name 'node_modules' \
|
|
86
|
+
! -name '__build' \
|
|
87
|
+
-exec rm -rf {} \; 2>/dev/null || true
|
|
88
|
+
|
|
89
|
+
# Remove generated files at root
|
|
90
|
+
rm -f *.d.ts *.js 2>/dev/null || true
|
|
91
|
+
|
|
92
|
+
echo " Done"
|
|
93
|
+
|
|
94
|
+
# Build tsbindgen
|
|
95
|
+
echo "[2/3] Building tsbindgen..."
|
|
96
|
+
cd "$TSBINDGEN_DIR"
|
|
97
|
+
dotnet build src/tsbindgen/tsbindgen.csproj -c Release --verbosity quiet
|
|
98
|
+
echo " Done"
|
|
99
|
+
|
|
100
|
+
# Generate types with JavaScript-style naming
|
|
101
|
+
# Uses --lib to reference BCL types from @tsonic/dotnet instead of regenerating them
|
|
102
|
+
# Uses --namespace-map to emit as index.d.ts/index.js for cleaner imports
|
|
103
|
+
# Uses --flatten-class to export Globals methods as top-level functions
|
|
104
|
+
echo "[3/3] Generating TypeScript declarations..."
|
|
105
|
+
dotnet run --project src/tsbindgen/tsbindgen.csproj --no-build -c Release -- \
|
|
106
|
+
generate -a "$JSRUNTIME_DLL" -d "$DOTNET_RUNTIME_PATH" -o "$PROJECT_DIR" \
|
|
107
|
+
--lib "$DOTNET_LIB" \
|
|
108
|
+
--lib "$CORE_LIB" \
|
|
109
|
+
--naming js \
|
|
110
|
+
--namespace-map "Tsonic.JSRuntime=index" \
|
|
111
|
+
--flatten-class "Tsonic.JSRuntime.Globals"
|
|
112
|
+
|
|
113
|
+
echo ""
|
|
114
|
+
echo "================================================================"
|
|
115
|
+
echo "Generation Complete"
|
|
116
|
+
echo "================================================================"
|
package/families.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|