@unibridge/sdk 0.5.0 → 0.9.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/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +59 -0
- package/dist/client.js.map +1 -0
- package/dist/commands/component/contract.d.ts +174 -0
- package/dist/commands/component/contract.d.ts.map +1 -0
- package/dist/commands/component/contract.js +142 -0
- package/dist/commands/component/contract.js.map +1 -0
- package/dist/commands/contracts.d.ts +9 -0
- package/dist/commands/contracts.d.ts.map +1 -0
- package/dist/commands/contracts.js +2 -0
- package/dist/commands/contracts.js.map +1 -0
- package/dist/commands/define.d.ts +19 -0
- package/dist/commands/define.d.ts.map +1 -0
- package/dist/commands/define.js +20 -0
- package/dist/commands/define.js.map +1 -0
- package/dist/commands/domain/contract.d.ts +10 -0
- package/dist/commands/domain/contract.d.ts.map +1 -0
- package/dist/commands/domain/contract.js +12 -0
- package/dist/commands/domain/contract.js.map +1 -0
- package/dist/commands/execute/contract.d.ts +4 -0
- package/dist/commands/execute/contract.d.ts.map +1 -0
- package/dist/commands/execute/contract.js +10 -0
- package/dist/commands/execute/contract.js.map +1 -0
- package/dist/commands/gameobject/contract.d.ts +320 -0
- package/dist/commands/gameobject/contract.d.ts.map +1 -0
- package/dist/commands/gameobject/contract.js +154 -0
- package/dist/commands/gameobject/contract.js.map +1 -0
- package/dist/commands/log/contract.d.ts +46 -0
- package/dist/commands/log/contract.d.ts.map +1 -0
- package/dist/commands/log/contract.js +31 -0
- package/dist/commands/log/contract.js.map +1 -0
- package/dist/commands/registry.d.ts +303 -0
- package/dist/commands/registry.d.ts.map +1 -0
- package/dist/commands/registry.js +10 -0
- package/dist/commands/registry.js.map +1 -0
- package/dist/commands/runtime.d.ts +7 -0
- package/dist/commands/runtime.d.ts.map +1 -0
- package/dist/commands/runtime.js +2 -0
- package/dist/commands/runtime.js.map +1 -0
- package/dist/commands/scene/contract.d.ts +127 -0
- package/dist/commands/scene/contract.d.ts.map +1 -0
- package/dist/commands/scene/contract.js +79 -0
- package/dist/commands/scene/contract.js.map +1 -0
- package/dist/commands/status/contract.d.ts +18 -0
- package/dist/commands/status/contract.d.ts.map +1 -0
- package/dist/commands/status/contract.js +16 -0
- package/dist/commands/status/contract.js.map +1 -0
- package/dist/commands/test/contract.d.ts +111 -0
- package/dist/commands/test/contract.d.ts.map +1 -0
- package/dist/commands/test/contract.js +71 -0
- package/dist/commands/test/contract.js.map +1 -0
- package/dist/connection.d.ts +37 -0
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +311 -0
- package/dist/connection.js.map +1 -0
- package/dist/hash.d.ts +4 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +41 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/project.d.ts +6 -0
- package/dist/project.d.ts.map +1 -0
- package/dist/project.js +71 -0
- package/dist/project.js.map +1 -0
- package/dist/types.d.ts +55 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +31 -5
- package/src/client.ts +0 -76
- package/src/commands/contracts.ts +0 -4
- package/src/commands/define.ts +0 -56
- package/src/commands/domain/contract.ts +0 -15
- package/src/commands/execute/contract.ts +0 -12
- package/src/commands/registry.ts +0 -6
- package/src/commands/runtime.ts +0 -7
- package/src/commands/scene/contract.ts +0 -46
- package/src/commands/status/contract.ts +0 -19
- package/src/connection.test.ts +0 -330
- package/src/connection.ts +0 -382
- package/src/hash.test.ts +0 -48
- package/src/hash.ts +0 -50
- package/src/index.ts +0 -10
- package/src/project.test.ts +0 -93
- package/src/project.ts +0 -99
- package/src/types.ts +0 -64
- package/tsconfig.json +0 -16
package/dist/project.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { existsSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { cwd } from 'node:process';
|
|
4
|
+
const PLUGIN_NAME = 'com.msanatan.unibridge';
|
|
5
|
+
const SDK_VERSION = JSON.parse(readFileSync(path.join(import.meta.dirname, '..', 'package.json'), 'utf-8')).version;
|
|
6
|
+
const DEFAULT_GIT_SOURCE = `https://github.com/msanatan/unibridge.git?path=unity#v${SDK_VERSION}`;
|
|
7
|
+
function readManifest(projectPath) {
|
|
8
|
+
const manifestPath = path.join(projectPath, 'Packages', 'manifest.json');
|
|
9
|
+
return JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
10
|
+
}
|
|
11
|
+
function writeManifestAtomic(projectPath, manifest) {
|
|
12
|
+
const manifestPath = path.join(projectPath, 'Packages', 'manifest.json');
|
|
13
|
+
const tempPath = `${manifestPath}.tmp`;
|
|
14
|
+
const content = `${JSON.stringify(manifest, null, 2)}\n`;
|
|
15
|
+
writeFileSync(tempPath, content, 'utf-8');
|
|
16
|
+
renameSync(tempPath, manifestPath);
|
|
17
|
+
}
|
|
18
|
+
export function findUnityProject(startPath = cwd()) {
|
|
19
|
+
let current = path.resolve(startPath);
|
|
20
|
+
while (true) {
|
|
21
|
+
const assetsPath = path.join(current, 'Assets');
|
|
22
|
+
const versionPath = path.join(current, 'ProjectSettings', 'ProjectVersion.txt');
|
|
23
|
+
if (existsSync(assetsPath) && existsSync(versionPath)) {
|
|
24
|
+
return current;
|
|
25
|
+
}
|
|
26
|
+
const parent = path.dirname(current);
|
|
27
|
+
if (parent === current) {
|
|
28
|
+
throw new Error('Unity project not found. Run inside a Unity project or pass --project <path>.');
|
|
29
|
+
}
|
|
30
|
+
current = parent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function parseUnityVersion(projectPath) {
|
|
34
|
+
const versionPath = path.join(projectPath, 'ProjectSettings', 'ProjectVersion.txt');
|
|
35
|
+
const content = readFileSync(versionPath, 'utf-8');
|
|
36
|
+
const match = content.match(/m_EditorVersion:\s*(\S+)/);
|
|
37
|
+
if (!match) {
|
|
38
|
+
throw new Error(`Could not parse m_EditorVersion from ${versionPath}`);
|
|
39
|
+
}
|
|
40
|
+
return match[1];
|
|
41
|
+
}
|
|
42
|
+
export function isPluginInstalled(projectPath) {
|
|
43
|
+
const manifest = readManifest(projectPath);
|
|
44
|
+
return Boolean(manifest.dependencies?.[PLUGIN_NAME]);
|
|
45
|
+
}
|
|
46
|
+
export async function init(options = {}) {
|
|
47
|
+
const projectPath = findUnityProject(options.projectPath);
|
|
48
|
+
const unityVersion = parseUnityVersion(projectPath);
|
|
49
|
+
const manifest = readManifest(projectPath);
|
|
50
|
+
const dependencies = { ...(manifest.dependencies ?? {}) };
|
|
51
|
+
const pluginSource = options.source?.type ?? 'git';
|
|
52
|
+
const pluginReference = options.source?.type === 'local'
|
|
53
|
+
? `file:${options.source.path}`
|
|
54
|
+
: options.source?.type === 'git'
|
|
55
|
+
? options.source.url
|
|
56
|
+
: DEFAULT_GIT_SOURCE;
|
|
57
|
+
if (dependencies[PLUGIN_NAME] !== pluginReference) {
|
|
58
|
+
dependencies[PLUGIN_NAME] = pluginReference;
|
|
59
|
+
writeManifestAtomic(projectPath, {
|
|
60
|
+
...manifest,
|
|
61
|
+
dependencies,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
projectPath,
|
|
66
|
+
unityVersion,
|
|
67
|
+
pluginVersion: SDK_VERSION,
|
|
68
|
+
pluginSource,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=project.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC7E,OAAO,IAAI,MAAM,WAAW,CAA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C,CAAA;IAC1C,MAAM,YAAY,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,CAAA;IAEzD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,IAAI,KAAK,CAAA;IAClD,MAAM,eAAe,GACnB,OAAO,CAAC,MAAM,EAAE,IAAI,KAAK,OAAO;QAC9B,CAAC,CAAC,QAAQ,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE;QAC/B,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,KAAK,KAAK;YAC9B,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG;YACpB,CAAC,CAAC,kBAAkB,CAAA;IAE1B,IAAI,YAAY,CAAC,WAAW,CAAC,KAAK,eAAe,EAAE,CAAC;QAClD,YAAY,CAAC,WAAW,CAAC,GAAG,eAAe,CAAA;QAC3C,mBAAmB,CAAC,WAAW,EAAE;YAC/B,GAAG,QAAQ;YACX,YAAY;SACb,CAAC,CAAA;IACJ,CAAC;IAED,OAAO;QACL,WAAW;QACX,YAAY;QACZ,aAAa,EAAE,WAAW;QAC1B,YAAY;KACb,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { CommandMethods } from './commands/define.ts';
|
|
2
|
+
import type { allCommands } from './commands/registry.ts';
|
|
3
|
+
export interface InitOptions {
|
|
4
|
+
projectPath?: string;
|
|
5
|
+
source?: GitSource | LocalSource;
|
|
6
|
+
}
|
|
7
|
+
export interface GitSource {
|
|
8
|
+
type: 'git';
|
|
9
|
+
url: string;
|
|
10
|
+
}
|
|
11
|
+
export interface LocalSource {
|
|
12
|
+
type: 'local';
|
|
13
|
+
path: string;
|
|
14
|
+
}
|
|
15
|
+
export interface InitResult {
|
|
16
|
+
projectPath: string;
|
|
17
|
+
unityVersion: string;
|
|
18
|
+
pluginVersion: string;
|
|
19
|
+
pluginSource: 'git' | 'local';
|
|
20
|
+
}
|
|
21
|
+
export interface CommandRequest {
|
|
22
|
+
id: string;
|
|
23
|
+
command: string;
|
|
24
|
+
params: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
export interface CommandResponse {
|
|
27
|
+
id: string;
|
|
28
|
+
success: boolean;
|
|
29
|
+
result?: unknown;
|
|
30
|
+
error?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ServerMetadata {
|
|
33
|
+
pid: number;
|
|
34
|
+
unityVersion: string;
|
|
35
|
+
pluginVersion: string;
|
|
36
|
+
protocolVersion: number;
|
|
37
|
+
capabilities?: {
|
|
38
|
+
executeEnabled?: boolean;
|
|
39
|
+
};
|
|
40
|
+
projectPath?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface TimeoutOptions {
|
|
43
|
+
connectTimeout?: number;
|
|
44
|
+
commandTimeout?: number;
|
|
45
|
+
reconnectTimeout?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface ClientOptions extends TimeoutOptions {
|
|
48
|
+
projectPath?: string;
|
|
49
|
+
enableExecute?: boolean;
|
|
50
|
+
}
|
|
51
|
+
export type UniBridgeClient = CommandMethods<typeof allCommands> & {
|
|
52
|
+
readonly projectPath: string;
|
|
53
|
+
close(): void;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEzD,MAAM,WAAW,WAAW;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,SAAS,GAAG,WAAW,CAAA;CACjC;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,KAAK,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACZ;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.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,17 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unibridge/sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "UniBridge is a TypeScript SDK for interacting with the Unity Editor.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "node --test src/*.test.ts src/**/*.test.ts",
|
|
8
8
|
"build": "tsc -p tsconfig.json",
|
|
9
9
|
"prepublishOnly": "npm run build"
|
|
10
10
|
},
|
|
11
|
-
"keywords": [
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
"keywords": [
|
|
12
|
+
"unibridge",
|
|
13
|
+
"unity",
|
|
14
|
+
"sdk",
|
|
15
|
+
"typescript",
|
|
16
|
+
"automation"
|
|
17
|
+
],
|
|
18
|
+
"author": {
|
|
19
|
+
"name": "Marcus Sanatan",
|
|
20
|
+
"url": "https://gameboymarcus.com"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
14
23
|
"type": "module",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/msanatan/unibridge.git",
|
|
27
|
+
"directory": "packages/sdk"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/msanatan/unibridge/tree/main/packages/sdk",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/msanatan/unibridge/issues"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"README.md",
|
|
36
|
+
"LICENSE"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
15
41
|
"types": "./dist/index.d.ts",
|
|
16
42
|
"exports": {
|
|
17
43
|
".": "./dist/index.js"
|
package/src/client.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto'
|
|
2
|
-
import { PipeConnection } from './connection.ts'
|
|
3
|
-
import { pipePath } from './hash.ts'
|
|
4
|
-
import { findUnityProject } from './project.ts'
|
|
5
|
-
import type { ClientOptions, CommandResponse, UniBridgeClient } from './types.ts'
|
|
6
|
-
import { buildClientMethods } from './commands/define.ts'
|
|
7
|
-
import type { CommandRuntime, ExecuteGuard } from './commands/runtime.ts'
|
|
8
|
-
import { allCommands } from './commands/registry.ts'
|
|
9
|
-
|
|
10
|
-
export class UniBridgeError extends Error {
|
|
11
|
-
constructor(message: string) {
|
|
12
|
-
super(message)
|
|
13
|
-
this.name = 'UniBridgeError'
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function unwrap(response: CommandResponse): unknown {
|
|
18
|
-
if (!response.success) {
|
|
19
|
-
throw new UniBridgeError(response.error ?? 'Command failed')
|
|
20
|
-
}
|
|
21
|
-
return response.result
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function createRuntime(
|
|
25
|
-
sendCommand: (command: string, params: Record<string, unknown>) => Promise<CommandResponse>,
|
|
26
|
-
ensureExecuteEnabled: () => void,
|
|
27
|
-
): CommandRuntime & ExecuteGuard {
|
|
28
|
-
return {
|
|
29
|
-
async send(command: string, params: Record<string, unknown>): Promise<unknown> {
|
|
30
|
-
return unwrap(await sendCommand(command, params))
|
|
31
|
-
},
|
|
32
|
-
ensureExecuteEnabled,
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function createClient(options: ClientOptions = {}): UniBridgeClient {
|
|
37
|
-
const projectPath = options.projectPath ?? findUnityProject()
|
|
38
|
-
const connection = new PipeConnection({
|
|
39
|
-
projectPath,
|
|
40
|
-
connectTimeout: options.connectTimeout,
|
|
41
|
-
commandTimeout: options.commandTimeout,
|
|
42
|
-
reconnectTimeout: options.reconnectTimeout,
|
|
43
|
-
})
|
|
44
|
-
const callerExecuteEnabled = options.enableExecute ?? true
|
|
45
|
-
|
|
46
|
-
async function sendCommand(
|
|
47
|
-
command: string,
|
|
48
|
-
params: Record<string, unknown>,
|
|
49
|
-
): Promise<CommandResponse> {
|
|
50
|
-
await connection.connect(pipePath(projectPath))
|
|
51
|
-
return connection.send({ id: randomUUID(), command, params })
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function ensureExecuteEnabled(): void {
|
|
55
|
-
if (!callerExecuteEnabled) {
|
|
56
|
-
throw new UniBridgeError('Execute is disabled by client or plugin configuration.')
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const metadata = connection.serverMetadata()
|
|
60
|
-
const serverExecuteEnabled = metadata?.capabilities?.executeEnabled ?? true
|
|
61
|
-
if (!serverExecuteEnabled) {
|
|
62
|
-
throw new UniBridgeError('Execute is disabled by client or plugin configuration.')
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const runtime = createRuntime(sendCommand, ensureExecuteEnabled)
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
projectPath,
|
|
70
|
-
...buildClientMethods(runtime, allCommands),
|
|
71
|
-
close(): void {
|
|
72
|
-
connection.disconnect()
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type { DomainReloadResult } from './domain/contract.ts'
|
|
2
|
-
export type { ExecuteResult } from './execute/contract.ts'
|
|
3
|
-
export type { SceneActiveResult, SceneCreateResult, SceneInfo, SceneOpenResult } from './scene/contract.ts'
|
|
4
|
-
export type { StatusResult } from './status/contract.ts'
|
package/src/commands/define.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot'
|
|
2
|
-
import type { CommandRuntime, ExecuteGuard } from './runtime.ts'
|
|
3
|
-
|
|
4
|
-
export interface CommandDef<
|
|
5
|
-
TMethod extends string,
|
|
6
|
-
TArgs extends unknown[],
|
|
7
|
-
TResult,
|
|
8
|
-
> {
|
|
9
|
-
readonly method: TMethod
|
|
10
|
-
readonly wire: string
|
|
11
|
-
readonly params: (...args: TArgs) => Record<string, unknown>
|
|
12
|
-
readonly result: v.GenericSchema<unknown, TResult>
|
|
13
|
-
readonly guard?: 'execute'
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function defineCommand<
|
|
17
|
-
TMethod extends string,
|
|
18
|
-
TArgs extends unknown[],
|
|
19
|
-
TResult,
|
|
20
|
-
>(def: CommandDef<TMethod, TArgs, TResult>): CommandDef<TMethod, TArgs, TResult> {
|
|
21
|
-
return def
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
export type InferResult<T> = T extends CommandDef<string, any[], infer R> ? R : never
|
|
26
|
-
|
|
27
|
-
type CommandMethod<T> = T extends CommandDef<string, infer TArgs, infer TResult>
|
|
28
|
-
? (...args: TArgs) => Promise<TResult>
|
|
29
|
-
: never
|
|
30
|
-
|
|
31
|
-
export type CommandMethods<T extends readonly CommandDef<string, any[], any>[]> = {
|
|
32
|
-
[K in T[number] as K['method']]: CommandMethod<K>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export async function invokeCommand<TArgs extends unknown[], TResult>(
|
|
36
|
-
def: CommandDef<string, TArgs, TResult>,
|
|
37
|
-
runtime: CommandRuntime & ExecuteGuard,
|
|
38
|
-
...args: TArgs
|
|
39
|
-
): Promise<TResult> {
|
|
40
|
-
if (def.guard === 'execute') {
|
|
41
|
-
runtime.ensureExecuteEnabled()
|
|
42
|
-
}
|
|
43
|
-
const params = def.params(...args)
|
|
44
|
-
const raw = await runtime.send(def.wire, params)
|
|
45
|
-
return v.parse(def.result, raw)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function buildClientMethods<
|
|
49
|
-
const T extends readonly CommandDef<string, any[], any>[],
|
|
50
|
-
>(runtime: CommandRuntime & ExecuteGuard, defs: T): CommandMethods<T> {
|
|
51
|
-
const methods: Record<string, (...args: unknown[]) => Promise<unknown>> = {}
|
|
52
|
-
for (const def of defs) {
|
|
53
|
-
methods[def.method] = (...args: unknown[]) => invokeCommand(def, runtime, ...args)
|
|
54
|
-
}
|
|
55
|
-
return methods as CommandMethods<T>
|
|
56
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot'
|
|
2
|
-
import { defineCommand, type InferResult } from '../define.ts'
|
|
3
|
-
|
|
4
|
-
export const DomainReloadResultSchema = v.object({
|
|
5
|
-
triggered: v.boolean(),
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
export const domainReloadCommand = defineCommand({
|
|
9
|
-
method: 'domainReload',
|
|
10
|
-
wire: 'domain.reload',
|
|
11
|
-
params: () => ({}),
|
|
12
|
-
result: DomainReloadResultSchema,
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
export type DomainReloadResult = InferResult<typeof domainReloadCommand>
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot'
|
|
2
|
-
import { defineCommand, type InferResult } from '../define.ts'
|
|
3
|
-
|
|
4
|
-
export const executeCommand = defineCommand({
|
|
5
|
-
method: 'execute',
|
|
6
|
-
wire: 'execute',
|
|
7
|
-
params: (code: string) => ({ code }),
|
|
8
|
-
result: v.unknown(),
|
|
9
|
-
guard: 'execute',
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
export type ExecuteResult = InferResult<typeof executeCommand>
|
package/src/commands/registry.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { domainReloadCommand } from './domain/contract.ts'
|
|
2
|
-
import { executeCommand } from './execute/contract.ts'
|
|
3
|
-
import { sceneActiveCommand, sceneCreateCommand, sceneOpenCommand } from './scene/contract.ts'
|
|
4
|
-
import { statusCommand } from './status/contract.ts'
|
|
5
|
-
|
|
6
|
-
export const allCommands = [domainReloadCommand, executeCommand, statusCommand, sceneActiveCommand, sceneCreateCommand, sceneOpenCommand] as const
|
package/src/commands/runtime.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot'
|
|
2
|
-
import { defineCommand, type InferResult } from '../define.ts'
|
|
3
|
-
|
|
4
|
-
const SceneInfoSchema = v.object({
|
|
5
|
-
name: v.string(),
|
|
6
|
-
path: v.string(),
|
|
7
|
-
isDirty: v.boolean(),
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
export const SceneActiveResultSchema = v.object({
|
|
11
|
-
scene: SceneInfoSchema,
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export const sceneActiveCommand = defineCommand({
|
|
15
|
-
method: 'sceneActive',
|
|
16
|
-
wire: 'scene.active',
|
|
17
|
-
params: () => ({}),
|
|
18
|
-
result: SceneActiveResultSchema,
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
export const SceneOpenResultSchema = v.object({
|
|
22
|
-
scene: SceneInfoSchema,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
export const sceneOpenCommand = defineCommand({
|
|
26
|
-
method: 'sceneOpen',
|
|
27
|
-
wire: 'scene.open',
|
|
28
|
-
params: (path: string) => ({ path }),
|
|
29
|
-
result: SceneOpenResultSchema,
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
export const SceneCreateResultSchema = v.object({
|
|
33
|
-
scene: SceneInfoSchema,
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
export const sceneCreateCommand = defineCommand({
|
|
37
|
-
method: 'sceneCreate',
|
|
38
|
-
wire: 'scene.create',
|
|
39
|
-
params: (path: string) => ({ path }),
|
|
40
|
-
result: SceneCreateResultSchema,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
export type SceneInfo = v.InferOutput<typeof SceneInfoSchema>
|
|
44
|
-
export type SceneActiveResult = InferResult<typeof sceneActiveCommand>
|
|
45
|
-
export type SceneOpenResult = InferResult<typeof sceneOpenCommand>
|
|
46
|
-
export type SceneCreateResult = InferResult<typeof sceneCreateCommand>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot'
|
|
2
|
-
import { defineCommand, type InferResult } from '../define.ts'
|
|
3
|
-
|
|
4
|
-
export const StatusResultSchema = v.object({
|
|
5
|
-
projectPath: v.string(),
|
|
6
|
-
unityVersion: v.string(),
|
|
7
|
-
pluginVersion: v.string(),
|
|
8
|
-
activeScene: v.string(),
|
|
9
|
-
playMode: v.string(),
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
export const statusCommand = defineCommand({
|
|
13
|
-
method: 'status',
|
|
14
|
-
wire: 'status',
|
|
15
|
-
params: () => ({}),
|
|
16
|
-
result: StatusResultSchema,
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
export type StatusResult = InferResult<typeof statusCommand>
|