@odigos/vmagent-api-apollo-client 0.9.0 → 0.11.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/dist/index.js CHANGED
@@ -1 +1,13 @@
1
- export * from './generated/graphql';
1
+ // Public entrypoint. The version-specific surface (flat latest-dialect exports +
2
+ // per-dialect namespaces) is GENERATED into ./generated/surface by
3
+ // scripts/gen-dialect-manifest.mjs, so this file is static and never needs
4
+ // editing when a snapshot is added.
5
+ //
6
+ // - Flat imports (e.g. `import { GetWorkloadReportsV2Document } from
7
+ // '@odigos/vmagent-api-apollo-client'`) resolve to the latest dialect.
8
+ // - Per-dialect namespaces (`v0_6_0`, `v0_8_0`, `next`, ...) target a specific
9
+ // dialect explicitly.
10
+ export * from "./generated/surface";
11
+ // Dialect registry: the `dialects` map, `resolveDialect`, version constants,
12
+ // and types for picking a dialect per connected VM-agent version.
13
+ export * from "./registry";
@@ -0,0 +1,6 @@
1
+ import { dialects, NEXT_DIALECT, LATEST_DIALECT_VERSION } from "./generated/dialects";
2
+ export { dialects, NEXT_DIALECT, LATEST_DIALECT_VERSION };
3
+ export type DialectVersion = keyof typeof dialects;
4
+ export type Dialect = (typeof dialects)[DialectVersion];
5
+ export declare function resolveDialectVersion(reported: string): DialectVersion;
6
+ export declare function resolveDialect(reported: string): Dialect;
@@ -0,0 +1,46 @@
1
+ // Dialect registry: resolves which frozen dialect a consumer should use for a
2
+ // connected agent. The package ships every dialect (see codegen.ts); central-ui
3
+ // passes the VM proxy's reported version to resolveDialect() and prints the
4
+ // matching document, so it never selects fields the agent's schema lacks.
5
+ //
6
+ // The `dialects` map and version constants are GENERATED into
7
+ // ./generated/dialects (by scripts/gen-dialect-manifest.mjs, run as part of
8
+ // `npm run codegen`) directly from the graphql/snapshots directory. This file
9
+ // is hand-written and holds only the resolution logic -- it never needs editing
10
+ // when a new snapshot is added.
11
+ import { dialects, NEXT_DIALECT, LATEST_DIALECT_VERSION, } from "./generated/dialects";
12
+ export { dialects, NEXT_DIALECT, LATEST_DIALECT_VERSION };
13
+ function parseVersion(version) {
14
+ const core = version.trim().replace(/^v/i, "").split("-")[0];
15
+ const [major = 0, minor = 0, patch = 0] = core
16
+ .split(".")
17
+ .map((part) => parseInt(part, 10) || 0);
18
+ return [major, minor, patch];
19
+ }
20
+ function compareVersions(a, b) {
21
+ const pa = parseVersion(a);
22
+ const pb = parseVersion(b);
23
+ for (let i = 0; i < 3; i += 1) {
24
+ if (pa[i] !== pb[i])
25
+ return pa[i] - pb[i];
26
+ }
27
+ return 0;
28
+ }
29
+ const SORTED_VERSIONS = Object.keys(dialects).sort(compareVersions);
30
+ // Resolution: exact match if a snapshot equals the reported version; otherwise
31
+ // the greatest snapshot <= reported (floor). Flooring is the safe choice -- the
32
+ // schema only grows, so an older-or-equal dialect never selects fields the
33
+ // agent is missing. A reported version newer than every snapshot floors to the
34
+ // latest. A reported version older than every snapshot falls back to the
35
+ // lowest known dialect (best effort; nothing safer is available).
36
+ export function resolveDialectVersion(reported) {
37
+ let floor;
38
+ for (const version of SORTED_VERSIONS) {
39
+ if (compareVersions(version, reported) <= 0)
40
+ floor = version;
41
+ }
42
+ return floor ?? SORTED_VERSIONS[0];
43
+ }
44
+ export function resolveDialect(reported) {
45
+ return dialects[resolveDialectVersion(reported)];
46
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odigos/vmagent-api-apollo-client",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Generated Apollo TypeScript client for the VM-agent GraphQL API",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -14,13 +14,23 @@
14
14
  "types": "./dist/index.d.ts",
15
15
  "import": "./dist/index.js",
16
16
  "require": "./dist/index.js"
17
+ },
18
+ "./registry": {
19
+ "types": "./dist/registry.d.ts",
20
+ "import": "./dist/registry.js",
21
+ "require": "./dist/registry.js"
22
+ },
23
+ "./next": {
24
+ "types": "./dist/generated/next/graphql.d.ts",
25
+ "import": "./dist/generated/next/graphql.js",
26
+ "require": "./dist/generated/next/graphql.js"
17
27
  }
18
28
  },
19
29
  "publishConfig": {
20
30
  "access": "public"
21
31
  },
22
32
  "scripts": {
23
- "codegen": "graphql-codegen --config codegen.ts",
33
+ "codegen": "graphql-codegen --config codegen.ts && node scripts/gen-dialect-manifest.mjs",
24
34
  "build": "tsc -p tsconfig.json"
25
35
  },
26
36
  "dependencies": {