@ankhorage/api 0.3.0 → 0.3.1
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/CHANGELOG.md +6 -0
- package/README.md +45 -6
- package/dist/capabilities/index.js.map +1 -1
- package/dist/features/execution/projectApiCapabilities.d.ts +1 -1
- package/dist/features/execution/projectApiCapabilities.d.ts.map +1 -1
- package/dist/features/execution/projectApiCapabilities.js +1 -1
- package/dist/features/execution/projectApiCapabilities.js.map +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -3,22 +3,61 @@
|
|
|
3
3
|
|
|
4
4
|
# @ankhorage/api
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
        
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
bindings, dispatches application handlers, and exposes a transport-adapter boundary without
|
|
10
|
-
depending on Fastify, Next.js, React, or another server framework.
|
|
8
|
+
Framework-neutral executable API runtime for Ankhorage.
|
|
11
9
|
|
|
12
10
|
## Usage
|
|
13
11
|
|
|
12
|
+
### CLI
|
|
13
|
+
|
|
14
|
+
Ankhorage packages expose their command-line interface through `ankh`. Use `ankh --help` to discover available package commands, or run a package command with `--help` for package-specific usage.
|
|
15
|
+
|
|
16
|
+
```zsh
|
|
17
|
+
# Install the Ankhorage CLI
|
|
18
|
+
bun add --global @ankhorage/ankh
|
|
19
|
+
|
|
20
|
+
# Show usage information for api
|
|
21
|
+
ankh api --help
|
|
22
|
+
```
|
|
23
|
+
|
|
14
24
|
### Basic Usage
|
|
15
25
|
|
|
16
26
|
`@ankhorage/api` executes portable internal REST API definitions without coupling application
|
|
17
27
|
handlers to Fastify, Next.js, or another HTTP framework. Framework packages adapt requests and
|
|
18
28
|
responses at the transport edge while this runtime owns operation lookup and dispatch.
|
|
19
29
|
|
|
20
|
-
|
|
30
|
+
```ts
|
|
31
|
+
const definition = {
|
|
32
|
+
id: "health-api",
|
|
33
|
+
origin: "internal",
|
|
34
|
+
protocol: "rest",
|
|
35
|
+
basePath: "/api",
|
|
36
|
+
endpoints: {
|
|
37
|
+
health: {
|
|
38
|
+
id: "health",
|
|
39
|
+
kind: "http",
|
|
40
|
+
operations: {
|
|
41
|
+
"health.read": {
|
|
42
|
+
id: "health.read",
|
|
43
|
+
protocol: "http",
|
|
44
|
+
intent: "read",
|
|
45
|
+
method: "GET",
|
|
46
|
+
path: "/health",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
} satisfies InternalRestApiDefinition;
|
|
52
|
+
```
|
|
21
53
|
|
|
22
54
|
## Generated documentation
|
|
23
55
|
|
|
24
|
-
|
|
56
|
+
- [Interactive documentation app](././paradox/index.html)
|
|
57
|
+
- [Public API reference](././paradox/exports.md)
|
|
58
|
+
- [Component registry](././paradox/components.md)
|
|
59
|
+
- [Architecture overview](././paradox/diagrams/architecture-overview.mmd)
|
|
60
|
+
- [Module relationships](././paradox/diagrams/module-relationships.mmd)
|
|
61
|
+
- [Export graph](././paradox/diagrams/export-graph.mmd)
|
|
62
|
+
- [createApiRuntime sequence](././paradox/diagrams/sequences/create-api-runtime.mmd)
|
|
63
|
+
- [projectApiCapabilities sequence](././paradox/diagrams/sequences/project-api-capabilities.mmd)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/capabilities/index.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,EAA2C,CAAC","sourcesContent":["import type { Capability } from \"@ankhorage/contracts/
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/capabilities/index.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,EAA2C,CAAC","sourcesContent":["import type { Capability } from \"@ankhorage/contracts/capability\";\n\n/**\n * Static API package capabilities.\n *\n * Executable API operations are dynamic and are projected from authored API definitions by\n * `projectApiCapabilities`; they are intentionally not duplicated in this static catalog.\n */\nexport const CAPABILITIES = [] as const satisfies readonly Capability[];\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Capability } from "@ankhorage/contracts/capability";
|
|
2
2
|
import type { InternalRestApiDefinition } from "@ankhorage/contracts/data";
|
|
3
3
|
/*** Project one internal REST API definition into canonical invocable API capabilities. */
|
|
4
4
|
export declare function projectApiCapabilities(definition: InternalRestApiDefinition): readonly Capability[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectApiCapabilities.d.ts","sourceRoot":"","sources":["../../../src/features/execution/projectApiCapabilities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"projectApiCapabilities.d.ts","sourceRoot":"","sources":["../../../src/features/execution/projectApiCapabilities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAMV,yBAAyB,EAC1B,MAAM,2BAA2B,CAAC;AAEnC,2FAA2F;AAC3F,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,yBAAyB,GACpC,SAAS,UAAU,EAAE,CAWvB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isCapabilityId
|
|
1
|
+
import { isCapabilityId } from "@ankhorage/capability";
|
|
2
2
|
/*** Project one internal REST API definition into canonical invocable API capabilities. */
|
|
3
3
|
export function projectApiCapabilities(definition) {
|
|
4
4
|
const capabilities = Object.values(definition.endpoints).flatMap((endpoint) => Object.values(endpoint.operations).map((operation) => projectApiOperationCapability(definition, operation)));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"projectApiCapabilities.js","sourceRoot":"","sources":["../../../src/features/execution/projectApiCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"projectApiCapabilities.js","sourceRoot":"","sources":["../../../src/features/execution/projectApiCapabilities.ts"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,CAAC;IAC/D,IAAI,IAAI,EAAE,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IACxE,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,kGAAkG;AAClG,SAAS,yBAAyB,CAChC,IAAgC;IAEhC,IAAI,IAAI,EAAE,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC;IACnD,IAAI,IAAI,EAAE,SAAS,KAAK,SAAS;QAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;IAClE,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,uGAAuG;AACvG,SAAS,yBAAyB,CAAC,YAAmC;IACpE,MAAM,IAAI,GAAG,IAAI,GAAG,EAAoB,CAAC;IACzC,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,KAAK,CACb,0CAA0C,UAAU,CAAC,EAAE,EAAE,CAC1D,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC","sourcesContent":["import { isCapabilityId } from \"@ankhorage/capability\";\nimport type { Capability } from \"@ankhorage/contracts/capability\";\nimport type {\n DataOperationConfig,\n DataOperationParameter,\n DataOperationRequest,\n DataSchema,\n DataSchemaSlot,\n InternalRestApiDefinition,\n} from \"@ankhorage/contracts/data\";\n\n/*** Project one internal REST API definition into canonical invocable API capabilities. */\nexport function projectApiCapabilities(\n definition: InternalRestApiDefinition,\n): readonly Capability[] {\n const capabilities = Object.values(definition.endpoints).flatMap((endpoint) =>\n Object.values(endpoint.operations).map((operation) =>\n projectApiOperationCapability(definition, operation),\n ),\n );\n\n assertUniqueCapabilityIds(capabilities);\n return [...capabilities].sort((left, right) =>\n left.id.localeCompare(right.id),\n );\n}\n\n/*** Project one authored API operation into its stable semantic capability descriptor. */\nfunction projectApiOperationCapability(\n definition: InternalRestApiDefinition,\n operation: DataOperationConfig,\n): Capability {\n const id = `api.${definition.id}.${operation.id}`;\n if (!isCapabilityId(id)) {\n throw new Error(\n `API operation projects to an invalid capability id: ${definition.id} / ${operation.id}`,\n );\n }\n\n const input = projectOperationInput(operation.request);\n const output = projectSchemaSlot(operation.response);\n\n return {\n id,\n owner: \"@ankhorage/api\",\n access: [\"invoke\"],\n binding: { kind: \"api\", bindableAs: [\"target\"] },\n label: operation.name ?? operation.id,\n ...(operation.description === undefined\n ? {}\n : { description: operation.description }),\n ...(input === undefined ? {} : { input }),\n ...(output === undefined ? {} : { output }),\n };\n}\n\n/*** Project request parameters and request body into the flat operation input value space. */\nfunction projectOperationInput(\n request: DataOperationRequest | undefined,\n): DataSchemaSlot | undefined {\n if (request === undefined) return undefined;\n\n const bodySchema = projectSchemaSlotAsSchema(request);\n const parameterSchema = projectOperationParameters(request.parameters);\n\n if (bodySchema === undefined) {\n return parameterSchema === undefined\n ? undefined\n : { schema: parameterSchema };\n }\n if (parameterSchema === undefined) return projectSchemaSlot(request);\n\n return {\n schema: {\n allOf: [bodySchema, parameterSchema],\n },\n };\n}\n\n/*** Project transport parameters into the flat object consumed by Runtime operation bindings. */\nfunction projectOperationParameters(\n parameters: readonly DataOperationParameter[] | undefined,\n): DataSchema | undefined {\n if (parameters === undefined || parameters.length === 0) return undefined;\n\n const properties: Record<string, DataSchema> = {};\n const required: string[] = [];\n for (const parameter of parameters) {\n if (Object.hasOwn(properties, parameter.name)) {\n throw new Error(\n `Duplicate API operation input parameter: ${parameter.name}`,\n );\n }\n properties[parameter.name] = projectOperationParameterSchema(parameter);\n if (parameter.required === true) required.push(parameter.name);\n }\n\n return {\n type: \"object\",\n properties,\n ...(required.length === 0 ? {} : { required: [...required].sort() }),\n };\n}\n\n/*** Preserve one parameter's schema reference plus parameter-specific description/default metadata. */\nfunction projectOperationParameterSchema(\n parameter: DataOperationParameter,\n): DataSchema {\n const schema = projectSchemaSlotAsSchema(parameter) ?? {};\n return {\n ...schema,\n ...(parameter.description === undefined\n ? {}\n : { description: parameter.description }),\n ...(parameter.default === undefined ? {} : { default: parameter.default }),\n };\n}\n\n/*** Preserve exactly one portable schema slot when the operation already owns one. */\nfunction projectSchemaSlot(\n slot: DataSchemaSlot | undefined,\n): DataSchemaSlot | undefined {\n if (slot?.schema !== undefined) return { schema: slot.schema };\n if (slot?.schemaRef !== undefined) return { schemaRef: slot.schemaRef };\n return undefined;\n}\n\n/*** Convert a schema slot to an embeddable schema while preserving authored schema references. */\nfunction projectSchemaSlotAsSchema(\n slot: DataSchemaSlot | undefined,\n): DataSchema | undefined {\n if (slot?.schema !== undefined) return slot.schema;\n if (slot?.schemaRef !== undefined) return { ref: slot.schemaRef };\n return undefined;\n}\n\n/*** Reject API definitions whose endpoint operations collide in the projected capability namespace. */\nfunction assertUniqueCapabilityIds(capabilities: readonly Capability[]): void {\n const seen = new Set<Capability[\"id\"]>();\n for (const capability of capabilities) {\n if (seen.has(capability.id)) {\n throw new Error(\n `Duplicate projected API capability id: ${capability.id}`,\n );\n }\n seen.add(capability.id);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/api",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Framework-neutral executable API runtime and transport contract for Ankhorage.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
"docs": "paradox"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@ankhorage/
|
|
65
|
+
"@ankhorage/capability": "^0.2.1",
|
|
66
|
+
"@ankhorage/contracts": "^26.0.0"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"@ankhorage/devtools": "^2.1.11",
|