macroforge 0.1.40 → 0.1.41
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/index.d.ts +96 -0
- package/index.js +54 -52
- package/js/utils/effect.ts +43 -0
- package/js/utils/index.d.ts +67 -0
- package/js/utils/index.mjs +31 -1
- package/js/utils/index.ts +91 -0
- package/package.json +7 -7
package/index.d.ts
CHANGED
|
@@ -700,6 +700,26 @@ export declare function __macroforgeRunSerialize(contextJson: string): string
|
|
|
700
700
|
*/
|
|
701
701
|
export declare function checkSyntax(code: string, filepath: string): SyntaxCheckResult
|
|
702
702
|
|
|
703
|
+
/**
|
|
704
|
+
* Clears the configuration cache.
|
|
705
|
+
*
|
|
706
|
+
* This is useful for testing to ensure each test starts with a clean state.
|
|
707
|
+
* In production, clearing the cache will force configs to be re-parsed on next access.
|
|
708
|
+
*
|
|
709
|
+
* # Example
|
|
710
|
+
*
|
|
711
|
+
* ```javascript
|
|
712
|
+
* const { clearConfigCache, loadConfig } = require('macroforge-ts');
|
|
713
|
+
*
|
|
714
|
+
* // Clear cache before each test
|
|
715
|
+
* clearConfigCache();
|
|
716
|
+
*
|
|
717
|
+
* // Now load a fresh config
|
|
718
|
+
* const result = loadConfig(configContent, configPath);
|
|
719
|
+
* ```
|
|
720
|
+
*/
|
|
721
|
+
export declare function clearConfigCache(): void
|
|
722
|
+
|
|
703
723
|
/**
|
|
704
724
|
* Entry for a registered decorator in the manifest.
|
|
705
725
|
*
|
|
@@ -769,6 +789,24 @@ export interface ExpandOptions {
|
|
|
769
789
|
* ```
|
|
770
790
|
*/
|
|
771
791
|
externalDecoratorModules?: Array<string>
|
|
792
|
+
/**
|
|
793
|
+
* Path to a previously loaded config file.
|
|
794
|
+
*
|
|
795
|
+
* When provided, the expansion will use the cached configuration
|
|
796
|
+
* (including foreign types) from this path. The config must have been
|
|
797
|
+
* previously loaded via [`load_config`].
|
|
798
|
+
*
|
|
799
|
+
* # Example
|
|
800
|
+
*
|
|
801
|
+
* ```javascript
|
|
802
|
+
* // First, load the config
|
|
803
|
+
* const configResult = loadConfig(configContent, configPath);
|
|
804
|
+
*
|
|
805
|
+
* // Then use it during expansion
|
|
806
|
+
* expandSync(code, filepath, { configPath });
|
|
807
|
+
* ```
|
|
808
|
+
*/
|
|
809
|
+
configPath?: string
|
|
772
810
|
}
|
|
773
811
|
|
|
774
812
|
/**
|
|
@@ -901,6 +939,59 @@ export interface JsDiagnostic {
|
|
|
901
939
|
category?: string
|
|
902
940
|
}
|
|
903
941
|
|
|
942
|
+
/**
|
|
943
|
+
* Load and parse a macroforge configuration file.
|
|
944
|
+
*
|
|
945
|
+
* Parses a `macroforge.config.js/ts` file and caches the result for use
|
|
946
|
+
* during macro expansion. The configuration includes both simple settings
|
|
947
|
+
* (like `keepDecorators`) and foreign type handlers.
|
|
948
|
+
*
|
|
949
|
+
* # Arguments
|
|
950
|
+
*
|
|
951
|
+
* * `content` - The raw content of the configuration file
|
|
952
|
+
* * `filepath` - Path to the configuration file (used to determine syntax and as cache key)
|
|
953
|
+
*
|
|
954
|
+
* # Returns
|
|
955
|
+
*
|
|
956
|
+
* A [`LoadConfigResult`] containing the parsed configuration summary.
|
|
957
|
+
*
|
|
958
|
+
* # Example
|
|
959
|
+
*
|
|
960
|
+
* ```javascript
|
|
961
|
+
* import { loadConfig, expandSync } from 'macroforge';
|
|
962
|
+
* import fs from 'fs';
|
|
963
|
+
*
|
|
964
|
+
* const configPath = 'macroforge.config.js';
|
|
965
|
+
* const configContent = fs.readFileSync(configPath, 'utf-8');
|
|
966
|
+
*
|
|
967
|
+
* // Load and cache the configuration
|
|
968
|
+
* const result = loadConfig(configContent, configPath);
|
|
969
|
+
* console.log(`Loaded config with ${result.foreignTypeCount} foreign types`);
|
|
970
|
+
*
|
|
971
|
+
* // The config is now cached and will be used by expandSync
|
|
972
|
+
* const expanded = expandSync(code, filepath, { configPath });
|
|
973
|
+
* ```
|
|
974
|
+
*/
|
|
975
|
+
export declare function loadConfig(content: string, filepath: string): LoadConfigResult
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Result of loading a macroforge configuration file.
|
|
979
|
+
*
|
|
980
|
+
* Returned by [`load_config`] after parsing a `macroforge.config.js/ts` file.
|
|
981
|
+
*/
|
|
982
|
+
export interface LoadConfigResult {
|
|
983
|
+
/** Whether to preserve `@derive` decorators in the output code. */
|
|
984
|
+
keepDecorators: boolean
|
|
985
|
+
/** Whether to generate a convenience const for non-class types. */
|
|
986
|
+
generateConvenienceConst: boolean
|
|
987
|
+
/** Whether the config has any foreign type handlers defined. */
|
|
988
|
+
hasForeignTypes: boolean
|
|
989
|
+
/** Number of foreign types configured. */
|
|
990
|
+
foreignTypeCount: number
|
|
991
|
+
/** Return types mode: "vanilla", "custom", or "effect". */
|
|
992
|
+
returnTypes: string
|
|
993
|
+
}
|
|
994
|
+
|
|
904
995
|
/**
|
|
905
996
|
* A diagnostic message produced during macro expansion.
|
|
906
997
|
*
|
|
@@ -1060,6 +1151,11 @@ export interface ProcessFileOptions {
|
|
|
1060
1151
|
* See [`ExpandOptions::external_decorator_modules`] for details.
|
|
1061
1152
|
*/
|
|
1062
1153
|
externalDecoratorModules?: Array<string>
|
|
1154
|
+
/**
|
|
1155
|
+
* Path to a previously loaded config file (for foreign types lookup).
|
|
1156
|
+
* See [`ExpandOptions::config_path`] for details.
|
|
1157
|
+
*/
|
|
1158
|
+
configPath?: string
|
|
1063
1159
|
}
|
|
1064
1160
|
|
|
1065
1161
|
/**
|
package/index.js
CHANGED
|
@@ -77,8 +77,8 @@ function requireNative() {
|
|
|
77
77
|
try {
|
|
78
78
|
const binding = require('@macroforge/bin-android-arm64')
|
|
79
79
|
const bindingPackageVersion = require('@macroforge/bin-android-arm64/package.json').version
|
|
80
|
-
if (bindingPackageVersion !== '0.1.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
80
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
81
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
82
82
|
}
|
|
83
83
|
return binding
|
|
84
84
|
} catch (e) {
|
|
@@ -93,8 +93,8 @@ function requireNative() {
|
|
|
93
93
|
try {
|
|
94
94
|
const binding = require('@macroforge/bin-android-arm-eabi')
|
|
95
95
|
const bindingPackageVersion = require('@macroforge/bin-android-arm-eabi/package.json').version
|
|
96
|
-
if (bindingPackageVersion !== '0.1.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
96
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
97
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
98
98
|
}
|
|
99
99
|
return binding
|
|
100
100
|
} catch (e) {
|
|
@@ -114,8 +114,8 @@ function requireNative() {
|
|
|
114
114
|
try {
|
|
115
115
|
const binding = require('@macroforge/bin-win32-x64-gnu')
|
|
116
116
|
const bindingPackageVersion = require('@macroforge/bin-win32-x64-gnu/package.json').version
|
|
117
|
-
if (bindingPackageVersion !== '0.1.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
117
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
118
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
119
119
|
}
|
|
120
120
|
return binding
|
|
121
121
|
} catch (e) {
|
|
@@ -130,8 +130,8 @@ function requireNative() {
|
|
|
130
130
|
try {
|
|
131
131
|
const binding = require('@macroforge/bin-win32-x64-msvc')
|
|
132
132
|
const bindingPackageVersion = require('@macroforge/bin-win32-x64-msvc/package.json').version
|
|
133
|
-
if (bindingPackageVersion !== '0.1.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
133
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
134
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
135
135
|
}
|
|
136
136
|
return binding
|
|
137
137
|
} catch (e) {
|
|
@@ -147,8 +147,8 @@ function requireNative() {
|
|
|
147
147
|
try {
|
|
148
148
|
const binding = require('@macroforge/bin-win32-ia32-msvc')
|
|
149
149
|
const bindingPackageVersion = require('@macroforge/bin-win32-ia32-msvc/package.json').version
|
|
150
|
-
if (bindingPackageVersion !== '0.1.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
150
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
151
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
152
152
|
}
|
|
153
153
|
return binding
|
|
154
154
|
} catch (e) {
|
|
@@ -163,8 +163,8 @@ function requireNative() {
|
|
|
163
163
|
try {
|
|
164
164
|
const binding = require('@macroforge/bin-win32-arm64-msvc')
|
|
165
165
|
const bindingPackageVersion = require('@macroforge/bin-win32-arm64-msvc/package.json').version
|
|
166
|
-
if (bindingPackageVersion !== '0.1.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
166
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
167
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
168
168
|
}
|
|
169
169
|
return binding
|
|
170
170
|
} catch (e) {
|
|
@@ -182,8 +182,8 @@ function requireNative() {
|
|
|
182
182
|
try {
|
|
183
183
|
const binding = require('@macroforge/bin-darwin-universal')
|
|
184
184
|
const bindingPackageVersion = require('@macroforge/bin-darwin-universal/package.json').version
|
|
185
|
-
if (bindingPackageVersion !== '0.1.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
185
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
186
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
187
187
|
}
|
|
188
188
|
return binding
|
|
189
189
|
} catch (e) {
|
|
@@ -198,8 +198,8 @@ function requireNative() {
|
|
|
198
198
|
try {
|
|
199
199
|
const binding = require('@macroforge/bin-darwin-x64')
|
|
200
200
|
const bindingPackageVersion = require('@macroforge/bin-darwin-x64/package.json').version
|
|
201
|
-
if (bindingPackageVersion !== '0.1.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
201
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
202
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
203
203
|
}
|
|
204
204
|
return binding
|
|
205
205
|
} catch (e) {
|
|
@@ -214,8 +214,8 @@ function requireNative() {
|
|
|
214
214
|
try {
|
|
215
215
|
const binding = require('@macroforge/bin-darwin-arm64')
|
|
216
216
|
const bindingPackageVersion = require('@macroforge/bin-darwin-arm64/package.json').version
|
|
217
|
-
if (bindingPackageVersion !== '0.1.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
217
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
218
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
219
219
|
}
|
|
220
220
|
return binding
|
|
221
221
|
} catch (e) {
|
|
@@ -234,8 +234,8 @@ function requireNative() {
|
|
|
234
234
|
try {
|
|
235
235
|
const binding = require('@macroforge/bin-freebsd-x64')
|
|
236
236
|
const bindingPackageVersion = require('@macroforge/bin-freebsd-x64/package.json').version
|
|
237
|
-
if (bindingPackageVersion !== '0.1.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
237
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
238
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
239
239
|
}
|
|
240
240
|
return binding
|
|
241
241
|
} catch (e) {
|
|
@@ -250,8 +250,8 @@ function requireNative() {
|
|
|
250
250
|
try {
|
|
251
251
|
const binding = require('@macroforge/bin-freebsd-arm64')
|
|
252
252
|
const bindingPackageVersion = require('@macroforge/bin-freebsd-arm64/package.json').version
|
|
253
|
-
if (bindingPackageVersion !== '0.1.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
253
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
254
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
255
255
|
}
|
|
256
256
|
return binding
|
|
257
257
|
} catch (e) {
|
|
@@ -271,8 +271,8 @@ function requireNative() {
|
|
|
271
271
|
try {
|
|
272
272
|
const binding = require('@macroforge/bin-linux-x64-musl')
|
|
273
273
|
const bindingPackageVersion = require('@macroforge/bin-linux-x64-musl/package.json').version
|
|
274
|
-
if (bindingPackageVersion !== '0.1.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
274
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
275
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
276
276
|
}
|
|
277
277
|
return binding
|
|
278
278
|
} catch (e) {
|
|
@@ -287,8 +287,8 @@ function requireNative() {
|
|
|
287
287
|
try {
|
|
288
288
|
const binding = require('@macroforge/bin-linux-x64-gnu')
|
|
289
289
|
const bindingPackageVersion = require('@macroforge/bin-linux-x64-gnu/package.json').version
|
|
290
|
-
if (bindingPackageVersion !== '0.1.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
290
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
291
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
292
292
|
}
|
|
293
293
|
return binding
|
|
294
294
|
} catch (e) {
|
|
@@ -305,8 +305,8 @@ function requireNative() {
|
|
|
305
305
|
try {
|
|
306
306
|
const binding = require('@macroforge/bin-linux-arm64-musl')
|
|
307
307
|
const bindingPackageVersion = require('@macroforge/bin-linux-arm64-musl/package.json').version
|
|
308
|
-
if (bindingPackageVersion !== '0.1.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
308
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
309
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
310
310
|
}
|
|
311
311
|
return binding
|
|
312
312
|
} catch (e) {
|
|
@@ -321,8 +321,8 @@ function requireNative() {
|
|
|
321
321
|
try {
|
|
322
322
|
const binding = require('@macroforge/bin-linux-arm64-gnu')
|
|
323
323
|
const bindingPackageVersion = require('@macroforge/bin-linux-arm64-gnu/package.json').version
|
|
324
|
-
if (bindingPackageVersion !== '0.1.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
324
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
325
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
326
326
|
}
|
|
327
327
|
return binding
|
|
328
328
|
} catch (e) {
|
|
@@ -339,8 +339,8 @@ function requireNative() {
|
|
|
339
339
|
try {
|
|
340
340
|
const binding = require('@macroforge/bin-linux-arm-musleabihf')
|
|
341
341
|
const bindingPackageVersion = require('@macroforge/bin-linux-arm-musleabihf/package.json').version
|
|
342
|
-
if (bindingPackageVersion !== '0.1.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
342
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
343
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
344
344
|
}
|
|
345
345
|
return binding
|
|
346
346
|
} catch (e) {
|
|
@@ -355,8 +355,8 @@ function requireNative() {
|
|
|
355
355
|
try {
|
|
356
356
|
const binding = require('@macroforge/bin-linux-arm-gnueabihf')
|
|
357
357
|
const bindingPackageVersion = require('@macroforge/bin-linux-arm-gnueabihf/package.json').version
|
|
358
|
-
if (bindingPackageVersion !== '0.1.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
358
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
359
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
360
360
|
}
|
|
361
361
|
return binding
|
|
362
362
|
} catch (e) {
|
|
@@ -373,8 +373,8 @@ function requireNative() {
|
|
|
373
373
|
try {
|
|
374
374
|
const binding = require('@macroforge/bin-linux-loong64-musl')
|
|
375
375
|
const bindingPackageVersion = require('@macroforge/bin-linux-loong64-musl/package.json').version
|
|
376
|
-
if (bindingPackageVersion !== '0.1.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
376
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
377
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
378
378
|
}
|
|
379
379
|
return binding
|
|
380
380
|
} catch (e) {
|
|
@@ -389,8 +389,8 @@ function requireNative() {
|
|
|
389
389
|
try {
|
|
390
390
|
const binding = require('@macroforge/bin-linux-loong64-gnu')
|
|
391
391
|
const bindingPackageVersion = require('@macroforge/bin-linux-loong64-gnu/package.json').version
|
|
392
|
-
if (bindingPackageVersion !== '0.1.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
392
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
393
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
394
394
|
}
|
|
395
395
|
return binding
|
|
396
396
|
} catch (e) {
|
|
@@ -407,8 +407,8 @@ function requireNative() {
|
|
|
407
407
|
try {
|
|
408
408
|
const binding = require('@macroforge/bin-linux-riscv64-musl')
|
|
409
409
|
const bindingPackageVersion = require('@macroforge/bin-linux-riscv64-musl/package.json').version
|
|
410
|
-
if (bindingPackageVersion !== '0.1.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
410
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
411
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
412
412
|
}
|
|
413
413
|
return binding
|
|
414
414
|
} catch (e) {
|
|
@@ -423,8 +423,8 @@ function requireNative() {
|
|
|
423
423
|
try {
|
|
424
424
|
const binding = require('@macroforge/bin-linux-riscv64-gnu')
|
|
425
425
|
const bindingPackageVersion = require('@macroforge/bin-linux-riscv64-gnu/package.json').version
|
|
426
|
-
if (bindingPackageVersion !== '0.1.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
426
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
427
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
428
428
|
}
|
|
429
429
|
return binding
|
|
430
430
|
} catch (e) {
|
|
@@ -440,8 +440,8 @@ function requireNative() {
|
|
|
440
440
|
try {
|
|
441
441
|
const binding = require('@macroforge/bin-linux-ppc64-gnu')
|
|
442
442
|
const bindingPackageVersion = require('@macroforge/bin-linux-ppc64-gnu/package.json').version
|
|
443
|
-
if (bindingPackageVersion !== '0.1.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
443
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
444
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
445
445
|
}
|
|
446
446
|
return binding
|
|
447
447
|
} catch (e) {
|
|
@@ -456,8 +456,8 @@ function requireNative() {
|
|
|
456
456
|
try {
|
|
457
457
|
const binding = require('@macroforge/bin-linux-s390x-gnu')
|
|
458
458
|
const bindingPackageVersion = require('@macroforge/bin-linux-s390x-gnu/package.json').version
|
|
459
|
-
if (bindingPackageVersion !== '0.1.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
459
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
460
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
461
461
|
}
|
|
462
462
|
return binding
|
|
463
463
|
} catch (e) {
|
|
@@ -476,8 +476,8 @@ function requireNative() {
|
|
|
476
476
|
try {
|
|
477
477
|
const binding = require('@macroforge/bin-openharmony-arm64')
|
|
478
478
|
const bindingPackageVersion = require('@macroforge/bin-openharmony-arm64/package.json').version
|
|
479
|
-
if (bindingPackageVersion !== '0.1.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
479
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
480
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
481
481
|
}
|
|
482
482
|
return binding
|
|
483
483
|
} catch (e) {
|
|
@@ -492,8 +492,8 @@ function requireNative() {
|
|
|
492
492
|
try {
|
|
493
493
|
const binding = require('@macroforge/bin-openharmony-x64')
|
|
494
494
|
const bindingPackageVersion = require('@macroforge/bin-openharmony-x64/package.json').version
|
|
495
|
-
if (bindingPackageVersion !== '0.1.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
495
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
496
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
497
497
|
}
|
|
498
498
|
return binding
|
|
499
499
|
} catch (e) {
|
|
@@ -508,8 +508,8 @@ function requireNative() {
|
|
|
508
508
|
try {
|
|
509
509
|
const binding = require('@macroforge/bin-openharmony-arm')
|
|
510
510
|
const bindingPackageVersion = require('@macroforge/bin-openharmony-arm/package.json').version
|
|
511
|
-
if (bindingPackageVersion !== '0.1.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 0.1.
|
|
511
|
+
if (bindingPackageVersion !== '0.1.41' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
512
|
+
throw new Error(`Native binding package version mismatch, expected 0.1.41 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
513
513
|
}
|
|
514
514
|
return binding
|
|
515
515
|
} catch (e) {
|
|
@@ -592,7 +592,9 @@ module.exports.__macroforgeRunPartialEq = nativeBinding.__macroforgeRunPartialEq
|
|
|
592
592
|
module.exports.__macroforgeRunPartialOrd = nativeBinding.__macroforgeRunPartialOrd
|
|
593
593
|
module.exports.__macroforgeRunSerialize = nativeBinding.__macroforgeRunSerialize
|
|
594
594
|
module.exports.checkSyntax = nativeBinding.checkSyntax
|
|
595
|
+
module.exports.clearConfigCache = nativeBinding.clearConfigCache
|
|
595
596
|
module.exports.Derive = nativeBinding.Derive
|
|
596
597
|
module.exports.expandSync = nativeBinding.expandSync
|
|
598
|
+
module.exports.loadConfig = nativeBinding.loadConfig
|
|
597
599
|
module.exports.parseImportSources = nativeBinding.parseImportSources
|
|
598
600
|
module.exports.transformSync = nativeBinding.transformSync
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* # Macroforge Effect Utils Module
|
|
3
|
+
*
|
|
4
|
+
* This module re-exports Effect library types for use in generated macro code
|
|
5
|
+
* when `returnTypes: 'effect'` is configured.
|
|
6
|
+
*
|
|
7
|
+
* ## Exit<E, A>
|
|
8
|
+
*
|
|
9
|
+
* Represents the result of a computation that may fail.
|
|
10
|
+
* Used by the `Deserialize` macro for validation errors.
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { Exit } from "macroforge/utils/effect";
|
|
14
|
+
*
|
|
15
|
+
* const result = User.fromStringifiedJSON(json);
|
|
16
|
+
* if (Exit.isSuccess(result)) {
|
|
17
|
+
* const user = result.value;
|
|
18
|
+
* } else {
|
|
19
|
+
* console.error(result.cause); // Array of field errors
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* ## Option<A>
|
|
24
|
+
*
|
|
25
|
+
* Represents an optional value.
|
|
26
|
+
* Used by `PartialOrd` macro for incomparable values.
|
|
27
|
+
*
|
|
28
|
+
* ```typescript
|
|
29
|
+
* import { Option } from "macroforge/utils/effect";
|
|
30
|
+
*
|
|
31
|
+
* const cmp = user1.compareTo(user2);
|
|
32
|
+
* if (Option.isSome(cmp)) {
|
|
33
|
+
* console.log(cmp.value); // -1, 0, or 1
|
|
34
|
+
* } else {
|
|
35
|
+
* console.log("Values are incomparable");
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @module macroforge/utils/effect
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
// Re-export Exit and Option from effect for use in generated code
|
|
43
|
+
export { Exit, Option } from "effect";
|
package/js/utils/index.d.ts
CHANGED
|
@@ -40,6 +40,73 @@
|
|
|
40
40
|
* @module macroforge/utils
|
|
41
41
|
*/
|
|
42
42
|
export { Result, Option } from "@rydshift/mirror/declarative";
|
|
43
|
+
/**
|
|
44
|
+
* Represents a successful deserialization result.
|
|
45
|
+
* Used when `returnTypes: 'vanilla'` is configured.
|
|
46
|
+
*/
|
|
47
|
+
export interface DeserializeSuccess<T> {
|
|
48
|
+
readonly success: true;
|
|
49
|
+
readonly value: T;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Represents a failed deserialization result with field errors.
|
|
53
|
+
* Used when `returnTypes: 'vanilla'` is configured.
|
|
54
|
+
*/
|
|
55
|
+
export interface DeserializeFailure {
|
|
56
|
+
readonly success: false;
|
|
57
|
+
readonly errors: Array<{
|
|
58
|
+
field: string;
|
|
59
|
+
message: string;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A simple discriminated union for deserialization results.
|
|
64
|
+
* Used when `returnTypes: 'vanilla'` is configured.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const result = userDeserialize(json);
|
|
69
|
+
* if (result.success) {
|
|
70
|
+
* const user = result.value;
|
|
71
|
+
* } else {
|
|
72
|
+
* console.error(result.errors);
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export type DeserializeResult<T> = DeserializeSuccess<T> | DeserializeFailure;
|
|
77
|
+
/**
|
|
78
|
+
* Namespace with helper functions for working with vanilla DeserializeResult.
|
|
79
|
+
* These mirror the Result API for familiarity.
|
|
80
|
+
*/
|
|
81
|
+
export declare namespace DeserializeResult {
|
|
82
|
+
/**
|
|
83
|
+
* Creates a successful result.
|
|
84
|
+
*/
|
|
85
|
+
function ok<T>(value: T): DeserializeResult<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a failed result with errors.
|
|
88
|
+
*/
|
|
89
|
+
function err<T>(errors: Array<{
|
|
90
|
+
field: string;
|
|
91
|
+
message: string;
|
|
92
|
+
}>): DeserializeResult<T>;
|
|
93
|
+
/**
|
|
94
|
+
* Type guard to check if the result is successful.
|
|
95
|
+
*/
|
|
96
|
+
function isOk<T>(result: DeserializeResult<T>): result is DeserializeSuccess<T>;
|
|
97
|
+
/**
|
|
98
|
+
* Type guard to check if the result is a failure.
|
|
99
|
+
*/
|
|
100
|
+
function isErr<T>(result: DeserializeResult<T>): result is DeserializeFailure;
|
|
101
|
+
/**
|
|
102
|
+
* Unwraps the value or throws an error.
|
|
103
|
+
*/
|
|
104
|
+
function unwrap<T>(result: DeserializeResult<T>): T;
|
|
105
|
+
/**
|
|
106
|
+
* Unwraps the value or returns a default.
|
|
107
|
+
*/
|
|
108
|
+
function unwrapOr<T>(result: DeserializeResult<T>, defaultValue: T): T;
|
|
109
|
+
}
|
|
43
110
|
/**
|
|
44
111
|
*
|
|
45
112
|
*
|
package/js/utils/index.mjs
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
// js/utils/index.ts
|
|
2
2
|
import { Result, Option } from "@rydshift/mirror/declarative";
|
|
3
|
+
var DeserializeResult;
|
|
4
|
+
((DeserializeResult) => {
|
|
5
|
+
function ok(value) {
|
|
6
|
+
return { success: true, value };
|
|
7
|
+
}
|
|
8
|
+
DeserializeResult.ok = ok;
|
|
9
|
+
function err(errors) {
|
|
10
|
+
return { success: false, errors };
|
|
11
|
+
}
|
|
12
|
+
DeserializeResult.err = err;
|
|
13
|
+
function isOk(result) {
|
|
14
|
+
return result.success;
|
|
15
|
+
}
|
|
16
|
+
DeserializeResult.isOk = isOk;
|
|
17
|
+
function isErr(result) {
|
|
18
|
+
return !result.success;
|
|
19
|
+
}
|
|
20
|
+
DeserializeResult.isErr = isErr;
|
|
21
|
+
function unwrap(result) {
|
|
22
|
+
if (result.success)
|
|
23
|
+
return result.value;
|
|
24
|
+
throw new Error(`Deserialization failed: ${JSON.stringify(result.errors)}`);
|
|
25
|
+
}
|
|
26
|
+
DeserializeResult.unwrap = unwrap;
|
|
27
|
+
function unwrapOr(result, defaultValue) {
|
|
28
|
+
return result.success ? result.value : defaultValue;
|
|
29
|
+
}
|
|
30
|
+
DeserializeResult.unwrapOr = unwrapOr;
|
|
31
|
+
})(DeserializeResult ||= {});
|
|
3
32
|
export {
|
|
4
33
|
Result,
|
|
5
|
-
Option
|
|
34
|
+
Option,
|
|
35
|
+
DeserializeResult
|
|
6
36
|
};
|
package/js/utils/index.ts
CHANGED
|
@@ -43,6 +43,97 @@
|
|
|
43
43
|
// Re-export Result and Option from @rydshift/mirror for use in generated code
|
|
44
44
|
export { Result, Option } from "@rydshift/mirror/declarative";
|
|
45
45
|
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Vanilla Return Types
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// These types are used when `returnTypes: 'vanilla'` is configured.
|
|
50
|
+
// They provide simple discriminated unions without requiring external dependencies.
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Represents a successful deserialization result.
|
|
54
|
+
* Used when `returnTypes: 'vanilla'` is configured.
|
|
55
|
+
*/
|
|
56
|
+
export interface DeserializeSuccess<T> {
|
|
57
|
+
readonly success: true;
|
|
58
|
+
readonly value: T;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Represents a failed deserialization result with field errors.
|
|
63
|
+
* Used when `returnTypes: 'vanilla'` is configured.
|
|
64
|
+
*/
|
|
65
|
+
export interface DeserializeFailure {
|
|
66
|
+
readonly success: false;
|
|
67
|
+
readonly errors: Array<{ field: string; message: string }>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A simple discriminated union for deserialization results.
|
|
72
|
+
* Used when `returnTypes: 'vanilla'` is configured.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const result = userDeserialize(json);
|
|
77
|
+
* if (result.success) {
|
|
78
|
+
* const user = result.value;
|
|
79
|
+
* } else {
|
|
80
|
+
* console.error(result.errors);
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export type DeserializeResult<T> = DeserializeSuccess<T> | DeserializeFailure;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Namespace with helper functions for working with vanilla DeserializeResult.
|
|
88
|
+
* These mirror the Result API for familiarity.
|
|
89
|
+
*/
|
|
90
|
+
export namespace DeserializeResult {
|
|
91
|
+
/**
|
|
92
|
+
* Creates a successful result.
|
|
93
|
+
*/
|
|
94
|
+
export function ok<T>(value: T): DeserializeResult<T> {
|
|
95
|
+
return { success: true, value };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Creates a failed result with errors.
|
|
100
|
+
*/
|
|
101
|
+
export function err<T>(errors: Array<{ field: string; message: string }>): DeserializeResult<T> {
|
|
102
|
+
return { success: false, errors };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Type guard to check if the result is successful.
|
|
107
|
+
*/
|
|
108
|
+
export function isOk<T>(result: DeserializeResult<T>): result is DeserializeSuccess<T> {
|
|
109
|
+
return result.success;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Type guard to check if the result is a failure.
|
|
114
|
+
*/
|
|
115
|
+
export function isErr<T>(result: DeserializeResult<T>): result is DeserializeFailure {
|
|
116
|
+
return !result.success;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Unwraps the value or throws an error.
|
|
121
|
+
*/
|
|
122
|
+
export function unwrap<T>(result: DeserializeResult<T>): T {
|
|
123
|
+
if (result.success) return result.value;
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Deserialization failed: ${JSON.stringify((result as DeserializeFailure).errors)}`,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Unwraps the value or returns a default.
|
|
131
|
+
*/
|
|
132
|
+
export function unwrapOr<T>(result: DeserializeResult<T>, defaultValue: T): T {
|
|
133
|
+
return result.success ? result.value : defaultValue;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
46
137
|
/**
|
|
47
138
|
*
|
|
48
139
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "macroforge",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "TypeScript macro expansion engine powered by Rust and SWC",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -67,12 +67,12 @@
|
|
|
67
67
|
"node": ">= 18"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
|
-
"@macroforge/bin-darwin-x64": "0.1.
|
|
71
|
-
"@macroforge/bin-darwin-arm64": "0.1.
|
|
72
|
-
"@macroforge/bin-linux-x64-gnu": "0.1.
|
|
73
|
-
"@macroforge/bin-linux-arm64-gnu": "0.1.
|
|
74
|
-
"@macroforge/bin-win32-x64-msvc": "0.1.
|
|
75
|
-
"@macroforge/bin-win32-arm64-msvc": "0.1.
|
|
70
|
+
"@macroforge/bin-darwin-x64": "0.1.41",
|
|
71
|
+
"@macroforge/bin-darwin-arm64": "0.1.41",
|
|
72
|
+
"@macroforge/bin-linux-x64-gnu": "0.1.41",
|
|
73
|
+
"@macroforge/bin-linux-arm64-gnu": "0.1.41",
|
|
74
|
+
"@macroforge/bin-win32-x64-msvc": "0.1.41",
|
|
75
|
+
"@macroforge/bin-win32-arm64-msvc": "0.1.41"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"build:serde": "bun build js/serde/index.ts --outfile js/serde/index.mjs && bun x tsc js/serde/index.ts --declaration --emitDeclarationOnly --outDir js/serde --lib ES2024 --skipLibCheck",
|