@jini-ai/core 0.7.0 → 0.7.2

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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.7.2
2
+
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 873f10c: Adds the `@jini-ai/core/contracts/server` subpath: the types-only `Server` route contract on web `Request`/`Response`. It exports `ServerMethod` (including `HEAD` and `OPTIONS`), `ServerHandler` (handlers get `{ request, params, client? }`, where `client.address` is the socket peer), `ServerRoute` (one route as data, so a host can mount a package's route list) and `Server`. It also fixes route precedence: a literal segment beats a `:name` segment at the first position where they differ, and registration order never decides. Not exported from the root barrel.
8
+
1
9
  ## 0.7.0
2
10
 
3
11
  ### Minor Changes
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @file The server contract: register a handler for an HTTP method + path, where handlers speak
3
+ * the web-standard `Request` → `Response`. Route code in Jini packages takes `{ app: Server }`
4
+ * and never names a concrete server, so any host adapter (plain Node `http`, Express, a Fetch
5
+ * runtime, an in-memory test fake) can serve the same routes.
6
+ *
7
+ * Types only. Path matching, dispatch and every other piece of server code belong to the host's
8
+ * adapter, which the host passes in as `app`.
9
+ *
10
+ * Overlap, kept deliberately: `@jini-ai/http-kit` has its own Express-bound route-spec shapes
11
+ * (`HttpMethod` in lowercase, `RouteInputContext.params`). Core is the bottom layer and must not
12
+ * import http-kit, so those are not reused; a later bridge can map one onto the other.
13
+ */
14
+ /**
15
+ * HTTP methods a route may be registered under. Uppercase, matching web `Request.method`.
16
+ *
17
+ * @agent-note Register `HEAD` only when it must differ from `GET`: an adapter answers a `HEAD`
18
+ * with no `HEAD` route from the `GET` route, keeping its status and headers and dropping the
19
+ * body. Register `OPTIONS` to answer a CORS preflight yourself; nothing answers it for you.
20
+ */
21
+ export type ServerMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
22
+ /**
23
+ * Handles one matched request. `params` holds the `:name` path segments of the registered path,
24
+ * already percent-decoded by the adapter (for `/notes/:id` and `/notes/a%20b`, `{ id: 'a b' }`).
25
+ * Body, query string, headers and abort signal are read from `request` itself.
26
+ *
27
+ * `client` is the immediate peer of the connection, which a web `Request` cannot carry: the
28
+ * adapter fills it from its socket (Node's `incoming.socket.remoteAddress`, Bun's `requestIP`,
29
+ * Deno's `remoteAddr`). It is absent when the adapter has no peer (an in-memory fake, a closed
30
+ * socket). It is never read from a header: trusting `x-forwarded-for` is host policy, applied
31
+ * on top of this value.
32
+ *
33
+ * @agent-note Return a web `Response`; never write to a socket or framework response object, so
34
+ * the same handler runs on every adapter. Read the body once from `request` (`json()`,
35
+ * `formData()`, `text()`). For a client IP, start from `client.address`; read a forwarded header
36
+ * only behind a proxy the host trusts.
37
+ */
38
+ export type ServerHandler = (requiredArgs: {
39
+ readonly request: Request;
40
+ readonly params: Readonly<Record<string, string>>;
41
+ readonly client?: {
42
+ readonly address: string;
43
+ };
44
+ }, optionalArgs?: Record<string, never>) => Response | Promise<Response>;
45
+ /**
46
+ * One route as data: what `Server.route` takes. A package can return `ServerRoute[]` and leave
47
+ * registration to the host.
48
+ *
49
+ * @agent-note To mount a package's route list on your server:
50
+ * `for (const route of routes()) app.route(route);`
51
+ */
52
+ export interface ServerRoute {
53
+ readonly method: ServerMethod;
54
+ readonly path: string;
55
+ readonly handler: ServerHandler;
56
+ }
57
+ /**
58
+ * Something routes can be registered on.
59
+ *
60
+ * Path syntax: literal segments and `:name` segments, matched segment by segment against the
61
+ * request URL's pathname (no wildcards, no regex, query string ignored). Segment counts must be
62
+ * equal and a trailing slash is not ignored. Literal segments compare against the pathname as
63
+ * given (still percent-encoded). A `:name` segment never matches an empty segment, and one whose
64
+ * percent-encoding is malformed does not match. Registering the same method + path twice is an
65
+ * adapter error; paths that differ only in their param names (`/x/:id`, `/x/:slug`) are the same
66
+ * path. An unmatched request is the adapter's to answer (typically 404, or 405 when only the
67
+ * method differs).
68
+ *
69
+ * Precedence, when more than one path of the request's method matches: compare the paths segment
70
+ * by segment from the left; at the first segment where one is literal and the other is `:name`,
71
+ * the literal wins. So `/x/new` beats `/x/:id` for `/x/new`, and `/a/b/:q` beats `/a/:p/c` for
72
+ * `/a/b/c`. Registration order never decides.
73
+ *
74
+ * @agent-note In your app, use whichever server adapter you prefer, including Express. A plain
75
+ * Node `http` adapter is about 60 lines (`examples/notes-app/src/node-server.ts` is one): keep a
76
+ * route list, convert each `IncomingMessage` into a web `Request`, match the path as described
77
+ * above, call the handler, and write the returned `Response` (status, headers, body) back to the
78
+ * `ServerResponse`. Fetch-native runtimes skip the conversion. Tests can use an in-memory fake
79
+ * that dispatches a `Request` directly.
80
+ */
81
+ export interface Server {
82
+ route(requiredArgs: ServerRoute, optionalArgs?: Record<string, never>): void;
83
+ }
84
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @file The server contract: register a handler for an HTTP method + path, where handlers speak
3
+ * the web-standard `Request` → `Response`. Route code in Jini packages takes `{ app: Server }`
4
+ * and never names a concrete server, so any host adapter (plain Node `http`, Express, a Fetch
5
+ * runtime, an in-memory test fake) can serve the same routes.
6
+ *
7
+ * Types only. Path matching, dispatch and every other piece of server code belong to the host's
8
+ * adapter, which the host passes in as `app`.
9
+ *
10
+ * Overlap, kept deliberately: `@jini-ai/http-kit` has its own Express-bound route-spec shapes
11
+ * (`HttpMethod` in lowercase, `RouteInputContext.params`). Core is the bottom layer and must not
12
+ * import http-kit, so those are not reused; a later bridge can map one onto the other.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=server.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/core",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "The Jini kernel: typed DI tokens, pack composition and lifecycle, the tool registry, redaction, and origin/API-token auth primitives. Zero dependencies.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -20,6 +20,7 @@
20
20
  "./contribution-registry": "universal",
21
21
  "./provider-registry": "universal",
22
22
  "./object-store": "universal",
23
+ "./contracts/server": "universal",
23
24
  "./naming": "universal",
24
25
  "./records": "universal",
25
26
  "./primitives": "universal",
@@ -125,6 +126,11 @@
125
126
  "import": "./dist/object-store.js",
126
127
  "default": "./dist/object-store.js"
127
128
  },
129
+ "./contracts/server": {
130
+ "types": "./dist/contracts/server.d.ts",
131
+ "import": "./dist/contracts/server.js",
132
+ "default": "./dist/contracts/server.js"
133
+ },
128
134
  "./naming": {
129
135
  "types": "./dist/naming.d.ts",
130
136
  "import": "./dist/naming.js",