mirror of
https://github.com/fluencelabs/aqua.git
synced 2024-12-03 22:20:17 +00:00
feat(aqua-api): Use scala.js link instead of opt (#891)
* Add link settings * fix * Rename to api-dist-js * Correct import * Update CI --------- Co-authored-by: Artsiom Shamsutdzinau <shamsartem@gmail.com>
This commit is contained in:
parent
6be2a3d5da
commit
3f916c78ab
2
.github/workflows/publish.yml
vendored
2
.github/workflows/publish.yml
vendored
@ -41,7 +41,7 @@ jobs:
|
||||
apps: sbt
|
||||
|
||||
- name: scala-js build
|
||||
run: sbt ";language-server-apiJS/fullOptJS;aqua-apiJS/fullOptJS"
|
||||
run: sbt ";language-server-apiJS/fullOptJS;aqua-apiJS/fullLinkJS"
|
||||
|
||||
- name: Import secrets
|
||||
uses: hashicorp/vault-action@v2.7.3
|
||||
|
2
.github/workflows/snapshot.yml
vendored
2
.github/workflows/snapshot.yml
vendored
@ -51,7 +51,7 @@ jobs:
|
||||
- name: scala-js build
|
||||
env:
|
||||
SNAPSHOT: ${{ steps.version.outputs.id }}
|
||||
run: sbt ";language-server-apiJS/fastOptJS;aqua-apiJS/fastOptJS"
|
||||
run: sbt ";language-server-apiJS/fastOptJS;aqua-apiJS/fastLinkJS"
|
||||
|
||||
- name: Import secrets
|
||||
uses: hashicorp/vault-action@v2.7.3
|
||||
|
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -82,7 +82,7 @@ jobs:
|
||||
apps: sbt
|
||||
|
||||
- name: aqua-api build
|
||||
run: sbt "aqua-apiJS/fastOptJS"
|
||||
run: sbt "aqua-apiJS/fastLinkJS"
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v2.4.0
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -9,9 +9,8 @@ project/target
|
||||
|
||||
.DS_Store
|
||||
|
||||
cli/cli-npm/aqua.j*
|
||||
language-server/language-server-npm/aqua-lsp-api.j*
|
||||
api/api-npm/aqua-api.j*
|
||||
api/api-npm/api-dist-js
|
||||
|
||||
integration-tests/src/compiled/*
|
||||
|
||||
|
69
api/api-npm/aqua-api.d.ts
vendored
69
api/api-npm/aqua-api.d.ts
vendored
@ -1,69 +0,0 @@
|
||||
import type { FunctionCallDef, ServiceDef } from "@fluencelabs/interfaces";
|
||||
|
||||
export class AquaConfig {
|
||||
constructor(
|
||||
logLevel?: string,
|
||||
constants?: string[],
|
||||
noXor?: boolean,
|
||||
noRelay?: boolean,
|
||||
targetType?: string,
|
||||
tracing?: boolean,
|
||||
);
|
||||
|
||||
logLevel?: string;
|
||||
constants?: string[];
|
||||
noXor?: boolean;
|
||||
noRelay?: boolean;
|
||||
targetType?: string;
|
||||
tracing?: boolean;
|
||||
}
|
||||
|
||||
export class AquaFunction {
|
||||
funcDef: FunctionCallDef;
|
||||
script: string;
|
||||
}
|
||||
|
||||
export class GeneratedSource {
|
||||
name: string;
|
||||
tsSource?: string;
|
||||
jsSource?: string;
|
||||
tsTypes?: string;
|
||||
}
|
||||
|
||||
export class CompilationResult {
|
||||
services: Record<string, ServiceDef>;
|
||||
functions: Record<string, AquaFunction>;
|
||||
functionCall?: AquaFunction;
|
||||
errors: string[];
|
||||
generatedSources: GeneratedSource[];
|
||||
}
|
||||
|
||||
export class Input {
|
||||
constructor(input: string);
|
||||
|
||||
input: string;
|
||||
}
|
||||
|
||||
export class Path {
|
||||
constructor(path: string);
|
||||
|
||||
path: string;
|
||||
}
|
||||
|
||||
export class Call {
|
||||
constructor(functionCall: string, arguments: any, input: Input | Path);
|
||||
|
||||
functionCall: string;
|
||||
arguments: any;
|
||||
input: Input | Path;
|
||||
}
|
||||
|
||||
export class Compiler {
|
||||
compile(
|
||||
input: Input | Path | Call,
|
||||
imports: string[],
|
||||
config?: AquaConfig,
|
||||
): Promise<CompilationResult>;
|
||||
}
|
||||
|
||||
export var Aqua: Compiler;
|
46
api/api-npm/index.d.ts
vendored
46
api/api-npm/index.d.ts
vendored
@ -1,4 +1,24 @@
|
||||
import { type CompilationResult } from "./aqua-api.js";
|
||||
import { ServiceDef, FunctionCallDef } from "@fluencelabs/interfaces";
|
||||
|
||||
class AquaFunction {
|
||||
funcDef: FunctionCallDef;
|
||||
script: string;
|
||||
}
|
||||
|
||||
class GeneratedSource {
|
||||
name: string;
|
||||
tsSource?: string;
|
||||
jsSource?: string;
|
||||
tsTypes?: string;
|
||||
}
|
||||
|
||||
class CompilationResult {
|
||||
services: Record<string, ServiceDef>;
|
||||
functions: Record<string, AquaFunction>;
|
||||
functionCall?: AquaFunction;
|
||||
errors: string[];
|
||||
generatedSources: GeneratedSource[];
|
||||
}
|
||||
|
||||
/** Common arguments for all compile functions */
|
||||
type CommonArgs = {
|
||||
@ -21,30 +41,38 @@ type CommonArgs = {
|
||||
type CodeString = {
|
||||
/** Aqua code to be compiled */
|
||||
code: string;
|
||||
}
|
||||
};
|
||||
|
||||
/** Compile aqua code from a string */
|
||||
export declare function compileFromString(args: CommonArgs & CodeString): Promise<Omit<CompilationResult, 'funcCall'>>
|
||||
export declare function compileFromString(
|
||||
args: CommonArgs & CodeString,
|
||||
): Promise<Omit<CompilationResult, "funcCall">>;
|
||||
|
||||
type FilePath = {
|
||||
/** Path to the aqua file to be compiled */
|
||||
filePath: string;
|
||||
}
|
||||
};
|
||||
|
||||
/** Compile aqua code from a file */
|
||||
export declare function compileFromPath(args: CommonArgs & FilePath): Promise<Omit<CompilationResult, 'funcCall'>>
|
||||
export declare function compileFromPath(
|
||||
args: CommonArgs & FilePath,
|
||||
): Promise<Omit<CompilationResult, "funcCall">>;
|
||||
|
||||
type FuncCall = {
|
||||
/** Function call you want to compile. Example: someFunc("someArg") */
|
||||
funcCall: string;
|
||||
/** Args to be passed to the function (record with keys named as args you want to pass to the function) Example: { someArg: 1 } */
|
||||
data?: Record<string, unknown> | undefined;
|
||||
}
|
||||
};
|
||||
|
||||
/** Compile aqua function call from a string */
|
||||
export declare function compileAquaCallFromString(args: CommonArgs & CodeString & FuncCall): Promise<Required<CompilationResult>>
|
||||
export declare function compileAquaCallFromString(
|
||||
args: CommonArgs & CodeString & FuncCall,
|
||||
): Promise<Required<CompilationResult>>;
|
||||
|
||||
/** Compile aqua function call from a file */
|
||||
export declare function compileAquaCallFromPath(args: CommonArgs & FilePath & FuncCall): Promise<Required<CompilationResult>>
|
||||
export declare function compileAquaCallFromPath(
|
||||
args: CommonArgs & FilePath & FuncCall,
|
||||
): Promise<Required<CompilationResult>>;
|
||||
|
||||
export {}
|
||||
export {};
|
||||
|
@ -1,5 +1,4 @@
|
||||
// @ts-check
|
||||
import { AquaConfig, Aqua, Call, Input, Path } from "./aqua-api.js";
|
||||
import { AquaConfig, Aqua, Call, Input, Path } from "./api-dist-js/main.js";
|
||||
|
||||
function getConfig({
|
||||
constants = [],
|
||||
|
@ -7,8 +7,7 @@
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts",
|
||||
"aqua-api.js",
|
||||
"aqua-api.d.ts",
|
||||
"api-dist-js/main.js",
|
||||
"meta-utils.js"
|
||||
],
|
||||
"prettier": {},
|
||||
|
11
build.sbt
11
build.sbt
@ -74,6 +74,7 @@ lazy val `language-server-api` = crossProject(JSPlatform, JVMPlatform)
|
||||
|
||||
lazy val `language-server-apiJS` = `language-server-api`.js
|
||||
.settings(
|
||||
// TODO: move to fast/fullLinkJS here
|
||||
Compile / fastOptJS / artifactPath := baseDirectory.value / "../../language-server-npm" / "aqua-lsp-api.js",
|
||||
Compile / fullOptJS / artifactPath := baseDirectory.value / "../../language-server-npm" / "aqua-lsp-api.js",
|
||||
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
|
||||
@ -103,11 +104,11 @@ lazy val `aqua-api` = crossProject(JSPlatform, JVMPlatform)
|
||||
|
||||
lazy val `aqua-apiJS` = `aqua-api`.js
|
||||
.settings(
|
||||
Compile / fastOptJS / artifactPath := baseDirectory.value / "../../api-npm" / "aqua-api.js",
|
||||
Compile / fullOptJS / artifactPath := baseDirectory.value / "../../api-npm" / "aqua-api.js",
|
||||
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule)),
|
||||
scalaJSUseMainModuleInitializer := true,
|
||||
Test / test := {}
|
||||
Compile / fastLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "../../api-npm/api-dist-js",
|
||||
Compile / fullLinkJS / scalaJSLinkerOutputDirectory := baseDirectory.value / "../../api-npm/api-dist-js",
|
||||
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule)),
|
||||
scalaJSUseMainModuleInitializer := true,
|
||||
Test / test := {}
|
||||
)
|
||||
.enablePlugins(ScalaJSPlugin)
|
||||
.dependsOn(`js-exports`)
|
||||
|
@ -7,8 +7,9 @@ object Meta {
|
||||
|
||||
// get `import`.meta.url info from javascript
|
||||
// it is needed for `createRequire` function
|
||||
// TODO: Investigate if it is really needed
|
||||
@js.native
|
||||
@JSImport("./meta-utils.js", "metaUrl")
|
||||
@JSImport("../meta-utils.js", "metaUrl")
|
||||
val metaUrl: String = js.native
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user