diff --git a/CHANGELOG.md b/CHANGELOG.md index cbbbcfa..f2f553f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.2.0 — remove the compute envelope + +- Remove the `exfa/compute@1` / `exfa/compute-result@1` envelope: the `computeRequest` / `compute_request` helpers, the `Compute*` TypeScript types and `schema/compute.schema.json`. The engine no longer has a `compute` entry; use `resolve` (a fully resolved FitRequest) with the engine's `calc`, or `batch`. +- `compileGroup` now returns a plain engine BatchRequest, `{ batch_version: 1, fits: [{ id, label, fit }] }`, instead of an envelope-wrapped one (**breaking**: read `request.fits`, not `request.batch.fits`). +- Shorthand defaults (skill presets, module states) are a Format concern; they are not part of this release. + ## 1.1.0 — next-stage compute media - Add `exfa/compute@1` request envelopes (`computeRequest`), `exfa/group@1` documents (`newGroup`, `compileGroup` lowering to `batch.fits` with `project`/`command` relations and per-item `select`), and `exfa/package@1` exchange packages (`packageFit`, `packageGroup`, `mergePackage`) plus the `exfa/workspace@1` type. diff --git a/fixtures/engine/README.md b/fixtures/engine/README.md index d361013..ae22073 100644 --- a/fixtures/engine/README.md +++ b/fixtures/engine/README.md @@ -1,5 +1,5 @@ # Engine contract fixture -`fit-request.schema.json` is copied from EXFA-Engine (`contract/schema/fit-request.schema.json`, tag `v0.2.0`) and extended for the `exfa/compute@1` contract: equipment entries accept an optional `id` (host-assigned stable id), and projected `kind:"fit"` entries accept an optional `select` whitelist (`module_ids`/`drone_ids`/`fighter_ids`). +`fit-request.schema.json` is copied from EXFA-Engine (`contract/schema/fit-request.schema.json`, tag `v0.2.0`) and extended for host-assigned item ids: equipment entries accept an optional `id` (host-assigned stable id), and projected `kind:"fit"` entries accept an optional `select` whitelist (`module_ids`/`drone_ids`/`fighter_ids`). There is a contract/schema mismatch with the current App adapter: App `toRequest` deliberately emits explicit `null` for optional request values (for example `ship.mode_type_id`, module `charge_type_id`/`mutation`/`spool`, and absent damage/target profiles), and passes the UI security labels `hisec`/`wspace` through unchanged. The v0.2.0 schema does not accept those nulls and only lists `highsec`/`wormhole`. Changing `resolve` would break the required App request parity. The TypeScript fixture checks therefore validate the raw request against a narrowly widened copy of the schema and validate a schema-normalized view against the unmodified Engine schema. The upstream file remains unchanged. diff --git a/package.json b/package.json index f232c50..80f6ad3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@exfa/format", - "version": "1.1.0", + "version": "1.2.0", "description": "EXFA fit library and document format", "type": "module", "license": "LGPL-3.0-or-later", diff --git a/rust/Cargo.lock b/rust/Cargo.lock index a4256d3..cd6f739 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "exfa-format" -version = "1.1.0" +version = "1.2.0" dependencies = [ "serde", "serde_json", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index efe26c9..57d8c79 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "exfa-format" -version = "1.1.0" +version = "1.2.0" edition = "2021" license = "LGPL-3.0-or-later" description = "EXFA fit library and document format" diff --git a/rust/src/compute.rs b/rust/src/compute.rs deleted file mode 100644 index 5577e9b..0000000 --- a/rust/src/compute.rs +++ /dev/null @@ -1,14 +0,0 @@ -use crate::resolve::{apply_branch, resolve_fit_document, ResolveOptions}; -use crate::types::{FitDocument, Library}; -use crate::FormatError; -use serde_json::{json, Value}; - -/// Resolves a host document into an `exfa/compute@1` `calc` request envelope (FitSpec inside). -pub fn compute_request(library: &Library, document: &FitDocument, options: ResolveOptions) -> Result { - let effective = match &options.branch { - Some(branch) => apply_branch(document, branch)?, - None => document.clone(), - }; - let fit = resolve_fit_document(&effective, library, 0)?; - Ok(json!({ "format": "exfa/compute@1", "operation": "calc", "fit": fit })) -} diff --git a/rust/src/group.rs b/rust/src/group.rs index 52f056b..1e76ac6 100644 --- a/rust/src/group.rs +++ b/rust/src/group.rs @@ -21,7 +21,7 @@ pub struct CompiledGroup { pub issues: Vec, } -/// Lowers a group into one `exfa/compute@1` batch request: every actor resolves to a `batch.fits[]` entry, +/// Lowers a group into one engine BatchRequest: every actor resolves to a `batch.fits[]` entry, /// `project` relations push `{kind:"fit"}` entries (with a strict-whitelist `select` when the relation names /// `source_item_ids`) onto the target's `projected[]`, and `command` relations push the source request onto the /// target's `fleet.booster_fits[]`. Problems are reported as issues, not returned as errors. @@ -111,11 +111,7 @@ pub fn compile_group(library: &Library, group: &Group, options: &ResolveOptions) }) }).collect::>(); Ok(CompiledGroup { - request: json!({ - "format": "exfa/compute@1", - "operation": "batch", - "batch": { "batch_version": 1, "fits": fits }, - }), + request: json!({ "batch_version": 1, "fits": fits }), issues, }) } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 2788412..b96062e 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1,4 +1,3 @@ -pub mod compute; pub mod files; pub mod group; pub mod migrate; @@ -29,7 +28,6 @@ impl Display for FormatError { impl std::error::Error for FormatError {} -pub use compute::compute_request; pub use files::{from_files, read_directory, to_files, write_directory, FormatFile}; pub use group::{compile_group, new_group, CompiledGroup}; pub use migrate::{migrate, migrate_fit_document}; diff --git a/rust/tests/format.rs b/rust/tests/format.rs index a44aa2c..0a56732 100644 --- a/rust/tests/format.rs +++ b/rust/tests/format.rs @@ -1,5 +1,5 @@ use exfa_format::{ - compile_group, compute_request, from_files, merge_package, migrate, package_fit, package_group, + compile_group, from_files, merge_package, migrate, package_fit, package_group, read_directory, resolve, resolve_with_options, to_files, write_directory, Group, Library, MergePolicy, Package, ResolveOptions, }; @@ -114,11 +114,6 @@ fn resolve_passes_item_ids_through() { assert_eq!(request["drones"][0]["id"], json!("drone-1")); assert_eq!(request["fighters"][0]["id"], json!("ftr-1")); assert_eq!(request["cargo"][0]["id"], json!("cargo-1")); - let document = library.fits.get("app-basic").expect("fixture fit should exist").clone(); - let request = compute_request(&library, &document, ResolveOptions::default()).expect("compute request should build"); - assert_eq!(request["format"], json!("exfa/compute@1")); - assert_eq!(request["operation"], json!("calc")); - assert_eq!(request["fit"]["modules"][0]["id"], json!("mod-1")); } #[test] @@ -188,10 +183,8 @@ fn compile_group_projects_with_select_and_commands() { })).expect("group should deserialize"); let compiled = compile_group(&library, &group, &ResolveOptions::default()).expect("group should compile"); let request = &compiled.request; - assert_eq!(request["format"], json!("exfa/compute@1")); - assert_eq!(request["operation"], json!("batch")); - assert_eq!(request["batch"]["batch_version"], json!(1)); - let fits = request["batch"]["fits"].as_array().expect("fits list"); + assert_eq!(request["batch_version"], json!(1)); + let fits = request["fits"].as_array().expect("fits list"); assert_eq!(fits.iter().map(|entry| entry["id"].as_str().unwrap()).collect::>(), ["logi", "a", "b"]); assert_eq!(fits[0]["label"], json!("Logi")); assert_eq!(fits[1]["label"], json!("Doc a")); diff --git a/schema/compute.schema.json b/schema/compute.schema.json deleted file mode 100644 index 9245c8a..0000000 --- a/schema/compute.schema.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://github.com/EX-CT/EXFA-Format/schema/compute.schema.json", - "title": "EXFA Compute Request v1", - "description": "Envelope shared with the engine. `fit` holds a FitSpec (the engine FitRequest shape plus optional entry `id`s and `select` on projected fit entries); `batch` holds a BatchSpec (the engine BatchRequest).", - "oneOf": [ - { - "type": "object", - "required": ["format", "operation", "fit"], - "properties": { - "format": { "const": "exfa/compute@1" }, - "operation": { "const": "calc" }, - "fit": { "type": "object" } - }, - "additionalProperties": true - }, - { - "type": "object", - "required": ["format", "operation", "batch"], - "properties": { - "format": { "const": "exfa/compute@1" }, - "operation": { "const": "batch" }, - "batch": { "type": "object" } - }, - "additionalProperties": true - } - ] -} diff --git a/ts/package.json b/ts/package.json index db6471b..3b9ae42 100644 --- a/ts/package.json +++ b/ts/package.json @@ -1,6 +1,6 @@ { "name": "@exfa/format", - "version": "1.1.0", + "version": "1.2.0", "description": "EXFA fit library and document format", "type": "module", "license": "LGPL-3.0-or-later", diff --git a/ts/scripts/engine-schema.mjs b/ts/scripts/engine-schema.mjs index 133a11d..673e0d8 100644 --- a/ts/scripts/engine-schema.mjs +++ b/ts/scripts/engine-schema.mjs @@ -100,7 +100,6 @@ export async function loadFormatSchemas() { readJson('schema/library-index.schema.json'), readJson('schema/package.schema.json'), readJson('schema/workspace.schema.json'), - readJson('schema/compute.schema.json'), ]); const ajv = new Ajv2020({ allErrors: true, strict: false }); addFormats(ajv); @@ -112,7 +111,6 @@ export async function loadFormatSchemas() { validateLibraryIndex: ajv.getSchema('https://github.com/EX-CT/EXFA-Format/schema/library-index.schema.json'), validatePackage: ajv.getSchema('https://github.com/EX-CT/EXFA-Format/schema/package.schema.json'), validateWorkspace: ajv.getSchema('https://github.com/EX-CT/EXFA-Format/schema/workspace.schema.json'), - validateCompute: ajv.getSchema('https://github.com/EX-CT/EXFA-Format/schema/compute.schema.json'), }; } diff --git a/ts/src/compute.ts b/ts/src/compute.ts deleted file mode 100644 index 0d6b58d..0000000 --- a/ts/src/compute.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { applyBranch } from './branches.js'; -import { resolveFit } from './resolve.js'; -import type { FitDocument, JsonObject, Library, ResolveOptions } from './types.js'; - -// Wire envelope shared with the engine (`exfa/compute@1` requests, `exfa/compute-result@1` responses). -// `fit` holds a FitSpec (the engine FitRequest shape plus optional entry `id`s); `batch` holds a BatchSpec -// (the engine BatchRequest: batch_version, exactly one of fits/variants/product/sweep, fields, deltas, ...). -export interface ComputeCalcRequest { format: 'exfa/compute@1'; operation: 'calc'; fit: JsonObject } -export interface ComputeBatchRequest { format: 'exfa/compute@1'; operation: 'batch'; batch: JsonObject } -export type ComputeRequest = ComputeCalcRequest | ComputeBatchRequest; - -export interface ComputeError { code: string; message: string; path?: string } -export interface ComputeCalcResult { format: 'exfa/compute-result@1'; operation: 'calc'; result?: JsonObject; error?: ComputeError } -export interface ComputeBatchResult { format: 'exfa/compute-result@1'; operation: 'batch'; result?: JsonObject; error?: ComputeError } -export type ComputeResult = ComputeCalcResult | ComputeBatchResult; - -/** Resolves a host document into a `calc` compute request envelope (FitSpec inside). */ -export function computeRequest(library: Library, doc: FitDocument, options: ResolveOptions = {}): ComputeCalcRequest { - const effective = options.branch ? applyBranch(doc, options.branch) : doc; - const fit = resolveFit(effective.fit, { library, depth: 0, document_id: effective.id, refs: effective.refs, links: effective.links }); - return { format: 'exfa/compute@1', operation: 'calc', fit }; -} diff --git a/ts/src/group.ts b/ts/src/group.ts index f8ab962..17a3107 100644 --- a/ts/src/group.ts +++ b/ts/src/group.ts @@ -1,5 +1,4 @@ import { applyBranch } from './branches.js'; -import type { ComputeBatchRequest } from './compute.js'; import { resolveFit } from './resolve.js'; import type { FitDocument, FitRequest, FitRequestProjected, Group, Library, ProjectedFitSelect, ResolveOptions } from './types.js'; @@ -11,13 +10,19 @@ export function newGroup(name?: string, id?: string): Group { return { format: 'exfa/group@1', id: id ?? uid(), name: name ?? 'New group', actors: [], relations: [] }; } +/** An engine BatchRequest (`fits` form): one resolved FitRequest per group actor. */ +export interface GroupBatchRequest { + batch_version: 1; + fits: { id: string; label: string; fit: FitRequest }[]; +} + export interface CompiledGroup { - request: ComputeBatchRequest; + request: GroupBatchRequest; issues: string[]; } /** - * Lowers a group into one `exfa/compute@1` batch request: every actor resolves to a `batch.fits[]` entry, + * Lowers a group into one engine BatchRequest: every actor resolves to a `fits[]` entry, * `project` relations push `{kind:'fit'}` entries (with a strict-whitelist `select` when the relation names * `source_item_ids`) onto the target's `projected[]`, and `command` relations push the source request onto the * target's `fleet.booster_fits[]`. Problems are reported as issues, not thrown. @@ -87,7 +92,7 @@ export function compileGroup(library: Library, group: Group, options: ResolveOpt return entry ? [{ id: actor.id, label: actor.label ?? entry.doc.name, fit: entry.request }] : []; }); return { - request: { format: 'exfa/compute@1', operation: 'batch', batch: { batch_version: 1, fits } }, + request: { batch_version: 1, fits }, issues, }; } diff --git a/ts/src/index.ts b/ts/src/index.ts index 04bd344..625414f 100644 --- a/ts/src/index.ts +++ b/ts/src/index.ts @@ -1,6 +1,5 @@ export * from './types.js'; export * from './branches.js'; -export * from './compute.js'; export * from './files.js'; export * from './group.js'; export * from './history.js'; diff --git a/ts/test/compute.test.ts b/ts/test/compute.test.ts deleted file mode 100644 index dde3679..0000000 --- a/ts/test/compute.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { readFileSync } from 'node:fs'; -import { describe, expect, it } from 'vitest'; -import { computeRequest, resolve, type Library } from '../src'; -import { fixturePath, loadFormatSchemas } from '../scripts/engine-schema.mjs'; - -const library = JSON.parse(readFileSync(fixturePath('fixtures/library.json'), 'utf8')) as Library; - -describe('compute request envelope', () => { - it('wraps the resolved FitSpec in an exfa/compute@1 calc envelope', () => { - const request = computeRequest(library, library.fits['app-basic']); - expect(request).toMatchObject({ format: 'exfa/compute@1', operation: 'calc' }); - expect(request.fit).toEqual(resolve(library, 'app-basic')); - }); - - it('applies the selected branch before wrapping', () => { - const request = computeRequest(library, library.fits.complex, { branch: 'budget' }); - const modules = (request.fit as { modules: { type_id: number; charge_type_id: number | null }[] }).modules; - expect(modules.map((module) => module.type_id)).toEqual([2874, 2874]); - expect(modules.map((module) => module.charge_type_id)).toEqual([21899, 21899]); - }); - - it('passes item ids through into the FitSpec', () => { - const document = structuredClone(library.fits['app-basic']); - document.fit.modules[0].id = 'mod-1'; - const request = computeRequest(library, document); - expect((request.fit.modules as { id?: string }[])[0].id).toBe('mod-1'); - }); - - it('validates the calc and batch envelopes against compute.schema.json', async () => { - const validators = await loadFormatSchemas(); - const request = computeRequest(library, library.fits['app-basic']); - expect(validators.validateCompute?.(request), JSON.stringify(validators.validateCompute?.errors)).toBe(true); - const batch = { format: 'exfa/compute@1', operation: 'batch', batch: { batch_version: 1, fits: [] } }; - expect(validators.validateCompute?.(batch), JSON.stringify(validators.validateCompute?.errors)).toBe(true); - const wrong = { format: 'exfa/compute@1', operation: 'calc' }; - expect(validators.validateCompute?.(wrong)).toBe(false); - }); -}); diff --git a/ts/test/group.test.ts b/ts/test/group.test.ts index f47d776..867410e 100644 --- a/ts/test/group.test.ts +++ b/ts/test/group.test.ts @@ -8,7 +8,7 @@ import { type Group, type Library, } from '../src'; -import { loadFormatSchemas } from '../scripts/engine-schema.mjs'; +import { loadEngineValidators } from '../scripts/engine-schema.mjs'; const makeDoc = (id: string, name: string, fit?: Partial): FitDocument => ({ format: 'exfa/fit@1', @@ -59,8 +59,7 @@ const makeLibrary = (): Library => ({ groups: {}, }); -const fitsOf = (request: { batch: Record }) => - request.batch.fits as { id: string; label: string; fit: FitRequest }[]; +const fitsOf = (request: { fits: { id: string; label: string; fit: FitRequest }[] }) => request.fits; describe('newGroup', () => { it('creates an empty exfa/group@1 document with a generated id', () => { @@ -85,16 +84,17 @@ describe('compileGroup', () => { }; const { request, issues } = compileGroup(library, group); expect(issues).toEqual([]); - expect(request).toMatchObject({ format: 'exfa/compute@1', operation: 'batch' }); - expect(request.batch.batch_version).toBe(1); + expect(request.batch_version).toBe(1); const fits = fitsOf(request); expect(fits.map((entry) => entry.id)).toEqual(['logi', 'dps']); expect(fits[0].label).toBe('Logi'); expect(fits[1].label).toBe('DPS A'); expect(fits[0].fit.modules.map((module) => module.id)).toEqual(['rep-1', 'rep-2']); - const validators = await loadFormatSchemas(); - expect(validators.validateCompute?.(request), JSON.stringify(validators.validateCompute?.errors)).toBe(true); + const { validateAppCompatible } = await loadEngineValidators(); + for (const entry of fits) { + expect(validateAppCompatible(entry.fit), JSON.stringify(validateAppCompatible.errors)).toBe(true); + } }); it('projects the full source fit with a classified select whitelist', () => {