@slotform/api 0.0.0-stage → 0.1.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 +50 -2
- package/dist/client.d.ts +16 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +98 -0
- package/dist/client.js.map +1 -0
- package/dist/error.d.ts +2 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +2 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +153 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +640 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/chosen.d.ts +12 -0
- package/dist/lib/chosen.d.ts.map +1 -0
- package/dist/lib/chosen.js +18 -0
- package/dist/lib/chosen.js.map +1 -0
- package/dist/lib/cursor.d.ts +68 -0
- package/dist/lib/cursor.d.ts.map +1 -0
- package/dist/lib/cursor.js +220 -0
- package/dist/lib/cursor.js.map +1 -0
- package/dist/lib/limits.d.ts +4 -0
- package/dist/lib/limits.d.ts.map +1 -0
- package/dist/lib/limits.js +10 -0
- package/dist/lib/limits.js.map +1 -0
- package/dist/lib/local-origin.d.ts +2 -0
- package/dist/lib/local-origin.d.ts.map +1 -0
- package/dist/lib/local-origin.js +17 -0
- package/dist/lib/local-origin.js.map +1 -0
- package/dist/lib/slugify.d.ts +4 -0
- package/dist/lib/slugify.d.ts.map +1 -0
- package/dist/lib/slugify.js +26 -0
- package/dist/lib/slugify.js.map +1 -0
- package/dist/lib/window.d.ts +52 -0
- package/dist/lib/window.d.ts.map +1 -0
- package/dist/lib/window.js +70 -0
- package/dist/lib/window.js.map +1 -0
- package/dist/mcp-path.d.ts +2 -0
- package/dist/mcp-path.d.ts.map +1 -0
- package/dist/mcp-path.js +3 -0
- package/dist/mcp-path.js.map +1 -0
- package/dist/mcp.d.ts +15 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +5 -0
- package/dist/mcp.js.map +1 -0
- package/dist/node/barrel.d.ts +3 -0
- package/dist/node/barrel.d.ts.map +1 -0
- package/dist/node/barrel.js +70 -0
- package/dist/node/barrel.js.map +1 -0
- package/dist/node/codegen.d.ts +10 -0
- package/dist/node/codegen.d.ts.map +1 -0
- package/dist/node/codegen.js +132 -0
- package/dist/node/codegen.js.map +1 -0
- package/dist/node/procedure-codegen.d.ts +14 -0
- package/dist/node/procedure-codegen.d.ts.map +1 -0
- package/dist/node/procedure-codegen.js +95 -0
- package/dist/node/procedure-codegen.js.map +1 -0
- package/dist/node/schema-child.d.ts +2 -0
- package/dist/node/schema-child.d.ts.map +1 -0
- package/dist/node/schema-child.js +31 -0
- package/dist/node/schema-child.js.map +1 -0
- package/dist/node/schema-source.d.ts +3 -0
- package/dist/node/schema-source.d.ts.map +1 -0
- package/dist/node/schema-source.js +33 -0
- package/dist/node/schema-source.js.map +1 -0
- package/dist/node/server-client.d.ts +19 -0
- package/dist/node/server-client.d.ts.map +1 -0
- package/dist/node/server-client.js +45 -0
- package/dist/node/server-client.js.map +1 -0
- package/dist/node/types.d.ts +42 -0
- package/dist/node/types.d.ts.map +1 -0
- package/dist/node/types.js +13 -0
- package/dist/node/types.js.map +1 -0
- package/dist/not-found.d.ts +2 -0
- package/dist/not-found.d.ts.map +1 -0
- package/dist/not-found.js +6 -0
- package/dist/not-found.js.map +1 -0
- package/dist/procedure.d.ts +188 -0
- package/dist/procedure.d.ts.map +1 -0
- package/dist/procedure.js +392 -0
- package/dist/procedure.js.map +1 -0
- package/dist/query-invalidation.d.ts +20 -0
- package/dist/query-invalidation.d.ts.map +1 -0
- package/dist/query-invalidation.js +66 -0
- package/dist/query-invalidation.js.map +1 -0
- package/dist/schema.d.ts +32 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +103 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +30 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/wire.d.ts +11 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +26 -0
- package/dist/wire.js.map +1 -0
- package/dist/worker/guards.d.ts +6 -0
- package/dist/worker/guards.d.ts.map +1 -0
- package/dist/worker/guards.js +29 -0
- package/dist/worker/guards.js.map +1 -0
- package/dist/worker/index.d.ts +57 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +418 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/mcp.d.ts +28 -0
- package/dist/worker/mcp.d.ts.map +1 -0
- package/dist/worker/mcp.js +361 -0
- package/dist/worker/mcp.js.map +1 -0
- package/dist/worker/request-log.d.ts +10 -0
- package/dist/worker/request-log.d.ts.map +1 -0
- package/dist/worker/request-log.js +37 -0
- package/dist/worker/request-log.js.map +1 -0
- package/guide/add-a-procedure.md +42 -0
- package/guide/background.md +86 -0
- package/guide/client.md +93 -0
- package/guide/config.md +85 -0
- package/guide/mcp.md +68 -0
- package/guide/middleware.md +79 -0
- package/guide/procedures.md +95 -0
- package/guide/utilities.md +135 -0
- package/package.json +120 -3
- package/src/client.ts +129 -0
- package/src/error.ts +1 -0
- package/src/index.ts +787 -0
- package/src/lib/chosen.ts +31 -0
- package/src/lib/cursor.ts +354 -0
- package/src/lib/limits.ts +10 -0
- package/src/lib/local-origin.ts +18 -0
- package/src/lib/slugify.ts +29 -0
- package/src/lib/window.ts +155 -0
- package/src/mcp-path.ts +2 -0
- package/src/mcp.ts +30 -0
- package/src/node/barrel.ts +77 -0
- package/src/node/codegen.ts +173 -0
- package/src/node/procedure-codegen.ts +131 -0
- package/src/node/schema-child.ts +31 -0
- package/src/node/schema-source.ts +45 -0
- package/src/node/server-client.ts +67 -0
- package/src/node/types.ts +64 -0
- package/src/not-found.ts +6 -0
- package/src/procedure.ts +935 -0
- package/src/query-invalidation.ts +106 -0
- package/src/schema.ts +133 -0
- package/src/types.ts +72 -0
- package/src/wire.ts +34 -0
- package/src/worker/guards.ts +37 -0
- package/src/worker/index.ts +681 -0
- package/src/worker/mcp.ts +470 -0
- package/src/worker/request-log.ts +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fcalell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @slotform/api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
API plugin for the `slotform` framework. Wraps Hono, oRPC and Zod so consumers only define
|
|
4
|
+
procedures. Provides the builder chain, the procedure factory, the typed RPC client and the
|
|
5
|
+
slot-driven worker codegen.
|
|
6
|
+
|
|
7
|
+
**Stack:** Hono, oRPC and Zod, all internal: consumers import none of them.
|
|
8
|
+
|
|
9
|
+
How it is built: [docs/architecture/plugins/api.md](../../docs/architecture/plugins/api.md).
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
slotform add api
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Guide
|
|
18
|
+
|
|
19
|
+
Writing procedures, worker middleware, the client, options, pagination and slugs lives in
|
|
20
|
+
`guide/`, indexed into a consumer's `.slotform/guide.md`:
|
|
21
|
+
[`add-a-procedure.md`](./guide/add-a-procedure.md), [`procedures.md`](./guide/procedures.md),
|
|
22
|
+
[`middleware.md`](./guide/middleware.md), [`client.md`](./guide/client.md),
|
|
23
|
+
[`mcp.md`](./guide/mcp.md), [`background.md`](./guide/background.md), [`config.md`](./guide/config.md) and
|
|
24
|
+
[`utilities.md`](./guide/utilities.md). Drawing the client's reads, acts and abilities is the query
|
|
25
|
+
plugin's (`@slotform/query`).
|
|
26
|
+
|
|
27
|
+
## Exports
|
|
28
|
+
|
|
29
|
+
| Subpath | Purpose |
|
|
30
|
+
|---------|---------|
|
|
31
|
+
| `@slotform/api` | `api()`, `ApiOptions`, `ApiError`, `Middleware`, `CallbackSpec`, `PluginRuntimeEntry` |
|
|
32
|
+
| `@slotform/api/runtime` | `createWorker()`, `AppBuilder`, `WorkerExport`, `ApiWorkerOptions`, `BaseContext`, `EnvCheckSpec`, `HandlerMount`, `slotformContext()`, `isForbiddenOrigin()`, `RATE_LIMITER_RPC` |
|
|
33
|
+
| `@slotform/api/mcp` | `defineMcp()`, `McpDefinition`, `ProcedurePath`: what `src/worker/mcp.ts` default-exports |
|
|
34
|
+
| `@slotform/api/procedure` | `createProcedure()`, `createJobs()`, `noSuch()` (a scope's `NOT_FOUND` refusal, "No such <scope>"), `extractIp()`, `JobBatch`, `JobMessage`, `JobScheduledEvent`, `Middleware`, `ProcedureBuilder`, `ProcedureConfig`, `ProcedureFactory`, `RateLimitBinding`, `RateLimitKind`, `ScopeLike`, `SLOTFORM_READS_HEADER`, `SLOTFORM_WRITES_HEADER`, `ORG_RULES_PATH`, `SCOPE_ROUTES_PATH`: what the generated `.slotform/procedure.ts` (`virtual:slotform-procedure`) imports |
|
|
35
|
+
| `@slotform/api/error` | `ApiError`, worker-safe (no Node-only deps): import this from route files |
|
|
36
|
+
| `@slotform/api/client` | `createClient()`, `RouterClient`, `ClientConfig`, `isNotFound()`, `registerApiClient()`, `getRegisteredApiClient()` (the client `useAbility()` fetches the org rules through), `registerOperationContext()` |
|
|
37
|
+
| `@slotform/api/wire` | the import-free wire constants: `SLOTFORM_READS_HEADER`, `SLOTFORM_WRITES_HEADER`, `SLOTFORM_NOT_FOUND_HEADER`, `SLOTFORM_EXPOSED_HEADERS`, `ENTITY_NAME_RE`, `ORG_RULES_PATH`, `SCOPE_ROUTES_PATH`, `LISTENER_ENV`, `ORIGIN_ENV`, `listenerOrigin()` |
|
|
38
|
+
| `@slotform/api/query-invalidation` | `captureEntityHeaders()`, `invalidateForWrites()`, `handleMutationSuccess()`, `EntityName`, `InvalidatableQueryClient`, `Register`: the framework-agnostic auto-invalidation core; `invalidateForWrites` takes the app's `Entity` names (type-only) |
|
|
39
|
+
| `@slotform/api/types` | `Procedure`, `Router`, `RouterClient`, `ScopedRouterClient`, `EnvSpec`, `EnvValidation`: the types of the client and the worker |
|
|
40
|
+
| `@slotform/api/schema` | `z` (Zod re-export), `ZodObject`, `ZodType`, `ZodRawShape`, `selector()` / `Selector` (rows a mutation acts on: ids, or a read's query less the unticked ids), `inputJsonSchema()` (a procedure's input as JSON Schema, also the MCP tool's), `routerSchema()` (every procedure of a router, the worker's `_router`: what `slotform generate` writes to `.slotform/schema.ts`) |
|
|
41
|
+
| `@slotform/api/lib/cursor` | `encodeCursor`, `decodeCursor`, `paginate` (keyset over one or more order columns), `clampLimit`, constants |
|
|
42
|
+
| `@slotform/api/lib/window` | `paginateWindow`: a `paginated: "window"` procedure's page at an offset with the filter's total, ordered by columns or SQL expressions over an optional join |
|
|
43
|
+
| `@slotform/api/lib/chosen` | `chosenWhere`: a `selector()` (from `/schema`) resolved to a where clause |
|
|
44
|
+
| `@slotform/api/lib/slugify` | `slugify`, `isReservedSlug`, `RESERVED_SLUGS` |
|
|
45
|
+
| `@slotform/api/local-origin` | `isLocalOrigin()`: whether an origin's hostname is a local-dev one |
|
|
46
|
+
|
|
47
|
+
`RuntimePlugin`, the contract a runtime plugin implements, is `@slotform/cli/runtime`'s.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { RouterClient } from "./types.ts";
|
|
2
|
+
export { isNotFound } from "./not-found.ts";
|
|
3
|
+
export type { RouterClient } from "./types.ts";
|
|
4
|
+
export declare function registerApiClient(client: unknown): void;
|
|
5
|
+
export declare function getRegisteredApiClient(): unknown;
|
|
6
|
+
export interface ClientConfig {
|
|
7
|
+
/** The RPC endpoint (`/rpc` by default). A function is read on every request, so an app whose server is chosen while it runs (a phone signing in to a server it is told the address of) changes the address without rebuilding the client. Clear the query cache when it changes: the data held is the old server's. */
|
|
8
|
+
url?: string | (() => string);
|
|
9
|
+
fetch?: typeof globalThis.fetch;
|
|
10
|
+
credentials?: RequestCredentials;
|
|
11
|
+
/** Sent with every request: an object, or a function read on every request that may answer later (a cookie or a key read from the device's secure store). */
|
|
12
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
13
|
+
}
|
|
14
|
+
export declare function registerOperationContext(symbol: symbol): void;
|
|
15
|
+
export declare function createClient<TRouter>(config?: ClientConfig): RouterClient<TRouter>;
|
|
16
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAEvD;AAKD,wBAAgB,sBAAsB,IAAI,OAAO,CAEhD;AAED,MAAM,WAAW,YAAY;IAC5B,wTAAwT;IACxT,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,6JAA6J;IAC7J,OAAO,CAAC,EACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtB,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CACpE;AA8BD,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE7D;AAgBD,wBAAgB,YAAY,CAAC,OAAO,EACnC,MAAM,CAAC,EAAE,YAAY,GACnB,YAAY,CAAC,OAAO,CAAC,CA8CvB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createORPCClient } from "@orpc/client";
|
|
2
|
+
import { RPCLink } from "@orpc/client/fetch";
|
|
3
|
+
import { captureEntityHeaders } from "./query-invalidation.js";
|
|
4
|
+
import { SLOTFORM_NOT_FOUND_HEADER } from "./wire.js";
|
|
5
|
+
export { isNotFound } from "./not-found.js";
|
|
6
|
+
// Default client registration: docs/architecture/plugins/api.md, "Client".
|
|
7
|
+
let registeredApiClient;
|
|
8
|
+
export function registerApiClient(client) {
|
|
9
|
+
registeredApiClient = client;
|
|
10
|
+
}
|
|
11
|
+
// Read by the query plugin's org-rules fetch and by `createClient`'s
|
|
12
|
+
// auto-registration guard. Not a consumer-facing surface -- there's nothing
|
|
13
|
+
// to inspect on the value beyond "is a client registered".
|
|
14
|
+
export function getRegisteredApiClient() {
|
|
15
|
+
return registeredApiClient;
|
|
16
|
+
}
|
|
17
|
+
// Derives the procedure pathKey ("todos/list") from a request URL by
|
|
18
|
+
// stripping the configured base's pathname. `base` is either relative
|
|
19
|
+
// ("/rpc") or absolute ("https://host/rpc"); both cases resolve through
|
|
20
|
+
// `URL` against a dummy origin so the pathname strip is identical either way.
|
|
21
|
+
function pathKeyFromRequestUrl(requestUrl, base) {
|
|
22
|
+
const basePath = new URL(base, "http://slotform.invalid").pathname;
|
|
23
|
+
const path = new URL(requestUrl, "http://slotform.invalid").pathname;
|
|
24
|
+
const trimmedBase = basePath.replace(/^\/|\/$/g, "");
|
|
25
|
+
const trimmedPath = path.replace(/^\/|\/$/g, "");
|
|
26
|
+
return trimmedPath.startsWith(trimmedBase)
|
|
27
|
+
? trimmedPath.slice(trimmedBase.length).replace(/^\/+/, "")
|
|
28
|
+
: trimmedPath;
|
|
29
|
+
}
|
|
30
|
+
// oRPC's RPCLink resolves every request URL via `new URL(baseUrl)` with no
|
|
31
|
+
// `base` argument, so a relative default like "/rpc" throws "Invalid URL" on
|
|
32
|
+
// the first real call. Resolve against `location.origin` when present (any
|
|
33
|
+
// browser); native/SSR/test callers keep passing an absolute `url` (as the
|
|
34
|
+
// README's Expo example already does), so this is a no-op for them.
|
|
35
|
+
function resolveClientUrl(url) {
|
|
36
|
+
if (/^[a-z][a-z\d+\-.]*:\/\//i.test(url))
|
|
37
|
+
return url;
|
|
38
|
+
if (typeof location === "undefined")
|
|
39
|
+
return url;
|
|
40
|
+
return new URL(url, location.origin).toString();
|
|
41
|
+
}
|
|
42
|
+
// Operation context handed over by the query plugin: docs/architecture/plugins/api.md, "Client".
|
|
43
|
+
let operationContext;
|
|
44
|
+
export function registerOperationContext(symbol) {
|
|
45
|
+
operationContext = symbol;
|
|
46
|
+
}
|
|
47
|
+
// The operation types oRPC's own docs send as GET.
|
|
48
|
+
const READ_OPERATIONS = new Set(["query", "streamed", "live", "infinite"]);
|
|
49
|
+
// Reads travel as GET: docs/architecture/plugins/api.md, "Reads travel as GET".
|
|
50
|
+
function methodOf(options) {
|
|
51
|
+
if (operationContext === undefined)
|
|
52
|
+
return "POST";
|
|
53
|
+
const operation = options.context[operationContext];
|
|
54
|
+
return operation?.type && READ_OPERATIONS.has(operation.type)
|
|
55
|
+
? "GET"
|
|
56
|
+
: "POST";
|
|
57
|
+
}
|
|
58
|
+
export function createClient(config) {
|
|
59
|
+
const given = config?.url ?? "/rpc";
|
|
60
|
+
// The address now: a function is asked each time, a string once.
|
|
61
|
+
const urlNow = () => resolveClientUrl(typeof given === "function" ? given() : given);
|
|
62
|
+
const baseFetch = config?.fetch ?? globalThis.fetch;
|
|
63
|
+
const link = new RPCLink({
|
|
64
|
+
url: typeof given === "function" ? urlNow : urlNow(),
|
|
65
|
+
method: methodOf,
|
|
66
|
+
headers: config?.headers,
|
|
67
|
+
fetch: async (request, init) => {
|
|
68
|
+
const response = await baseFetch(request, {
|
|
69
|
+
...init,
|
|
70
|
+
credentials: config?.credentials ?? "include",
|
|
71
|
+
});
|
|
72
|
+
try {
|
|
73
|
+
captureEntityHeaders(pathKeyFromRequestUrl(request.url, urlNow()), response.headers);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Capture is best-effort: a failure never breaks the response.
|
|
77
|
+
}
|
|
78
|
+
// A read's not found travels as a success status (see the worker);
|
|
79
|
+
// oRPC decodes an error from the status, so the 404 goes back on.
|
|
80
|
+
if (response.headers.has(SLOTFORM_NOT_FOUND_HEADER)) {
|
|
81
|
+
return new Response(response.body, {
|
|
82
|
+
status: 404,
|
|
83
|
+
statusText: "Not Found",
|
|
84
|
+
headers: response.headers,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return response;
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
const client = createORPCClient(link);
|
|
91
|
+
// A later `createClient` call never overwrites the registered client; an
|
|
92
|
+
// explicit `registerApiClient` always does.
|
|
93
|
+
if (getRegisteredApiClient() === undefined) {
|
|
94
|
+
registerApiClient(client);
|
|
95
|
+
}
|
|
96
|
+
return client;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,2EAA2E;AAC3E,IAAI,mBAA4B,CAAC;AAEjC,MAAM,UAAU,iBAAiB,CAAC,MAAe;IAChD,mBAAmB,GAAG,MAAM,CAAC;AAC9B,CAAC;AAED,qEAAqE;AACrE,4EAA4E;AAC5E,2DAA2D;AAC3D,MAAM,UAAU,sBAAsB;IACrC,OAAO,mBAAmB,CAAC;AAC5B,CAAC;AAaD,qEAAqE;AACrE,sEAAsE;AACtE,wEAAwE;AACxE,8EAA8E;AAC9E,SAAS,qBAAqB,CAAC,UAAkB,EAAE,IAAY;IAC9D,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC,QAAQ,CAAC;IACnE,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,UAAU,EAAE,yBAAyB,CAAC,CAAC,QAAQ,CAAC;IACrE,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACrD,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IACjD,OAAO,WAA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AsB,EAAE,KAAK,SAAS,EAAE,CAAC;QAC5C,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC"}
|
package/dist/error.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/error.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { MiddlewareSpec, TsExpression, TsImportSpec, TsTypeRef } from "@slotform/cli/ast";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { type CallbackSpec, type MiddlewareCall, type PluginRuntimeEntry } from "./node/types.ts";
|
|
4
|
+
import type { EnvSpec } from "./types.ts";
|
|
5
|
+
declare const apiOptionsSchema: z.ZodObject<{
|
|
6
|
+
prefix: z.ZodDefault<z.ZodString>;
|
|
7
|
+
env: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
8
|
+
name: z.ZodString;
|
|
9
|
+
devDefault: z.ZodString;
|
|
10
|
+
validate: z.ZodOptional<z.ZodObject<{
|
|
11
|
+
minLength: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
url: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
devLocalhost: z.ZodOptional<z.ZodBoolean>;
|
|
14
|
+
}, z.core.$strip>>;
|
|
15
|
+
}, z.core.$strip>>>;
|
|
16
|
+
entities: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
17
|
+
server: z.ZodOptional<z.ZodString>;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type ApiOptions = z.input<typeof apiOptionsSchema>;
|
|
20
|
+
export declare const api: import("@slotform/cli").PluginFactory<"api", {
|
|
21
|
+
prefix?: string | undefined;
|
|
22
|
+
env?: {
|
|
23
|
+
name: string;
|
|
24
|
+
devDefault: string;
|
|
25
|
+
validate?: {
|
|
26
|
+
minLength?: number | undefined;
|
|
27
|
+
url?: boolean | undefined;
|
|
28
|
+
devLocalhost?: boolean | undefined;
|
|
29
|
+
} | undefined;
|
|
30
|
+
}[] | undefined;
|
|
31
|
+
entities?: string[] | undefined;
|
|
32
|
+
server?: string | undefined;
|
|
33
|
+
}, {
|
|
34
|
+
readonly workerImports: import("@slotform/cli").Slot<TsImportSpec[]>;
|
|
35
|
+
readonly pluginRuntimes: import("@slotform/cli").Slot<PluginRuntimeEntry[]>;
|
|
36
|
+
readonly middlewareEntries: import("@slotform/cli").Slot<MiddlewareSpec[]>;
|
|
37
|
+
readonly middlewareCalls: import("@slotform/cli").Slot<MiddlewareCall[]>;
|
|
38
|
+
readonly middlewareImports: import("@slotform/cli").Slot<TsImportSpec[]>;
|
|
39
|
+
readonly routesHandler: import("@slotform/cli").Slot<{
|
|
40
|
+
identifier: string;
|
|
41
|
+
} | null>;
|
|
42
|
+
readonly mcpAuth: import("@slotform/cli").Slot<boolean>;
|
|
43
|
+
readonly serverAuth: import("@slotform/cli").Slot<boolean>;
|
|
44
|
+
readonly serverSchemaSource: import("@slotform/cli").Slot<string | null>;
|
|
45
|
+
readonly serverTypesSource: import("@slotform/cli").Slot<string | null>;
|
|
46
|
+
readonly mcpMount: import("@slotform/cli").Slot<{
|
|
47
|
+
identifier: string;
|
|
48
|
+
name: string;
|
|
49
|
+
} | null>;
|
|
50
|
+
readonly queueHandler: import("@slotform/cli").Slot<{
|
|
51
|
+
identifier: "queue";
|
|
52
|
+
} | null>;
|
|
53
|
+
readonly scheduledHandler: import("@slotform/cli").Slot<{
|
|
54
|
+
identifier: "scheduled";
|
|
55
|
+
} | null>;
|
|
56
|
+
readonly corsOrigins: import("@slotform/cli").Slot<string[]>;
|
|
57
|
+
readonly devCorsOrigins: import("@slotform/cli").Slot<string[]>;
|
|
58
|
+
readonly devTargetOrigins: import("@slotform/cli").Slot<string[]>;
|
|
59
|
+
readonly nativeScheme: import("@slotform/cli").Slot<string | null>;
|
|
60
|
+
readonly routePrefixes: import("@slotform/cli").Slot<string[]>;
|
|
61
|
+
readonly rpcPrefix: import("@slotform/cli").Slot<string>;
|
|
62
|
+
readonly cors: import("@slotform/cli").Slot<string[]>;
|
|
63
|
+
readonly callbacks: import("@slotform/cli").Slot<Record<string, CallbackSpec>>;
|
|
64
|
+
readonly env: import("@slotform/cli").Slot<EnvSpec[]>;
|
|
65
|
+
readonly envType: import("@slotform/cli").Slot<TsTypeRef | null>;
|
|
66
|
+
readonly workerBase: import("@slotform/cli").Slot<{
|
|
67
|
+
kind: "string";
|
|
68
|
+
value: string;
|
|
69
|
+
} | {
|
|
70
|
+
kind: "number";
|
|
71
|
+
value: number;
|
|
72
|
+
} | {
|
|
73
|
+
kind: "boolean";
|
|
74
|
+
value: boolean;
|
|
75
|
+
} | {
|
|
76
|
+
kind: "null";
|
|
77
|
+
} | {
|
|
78
|
+
kind: "undefined";
|
|
79
|
+
} | {
|
|
80
|
+
kind: "identifier";
|
|
81
|
+
name: string;
|
|
82
|
+
} | {
|
|
83
|
+
kind: "member";
|
|
84
|
+
object: TsExpression;
|
|
85
|
+
property: string;
|
|
86
|
+
} | {
|
|
87
|
+
kind: "call";
|
|
88
|
+
callee: TsExpression;
|
|
89
|
+
args: TsExpression[];
|
|
90
|
+
typeArgs?: TsTypeRef[];
|
|
91
|
+
} | {
|
|
92
|
+
kind: "new";
|
|
93
|
+
callee: TsExpression;
|
|
94
|
+
args: TsExpression[];
|
|
95
|
+
} | {
|
|
96
|
+
kind: "object";
|
|
97
|
+
properties: Array<{
|
|
98
|
+
key: string;
|
|
99
|
+
value: TsExpression;
|
|
100
|
+
shorthand?: boolean;
|
|
101
|
+
}>;
|
|
102
|
+
} | {
|
|
103
|
+
kind: "array";
|
|
104
|
+
items: TsExpression[];
|
|
105
|
+
} | {
|
|
106
|
+
kind: "arrow";
|
|
107
|
+
params: Array<{
|
|
108
|
+
name: string;
|
|
109
|
+
type?: TsTypeRef;
|
|
110
|
+
}>;
|
|
111
|
+
body: TsExpression | import("@slotform/cli/ast").TsStatement[];
|
|
112
|
+
async?: boolean;
|
|
113
|
+
} | {
|
|
114
|
+
kind: "as";
|
|
115
|
+
expression: TsExpression;
|
|
116
|
+
type: TsTypeRef;
|
|
117
|
+
} | {
|
|
118
|
+
kind: "jsx";
|
|
119
|
+
tag: string;
|
|
120
|
+
props: Array<{
|
|
121
|
+
name: string;
|
|
122
|
+
value?: TsExpression;
|
|
123
|
+
}>;
|
|
124
|
+
children: Array<TsExpression | {
|
|
125
|
+
kind: "text";
|
|
126
|
+
value: string;
|
|
127
|
+
}>;
|
|
128
|
+
selfClosing?: boolean;
|
|
129
|
+
}>;
|
|
130
|
+
readonly workerSource: import("@slotform/cli").Slot<string | null>;
|
|
131
|
+
readonly routeBarrelSource: import("@slotform/cli").Slot<string | null>;
|
|
132
|
+
readonly rbacStatements: import("@slotform/cli").Slot<Record<string, readonly string[]> | null>;
|
|
133
|
+
readonly localOrigins: import("@slotform/cli").Slot<"deployed" | "dev">;
|
|
134
|
+
readonly entities: import("@slotform/cli").Slot<string[]>;
|
|
135
|
+
readonly procedureSource: import("@slotform/cli").Slot<string | null>;
|
|
136
|
+
}, Record<string, never>, {
|
|
137
|
+
prefix: string;
|
|
138
|
+
env: {
|
|
139
|
+
name: string;
|
|
140
|
+
devDefault: string;
|
|
141
|
+
validate?: {
|
|
142
|
+
minLength?: number | undefined;
|
|
143
|
+
url?: boolean | undefined;
|
|
144
|
+
devLocalhost?: boolean | undefined;
|
|
145
|
+
} | undefined;
|
|
146
|
+
}[];
|
|
147
|
+
entities: string[];
|
|
148
|
+
server?: string | undefined;
|
|
149
|
+
}>;
|
|
150
|
+
export { ApiError } from "./error.ts";
|
|
151
|
+
export type { CallbackSpec, PluginRuntimeEntry } from "./node/types.ts";
|
|
152
|
+
export type { Middleware } from "./procedure.ts";
|
|
153
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoBxB,OAAO,EACN,KAAK,YAAY,EAEjB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EAOvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAe1C,QAAA,MAAM,gBAAgB;;;;;;;;;;;;;iBAoBpB,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AA6c1D,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;oBA3Y+B,MAAM;;;;;;;oBA+D3B,MAAM;cAAQ,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6jB5C,CAAC;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACxE,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC"}
|