functionalscript 0.3.14 → 0.4.0
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/package.json +2 -3
- package/types/bit_vec/module.f.js +6 -5
- package/com/cpp/module.f.d.ts +0 -10
- package/com/cpp/module.f.js +0 -106
- package/com/cpp/test.f.d.ts +0 -2
- package/com/cpp/test.f.js +0 -40
- package/com/cpp/testlib.f.d.ts +0 -2
- package/com/cpp/testlib.f.js +0 -5
- package/com/cs/module.f.d.ts +0 -12
- package/com/cs/module.f.js +0 -79
- package/com/cs/test.f.d.ts +0 -2
- package/com/cs/test.f.js +0 -43
- package/com/cs/testlib.f.d.ts +0 -2
- package/com/cs/testlib.f.js +0 -5
- package/com/rust/module.f.d.ts +0 -15
- package/com/rust/module.f.js +0 -164
- package/com/rust/test.f.d.ts +0 -2
- package/com/rust/test.f.js +0 -123
- package/com/rust/testlib.f.d.ts +0 -2
- package/com/rust/testlib.f.js +0 -5
- package/com/test/build.f.d.ts +0 -20
- package/com/test/build.f.js +0 -58
- package/com/types/module.f.d.ts +0 -28
- package/com/types/module.f.js +0 -7
- package/com/types/testlib.f.d.ts +0 -44
- package/com/types/testlib.f.js +0 -28
- package/commonjs/build/module.f.d.ts +0 -6
- package/commonjs/build/module.f.js +0 -66
- package/commonjs/build/test.f.d.ts +0 -2
- package/commonjs/build/test.f.js +0 -92
- package/commonjs/module/function/module.f.d.ts +0 -8
- package/commonjs/module/function/module.f.js +0 -4
- package/commonjs/module/module.f.d.ts +0 -18
- package/commonjs/module/module.f.js +0 -11
- package/commonjs/module.f.d.ts +0 -6
- package/commonjs/module.f.js +0 -1
- package/commonjs/package/dependencies/module.f.d.ts +0 -7
- package/commonjs/package/dependencies/module.f.js +0 -13
- package/commonjs/package/dependencies/test.f.d.ts +0 -2
- package/commonjs/package/dependencies/test.f.js +0 -15
- package/commonjs/package/module.f.d.ts +0 -17
- package/commonjs/package/module.f.js +0 -18
- package/commonjs/package/test.f.d.ts +0 -2
- package/commonjs/package/test.f.js +0 -27
- package/commonjs/path/module.f.d.ts +0 -24
- package/commonjs/path/module.f.js +0 -112
- package/commonjs/path/test.f.d.ts +0 -25
- package/commonjs/path/test.f.js +0 -221
package/com/rust/test.f.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import rust from "./testlib.f.js";
|
|
2
|
-
export default () => {
|
|
3
|
-
const e = '#![allow(non_snake_case)]\n' +
|
|
4
|
-
'#[repr(C)]\n' +
|
|
5
|
-
'pub struct Slice {\n' +
|
|
6
|
-
' pub Start: *const u8,\n' +
|
|
7
|
-
' pub Size: usize,\n' +
|
|
8
|
-
'}\n' +
|
|
9
|
-
'#[repr(C)]\n' +
|
|
10
|
-
'pub struct ManagedStruct {\n' +
|
|
11
|
-
' pub M: IMy::Ref,\n' +
|
|
12
|
-
'}\n' +
|
|
13
|
-
'pub mod IMy {\n' +
|
|
14
|
-
' pub type Object = nanocom::Object<Interface>;\n' +
|
|
15
|
-
' pub type Ref = nanocom::Ref<Interface>;\n' +
|
|
16
|
-
' pub type Vmt = nanocom::Vmt<Interface>;\n' +
|
|
17
|
-
' #[repr(C)]\n' +
|
|
18
|
-
' pub struct Interface {\n' +
|
|
19
|
-
' pub GetSlice: unsafe extern "system" fn(this: &Object) -> super::Slice,\n' +
|
|
20
|
-
' pub SetSlice: unsafe extern "system" fn(this: &Object, slice: super::Slice),\n' +
|
|
21
|
-
' pub GetUnsafe: unsafe extern "system" fn(this: &Object) -> *const bool,\n' +
|
|
22
|
-
' pub SetUnsafe: unsafe extern "system" fn(this: &Object, p: *const super::Slice, size: u32),\n' +
|
|
23
|
-
' pub Some: unsafe extern "system" fn(this: &Object, p: &super::IMy::Object) -> bool,\n' +
|
|
24
|
-
' pub GetIMy: unsafe extern "system" fn(this: &Object, a: u16, b: i16) -> super::IMy::Ref,\n' +
|
|
25
|
-
' pub SetManagedStruct: unsafe extern "system" fn(this: &Object, a: super::ManagedStruct),\n' +
|
|
26
|
-
' }\n' +
|
|
27
|
-
' impl nanocom::Interface for Interface {\n' +
|
|
28
|
-
' const GUID: nanocom::GUID = 0xC66FB270_2D80_49AD_BB6E_88C1F90B805D;\n' +
|
|
29
|
-
' }\n' +
|
|
30
|
-
' pub trait Ex {\n' +
|
|
31
|
-
' fn GetSlice(&self) -> super::Slice;\n' +
|
|
32
|
-
' fn SetSlice(&self, slice: super::Slice);\n' +
|
|
33
|
-
' fn GetUnsafe(&self) -> *const bool;\n' +
|
|
34
|
-
' fn SetUnsafe(&self, p: *const super::Slice, size: u32);\n' +
|
|
35
|
-
' fn Some(&self, p: &super::IMy::Object) -> bool;\n' +
|
|
36
|
-
' fn GetIMy(&self, a: u16, b: i16) -> super::IMy::Ref;\n' +
|
|
37
|
-
' fn SetManagedStruct(&self, a: super::ManagedStruct);\n' +
|
|
38
|
-
' }\n' +
|
|
39
|
-
' impl Ex for Object {\n' +
|
|
40
|
-
' fn GetSlice(&self) -> super::Slice {\n' +
|
|
41
|
-
' unsafe { (self.interface().GetSlice)(self) }\n' +
|
|
42
|
-
' }\n' +
|
|
43
|
-
' fn SetSlice(&self, slice: super::Slice) {\n' +
|
|
44
|
-
' unsafe { (self.interface().SetSlice)(self, slice) }\n' +
|
|
45
|
-
' }\n' +
|
|
46
|
-
' fn GetUnsafe(&self) -> *const bool {\n' +
|
|
47
|
-
' unsafe { (self.interface().GetUnsafe)(self) }\n' +
|
|
48
|
-
' }\n' +
|
|
49
|
-
' fn SetUnsafe(&self, p: *const super::Slice, size: u32) {\n' +
|
|
50
|
-
' unsafe { (self.interface().SetUnsafe)(self, p, size) }\n' +
|
|
51
|
-
' }\n' +
|
|
52
|
-
' fn Some(&self, p: &super::IMy::Object) -> bool {\n' +
|
|
53
|
-
' unsafe { (self.interface().Some)(self, p) }\n' +
|
|
54
|
-
' }\n' +
|
|
55
|
-
' fn GetIMy(&self, a: u16, b: i16) -> super::IMy::Ref {\n' +
|
|
56
|
-
' unsafe { (self.interface().GetIMy)(self, a, b) }\n' +
|
|
57
|
-
' }\n' +
|
|
58
|
-
' fn SetManagedStruct(&self, a: super::ManagedStruct) {\n' +
|
|
59
|
-
' unsafe { (self.interface().SetManagedStruct)(self, a) }\n' +
|
|
60
|
-
' }\n' +
|
|
61
|
-
' }\n' +
|
|
62
|
-
' pub trait ClassEx\n' +
|
|
63
|
-
' where\n' +
|
|
64
|
-
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
65
|
-
' nanocom::CObject<Self>: Ex,\n' +
|
|
66
|
-
' {\n' +
|
|
67
|
-
' const VMT: Vmt = Vmt {\n' +
|
|
68
|
-
' iunknown: nanocom::CObject::<Self>::IUNKNOWN,\n' +
|
|
69
|
-
' interface: Interface {\n' +
|
|
70
|
-
' GetSlice: Self::GetSlice,\n' +
|
|
71
|
-
' SetSlice: Self::SetSlice,\n' +
|
|
72
|
-
' GetUnsafe: Self::GetUnsafe,\n' +
|
|
73
|
-
' SetUnsafe: Self::SetUnsafe,\n' +
|
|
74
|
-
' Some: Self::Some,\n' +
|
|
75
|
-
' GetIMy: Self::GetIMy,\n' +
|
|
76
|
-
' SetManagedStruct: Self::SetManagedStruct,\n' +
|
|
77
|
-
' },\n' +
|
|
78
|
-
' };\n' +
|
|
79
|
-
' }\n' +
|
|
80
|
-
' impl<T> ClassEx for T\n' +
|
|
81
|
-
' where\n' +
|
|
82
|
-
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
83
|
-
' nanocom::CObject<Self>: Ex,\n' +
|
|
84
|
-
' {\n' +
|
|
85
|
-
' }\n' +
|
|
86
|
-
' trait PrivateClassEx\n' +
|
|
87
|
-
' where\n' +
|
|
88
|
-
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
89
|
-
' nanocom::CObject<Self>: Ex,\n' +
|
|
90
|
-
' {\n' +
|
|
91
|
-
' extern "system" fn GetSlice(this: &Object) -> super::Slice {\n' +
|
|
92
|
-
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetSlice()\n' +
|
|
93
|
-
' }\n' +
|
|
94
|
-
' extern "system" fn SetSlice(this: &Object, slice: super::Slice) {\n' +
|
|
95
|
-
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetSlice(slice)\n' +
|
|
96
|
-
' }\n' +
|
|
97
|
-
' extern "system" fn GetUnsafe(this: &Object) -> *const bool {\n' +
|
|
98
|
-
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetUnsafe()\n' +
|
|
99
|
-
' }\n' +
|
|
100
|
-
' extern "system" fn SetUnsafe(this: &Object, p: *const super::Slice, size: u32) {\n' +
|
|
101
|
-
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetUnsafe(p, size)\n' +
|
|
102
|
-
' }\n' +
|
|
103
|
-
' extern "system" fn Some(this: &Object, p: &super::IMy::Object) -> bool {\n' +
|
|
104
|
-
' unsafe { nanocom::CObject::from_object_unchecked(this) }.Some(p)\n' +
|
|
105
|
-
' }\n' +
|
|
106
|
-
' extern "system" fn GetIMy(this: &Object, a: u16, b: i16) -> super::IMy::Ref {\n' +
|
|
107
|
-
' unsafe { nanocom::CObject::from_object_unchecked(this) }.GetIMy(a, b)\n' +
|
|
108
|
-
' }\n' +
|
|
109
|
-
' extern "system" fn SetManagedStruct(this: &Object, a: super::ManagedStruct) {\n' +
|
|
110
|
-
' unsafe { nanocom::CObject::from_object_unchecked(this) }.SetManagedStruct(a)\n' +
|
|
111
|
-
' }\n' +
|
|
112
|
-
' }\n' +
|
|
113
|
-
' impl<T> PrivateClassEx for T\n' +
|
|
114
|
-
' where\n' +
|
|
115
|
-
' Self: nanocom::Class<Interface = Interface>,\n' +
|
|
116
|
-
' nanocom::CObject<Self>: Ex,\n' +
|
|
117
|
-
' {\n' +
|
|
118
|
-
' }\n' +
|
|
119
|
-
'}';
|
|
120
|
-
if (rust !== e) {
|
|
121
|
-
throw rust;
|
|
122
|
-
}
|
|
123
|
-
};
|
package/com/rust/testlib.f.d.ts
DELETED
package/com/rust/testlib.f.js
DELETED
package/com/test/build.f.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type List } from '../../types/list/module.f.ts';
|
|
2
|
-
type Platform = 'aix' | 'android' | 'darwin' | 'freebsd' | 'haiku' | 'linux' | 'openbsd' | 'sunos' | 'win32' | 'cygwin' | 'netbsd';
|
|
3
|
-
type NodeJs = {
|
|
4
|
-
readonly dirname: string;
|
|
5
|
-
readonly platform: Platform;
|
|
6
|
-
};
|
|
7
|
-
type Output = {
|
|
8
|
-
readonly file: {
|
|
9
|
-
readonly name: string;
|
|
10
|
-
readonly content: string;
|
|
11
|
-
};
|
|
12
|
-
readonly line: List<List<string>>;
|
|
13
|
-
};
|
|
14
|
-
export type Func = (nodejs: NodeJs) => Output;
|
|
15
|
-
declare const _default: {
|
|
16
|
-
cpp: Func;
|
|
17
|
-
cs: Func;
|
|
18
|
-
rust: Func;
|
|
19
|
-
};
|
|
20
|
-
export default _default;
|
package/com/test/build.f.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { flat } from "../../types/list/module.f.js";
|
|
2
|
-
import cppContent from "../cpp/testlib.f.js";
|
|
3
|
-
import csContent from "../cs/testlib.f.js";
|
|
4
|
-
import rustContent from "../rust/testlib.f.js";
|
|
5
|
-
const flags = (platform) => {
|
|
6
|
-
switch (platform) {
|
|
7
|
-
case 'win32':
|
|
8
|
-
return [];
|
|
9
|
-
case 'linux':
|
|
10
|
-
return ['-std=c++17', '-lstdc++', '-fPIC'];
|
|
11
|
-
default:
|
|
12
|
-
return ['-std=c++17', '-lc++'];
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const output = (platform) => (name) => {
|
|
16
|
-
switch (platform) {
|
|
17
|
-
case 'win32': return `${name}.dll`;
|
|
18
|
-
case 'darwin': return `lib${name}.dylib`;
|
|
19
|
-
default: return `lib${name}.so`;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const cpp = ({ dirname, platform }) => ({
|
|
23
|
-
file: {
|
|
24
|
-
name: `${dirname}/cpp/_result.hpp`,
|
|
25
|
-
content: cppContent(),
|
|
26
|
-
},
|
|
27
|
-
line: [
|
|
28
|
-
flat([
|
|
29
|
-
['clang', '-shared', '-o', output(platform)('testc')],
|
|
30
|
-
flags(platform),
|
|
31
|
-
[`${dirname}/cpp/main.cpp`],
|
|
32
|
-
]),
|
|
33
|
-
],
|
|
34
|
-
});
|
|
35
|
-
const cs = ({ dirname, platform }) => ({
|
|
36
|
-
file: {
|
|
37
|
-
name: `${dirname}/cs/_result.cs`,
|
|
38
|
-
content: csContent,
|
|
39
|
-
},
|
|
40
|
-
line: [
|
|
41
|
-
platform === 'win32'
|
|
42
|
-
? ['dotnet', 'run', '--project', `${dirname}/cs/cs.csproj`]
|
|
43
|
-
// .Net on Linux and MacOS doesn't properly support COM object marshalling
|
|
44
|
-
: ['dotnet', 'build', `${dirname}/cs/cs.csproj`]
|
|
45
|
-
],
|
|
46
|
-
});
|
|
47
|
-
const rust = ({ dirname }) => ({
|
|
48
|
-
file: {
|
|
49
|
-
name: `${dirname}/rust/src/_result.rs`,
|
|
50
|
-
content: rustContent,
|
|
51
|
-
},
|
|
52
|
-
line: [['cargo', 'build' /**, '--locked' */]]
|
|
53
|
-
});
|
|
54
|
-
export default {
|
|
55
|
-
cpp,
|
|
56
|
-
cs,
|
|
57
|
-
rust,
|
|
58
|
-
};
|
package/com/types/module.f.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type * as O from '../../types/object/module.f.ts';
|
|
2
|
-
import { type List } from '../../types/list/module.f.ts';
|
|
3
|
-
export type Library = {
|
|
4
|
-
readonly [k in string]: Definition;
|
|
5
|
-
};
|
|
6
|
-
export type Definition = Struct | Interface;
|
|
7
|
-
export type Struct = {
|
|
8
|
-
readonly struct: FieldArray;
|
|
9
|
-
};
|
|
10
|
-
export type FieldArray = {
|
|
11
|
-
readonly [k in string]: Type;
|
|
12
|
-
};
|
|
13
|
-
export type Field = O.Entry<Type>;
|
|
14
|
-
export type Interface = {
|
|
15
|
-
readonly interface: MethodArray;
|
|
16
|
-
readonly guid: string;
|
|
17
|
-
};
|
|
18
|
-
type MethodArray = {
|
|
19
|
-
readonly [k in string]: FieldArray;
|
|
20
|
-
};
|
|
21
|
-
export type Method = O.Entry<FieldArray>;
|
|
22
|
-
export type Type = BaseType | Id | Pointer;
|
|
23
|
-
type Id = readonly [string];
|
|
24
|
-
export type BaseType = 'u8' | 'i8' | 'u16' | 'i16' | 'u32' | 'i32' | 'u64' | 'i64' | 'usize' | 'isize' | 'f32' | 'f64' | 'bool';
|
|
25
|
-
type Pointer = readonly ['*', Type];
|
|
26
|
-
export declare const paramList: (fa: FieldArray) => List<Field>;
|
|
27
|
-
export declare const result: <T>(v: T) => (f: (type: Type) => T) => (fa: FieldArray) => T;
|
|
28
|
-
export {};
|
package/com/types/module.f.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { filter } from "../../types/list/module.f.js";
|
|
2
|
-
import { compose } from "../../types/function/module.f.js";
|
|
3
|
-
const { entries } = Object;
|
|
4
|
-
const isParam = ([name]) => name !== '_';
|
|
5
|
-
const filterParam = filter(isParam);
|
|
6
|
-
export const paramList = compose(entries)(filterParam);
|
|
7
|
-
export const result = (v) => (f) => (fa) => '_' in fa ? f(fa._) : v;
|
package/com/types/testlib.f.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
declare const _default: {
|
|
2
|
-
Slice: {
|
|
3
|
-
struct: {
|
|
4
|
-
Start: ["*", "u8"];
|
|
5
|
-
Size: "usize";
|
|
6
|
-
};
|
|
7
|
-
};
|
|
8
|
-
ManagedStruct: {
|
|
9
|
-
struct: {
|
|
10
|
-
M: ["IMy"];
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
IMy: {
|
|
14
|
-
guid: string;
|
|
15
|
-
interface: {
|
|
16
|
-
GetSlice: {
|
|
17
|
-
_: ["Slice"];
|
|
18
|
-
};
|
|
19
|
-
SetSlice: {
|
|
20
|
-
slice: ["Slice"];
|
|
21
|
-
};
|
|
22
|
-
GetUnsafe: {
|
|
23
|
-
_: ["*", "bool"];
|
|
24
|
-
};
|
|
25
|
-
SetUnsafe: {
|
|
26
|
-
p: ["*", ["Slice"]];
|
|
27
|
-
size: "u32";
|
|
28
|
-
};
|
|
29
|
-
Some: {
|
|
30
|
-
p: ["IMy"];
|
|
31
|
-
_: "bool";
|
|
32
|
-
};
|
|
33
|
-
GetIMy: {
|
|
34
|
-
a: "u16";
|
|
35
|
-
b: "i16";
|
|
36
|
-
_: ["IMy"];
|
|
37
|
-
};
|
|
38
|
-
SetManagedStruct: {
|
|
39
|
-
a: ["ManagedStruct"];
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
export default _default;
|
package/com/types/testlib.f.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
Slice: {
|
|
3
|
-
struct: {
|
|
4
|
-
Start: ['*', 'u8'],
|
|
5
|
-
Size: 'usize',
|
|
6
|
-
},
|
|
7
|
-
},
|
|
8
|
-
ManagedStruct: {
|
|
9
|
-
struct: {
|
|
10
|
-
M: ['IMy']
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
IMy: {
|
|
14
|
-
guid: 'C66FB270-2D80-49AD-BB6E-88C1F90B805D',
|
|
15
|
-
interface: {
|
|
16
|
-
GetSlice: { _: ['Slice'] },
|
|
17
|
-
SetSlice: { slice: ['Slice'] },
|
|
18
|
-
GetUnsafe: { _: ['*', 'bool'] },
|
|
19
|
-
SetUnsafe: {
|
|
20
|
-
p: ['*', ['Slice']],
|
|
21
|
-
size: 'u32'
|
|
22
|
-
},
|
|
23
|
-
Some: { p: ['IMy'], _: 'bool' },
|
|
24
|
-
GetIMy: { a: 'u16', b: 'i16', _: ['IMy'] },
|
|
25
|
-
SetManagedStruct: { a: ['ManagedStruct'] },
|
|
26
|
-
},
|
|
27
|
-
}
|
|
28
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type * as package_ from '../package/module.f.ts';
|
|
2
|
-
import { type MapInterface, type Id, type State } from '../module/module.f.ts';
|
|
3
|
-
import type * as function_ from '../module/function/module.f.ts';
|
|
4
|
-
type Result<M> = readonly [State, M];
|
|
5
|
-
export declare const getOrBuild: (compile: function_.Compile) => (packageGet: package_.Get) => <M>(moduleMapInterface: MapInterface<M>) => (moduleId: Id) => (moduleMap: M) => Result<M>;
|
|
6
|
-
export {};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { idToString, dir, } from "../module/module.f.js";
|
|
2
|
-
import { empty as mapEmpty, setReplace } from "../../types/map/module.f.js";
|
|
3
|
-
import * as object from "../../types/object/module.f.js";
|
|
4
|
-
const { fromMap } = object;
|
|
5
|
-
import * as path from "../path/module.f.js";
|
|
6
|
-
const { parseAndFind } = path;
|
|
7
|
-
import * as stringSet from "../../types/string_set/module.f.js";
|
|
8
|
-
const { set: setSet, contains: setContains, empty: stringSetEmpty } = stringSet;
|
|
9
|
-
const notFound = (moduleMap) => [['error', ['file not found']], moduleMap];
|
|
10
|
-
export const getOrBuild = compile => packageGet => moduleMapInterface => {
|
|
11
|
-
const build = buildSet => moduleId => {
|
|
12
|
-
const moduleIdStr = idToString(moduleId);
|
|
13
|
-
const buildSet1 = setSet(moduleIdStr)(buildSet);
|
|
14
|
-
const moduleDir = dir(moduleId);
|
|
15
|
-
const require_ = p => ([requireMap, m]) => {
|
|
16
|
-
const error = e => [['error', e], [requireMap, m]];
|
|
17
|
-
if (moduleDir === null) {
|
|
18
|
-
return error('file not found');
|
|
19
|
-
}
|
|
20
|
-
const r = parseAndFind(packageGet)(moduleDir)(p);
|
|
21
|
-
if (r === null) {
|
|
22
|
-
return error('file not found');
|
|
23
|
-
}
|
|
24
|
-
const rIdStr = idToString(r.id);
|
|
25
|
-
if (setContains(rIdStr)(buildSet1)) {
|
|
26
|
-
return error('circular reference');
|
|
27
|
-
}
|
|
28
|
-
const [state, m1] = build(buildSet1)(r.id)(r.source)(m);
|
|
29
|
-
return [state[0] === 'error' ? state : ['ok', state[1].exports], [setReplace(p)(rIdStr)(requireMap), m1]];
|
|
30
|
-
};
|
|
31
|
-
return source => moduleMap => {
|
|
32
|
-
const set = s => m => [s, moduleMapInterface.setReplace(moduleIdStr)(s)(m)];
|
|
33
|
-
const error = e => set(['error', e]);
|
|
34
|
-
// check compilation
|
|
35
|
-
const [kind, result] = compile(source);
|
|
36
|
-
if (kind === 'error') {
|
|
37
|
-
return error(['compilation error', result])(moduleMap);
|
|
38
|
-
}
|
|
39
|
-
// build
|
|
40
|
-
const [[state, value], [requireMap, moduleMap2]] = result(require_)([mapEmpty, moduleMap]);
|
|
41
|
-
const x = state === 'error' ?
|
|
42
|
-
error(['runtime error', value]) :
|
|
43
|
-
set(['ok', { exports: value, requireMap: fromMap(requireMap) }]);
|
|
44
|
-
return x(moduleMap2);
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
const f = (moduleId) => (moduleMap) => {
|
|
48
|
-
const moduleIdStr = idToString(moduleId);
|
|
49
|
-
// check moduleMap
|
|
50
|
-
{
|
|
51
|
-
const m = moduleMapInterface.at(moduleIdStr)(moduleMap);
|
|
52
|
-
if (m !== null) {
|
|
53
|
-
return [m, moduleMap];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// check package
|
|
57
|
-
const p = packageGet(moduleId.package);
|
|
58
|
-
if (p === null) {
|
|
59
|
-
return notFound(moduleMap);
|
|
60
|
-
}
|
|
61
|
-
// check file
|
|
62
|
-
const source = p.file(moduleId.path.join('/'));
|
|
63
|
-
return (source === null ? notFound : build(stringSetEmpty)(moduleId)(source))(moduleMap);
|
|
64
|
-
};
|
|
65
|
-
return f;
|
|
66
|
-
};
|
package/commonjs/build/test.f.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as _ from "./module.f.js";
|
|
2
|
-
import * as map from "../../types/map/module.f.js";
|
|
3
|
-
import { at } from "../../types/object/module.f.js";
|
|
4
|
-
const compileMap = {
|
|
5
|
-
':index.js': [
|
|
6
|
-
'ok',
|
|
7
|
-
require_ => m0 => {
|
|
8
|
-
let [r, m] = require_('./b')(m0);
|
|
9
|
-
if (r[0] === 'error') {
|
|
10
|
-
throw JSON.stringify(r);
|
|
11
|
-
}
|
|
12
|
-
[r, m] = require_('./a/')(m);
|
|
13
|
-
if (r[0] === 'error') {
|
|
14
|
-
throw JSON.stringify(r);
|
|
15
|
-
}
|
|
16
|
-
[r, m] = require_('x/r')(m);
|
|
17
|
-
if (r[0] === 'error') {
|
|
18
|
-
throw JSON.stringify(r);
|
|
19
|
-
}
|
|
20
|
-
return [['ok', ':index.js'], m];
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
':b.js': [
|
|
24
|
-
'ok',
|
|
25
|
-
() => m0 => [['ok', ':b.js'], m0]
|
|
26
|
-
],
|
|
27
|
-
':a/index.js': [
|
|
28
|
-
'ok',
|
|
29
|
-
() => m0 => [['ok', ':a/index.js'], m0]
|
|
30
|
-
],
|
|
31
|
-
'x:r.js': [
|
|
32
|
-
'ok',
|
|
33
|
-
() => m0 => [['ok', 'x:r.js'], m0]
|
|
34
|
-
],
|
|
35
|
-
};
|
|
36
|
-
const compile = source => compileMap[source] ?? ['error', 'invalid source'];
|
|
37
|
-
const packageMap = {
|
|
38
|
-
'': {
|
|
39
|
-
dependencies: {
|
|
40
|
-
'x': '/node_modules/x'
|
|
41
|
-
},
|
|
42
|
-
files: {
|
|
43
|
-
'index.js': ':index.js',
|
|
44
|
-
'b.js': ':b.js',
|
|
45
|
-
'a/index.js': ':a/index.js',
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
'/node_modules/x': {
|
|
49
|
-
dependencies: {},
|
|
50
|
-
files: {
|
|
51
|
-
'r.js': 'x:r.js'
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
const packageGet = packageId => {
|
|
56
|
-
const p = at(packageId)(packageMap);
|
|
57
|
-
return p === null ? null :
|
|
58
|
-
{
|
|
59
|
-
dependency: dependency => at(dependency)(p.dependencies),
|
|
60
|
-
file: file => at(file)(p.files),
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
const getOrBuild = _.getOrBuild(compile)(packageGet)(map);
|
|
64
|
-
export default () => {
|
|
65
|
-
let [r, m] = getOrBuild({ package: '', path: ['index.js'] })(map.empty);
|
|
66
|
-
{
|
|
67
|
-
if (r === null) {
|
|
68
|
-
throw 'r === null';
|
|
69
|
-
}
|
|
70
|
-
const x = JSON.stringify(r);
|
|
71
|
-
if (x !==
|
|
72
|
-
'["ok",{"exports":":index.js","requireMap":{"./a/":"/a/index.js","./b":"/b.js","x/r":"/node_modules/x/r.js"}}]') {
|
|
73
|
-
throw `0:${x}`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
{
|
|
77
|
-
[r, m] = getOrBuild({ package: '', path: ['b.js'] })(m);
|
|
78
|
-
const x = JSON.stringify(r);
|
|
79
|
-
if (x !==
|
|
80
|
-
'["ok",{"exports":":b.js","requireMap":{}}]') {
|
|
81
|
-
throw x;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
{
|
|
85
|
-
[r, m] = getOrBuild({ package: '', path: ['c.js'] })(m);
|
|
86
|
-
const x = JSON.stringify(r);
|
|
87
|
-
if (x !==
|
|
88
|
-
'["error",["file not found"]]') {
|
|
89
|
-
throw x;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An IO interface for creating and running module functions.
|
|
3
|
-
*/
|
|
4
|
-
import type * as TypesResult from '../../../types/result/module.f.ts';
|
|
5
|
-
export type Function_ = <M>(require: Require<M>) => (prior: M) => Result<M>;
|
|
6
|
-
export type Result<M> = readonly [TypesResult.Result<unknown, unknown>, M];
|
|
7
|
-
export type Require<M> = (path: string) => (prior: M) => Result<M>;
|
|
8
|
-
export type Compile = (source: string) => TypesResult.Result<Function_, unknown>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type * as O from '../../types/object/module.f.ts';
|
|
2
|
-
export type MapInterface<M> = {
|
|
3
|
-
readonly at: (moduleId: string) => (moduleMap: M) => State | null;
|
|
4
|
-
readonly setReplace: (moduleId: string) => (moduleState: State) => (moduleMap: M) => M;
|
|
5
|
-
};
|
|
6
|
-
export type State = readonly ['ok', Module] | readonly ['error', Error];
|
|
7
|
-
type Module = {
|
|
8
|
-
readonly exports: unknown;
|
|
9
|
-
readonly requireMap: O.Map<string>;
|
|
10
|
-
};
|
|
11
|
-
export type Error = ['file not found'] | ['compilation error', unknown] | ['runtime error', unknown] | ['circular reference'];
|
|
12
|
-
export type Id = {
|
|
13
|
-
readonly package: string;
|
|
14
|
-
readonly path: readonly string[];
|
|
15
|
-
};
|
|
16
|
-
export declare const dir: (id: Id) => Id | null;
|
|
17
|
-
export declare const idToString: (id: Id) => string;
|
|
18
|
-
export {};
|
package/commonjs/module.f.d.ts
DELETED
package/commonjs/module.f.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type Unknown } from '../../../json/module.f.ts';
|
|
2
|
-
type DependencyMapJson = {
|
|
3
|
-
readonly [k in string]: string;
|
|
4
|
-
};
|
|
5
|
-
export type DependenciesJson = DependencyMapJson | null;
|
|
6
|
-
export declare const isDependenciesJson: (j: Unknown) => j is DependenciesJson;
|
|
7
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { isObject } from "../../../json/module.f.js";
|
|
2
|
-
import { map, every } from "../../../types/list/module.f.js";
|
|
3
|
-
const { entries } = Object;
|
|
4
|
-
const isDependencyJson = ([, v]) => typeof v === 'string';
|
|
5
|
-
export const isDependenciesJson = (j) => {
|
|
6
|
-
if (j === null) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
if (!isObject(j)) {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
return every(map(isDependencyJson)(entries(j)));
|
|
13
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as _ from "./module.f.js";
|
|
2
|
-
export default () => {
|
|
3
|
-
if (!_.isDependenciesJson(null)) {
|
|
4
|
-
throw 'error';
|
|
5
|
-
}
|
|
6
|
-
if (!_.isDependenciesJson({})) {
|
|
7
|
-
throw 'error';
|
|
8
|
-
}
|
|
9
|
-
if (!_.isDependenciesJson({ 'a': 'b' })) {
|
|
10
|
-
throw 'error';
|
|
11
|
-
}
|
|
12
|
-
if (_.isDependenciesJson({ 'a': 12 })) {
|
|
13
|
-
throw 'error';
|
|
14
|
-
}
|
|
15
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type Unknown } from '../../json/module.f.ts';
|
|
2
|
-
import { type DependenciesJson } from './dependencies/module.f.ts';
|
|
3
|
-
type PackageJson = {
|
|
4
|
-
readonly name: string;
|
|
5
|
-
readonly version: string;
|
|
6
|
-
readonly dependencies?: DependenciesJson;
|
|
7
|
-
};
|
|
8
|
-
export declare const isPackageJson: (j: Unknown) => j is PackageJson;
|
|
9
|
-
export type Package = {
|
|
10
|
-
readonly dependency: (localPackageId: string) => string | null;
|
|
11
|
-
readonly file: (localFileId: string) => string | null;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* @note Current package has an empty string '' as a packageId.
|
|
15
|
-
*/
|
|
16
|
-
export type Get = (packageId: string) => Package | null;
|
|
17
|
-
export {};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { isObject } from "../../json/module.f.js";
|
|
2
|
-
import { isDependenciesJson } from "./dependencies/module.f.js";
|
|
3
|
-
import { at } from "../../types/object/module.f.js";
|
|
4
|
-
export const isPackageJson = (j) => {
|
|
5
|
-
if (!isObject(j)) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
if (typeof j.name !== 'string') {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
if (typeof j.version !== 'string') {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
if (!isDependenciesJson(at('dependencies')(j))) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
};
|