@oatscenter/trellis 0.100.0-rc.4 → 0.100.0-rc.6

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/README.md CHANGED
@@ -5,8 +5,8 @@ and runtime error types.
5
5
 
6
6
  The npm package contains ESM JavaScript and TypeScript declarations. Use
7
7
  `import`; CommonJS output and `require()` support have intentionally been
8
- removed. Node and Deno adapters remain available as ESM subpaths. JSR
9
- publication remains supported.
8
+ removed. Node and Deno adapters remain available as ESM subpaths. The package is
9
+ published to npm.
10
10
 
11
11
  For AI-agent context, start with the generated package `TRELLIS.md` files and
12
12
  the raw docs index:
@@ -16,24 +16,30 @@ the raw docs index:
16
16
 
17
17
  ```typescript
18
18
  import { TrellisClient } from "@oatscenter/trellis";
19
- import { participants } from "example-trellis";
19
+ import { apps } from "example-trellis";
20
20
 
21
21
  const client = await TrellisClient.connect({
22
22
  trellisUrl: "https://trellis.example.com",
23
- participant: participants.exampleApp.participant,
23
+ request: apps.ExampleApp.request,
24
+ auth: { clientId: "example-app", redirectTo: `${location.origin}/callback` },
24
25
  }).orThrow();
25
26
  ```
26
27
 
27
28
  The local package name comes from `trellis.toml`. Generation emits one ordinary
28
- ESM package with `apis` and `participants` namespaces, executable JavaScript and
29
- declarations, and the matching published runtime dependency. Commit that package
29
+ ESM package with `apis`, `apps`, and `participants` namespaces, executable
30
+ JavaScript and declarations, and the matching published runtime dependency. Apps
31
+ connect with their generated `apps.<App>.request`; services connect with
32
+ `TrellisService.connect({ participant: participants.<Service>.participant, ... })`. Commit that package
30
33
  when ordinary builds should not require the Trellis CLI or API cache.
31
34
 
32
- Connected API facades group actions by surface: `.rpc.<group>.<leaf>(input)`,
33
- `.event.<group>.<leaf>.listen(handler)` or `.publish(event)`,
34
- `.feed.<group>.<leaf>(input)`, and `.operation.<group>.<leaf>.start(input)`.
35
- Inspect generated declarations for the exact selected APIs and action names. Do
36
- not reconstruct transport subjects or use handwritten contract metadata.
35
+ Generated clients expose flat methods named after each action: an RPC `Get` is
36
+ `client.get(input)`, an operation `Reindex` is `client.reindex(input).start()`,
37
+ and a live observation `Watch` is `client.watch(input, { signal })`. Services
38
+ register RPC and operation handlers with `service.handleGet(...)` and
39
+ `service.handleReindex(...)`, publish events with `service.publishShipped(...)`,
40
+ and listen with `service.onShipped(...)`. Calls return `Result` values. Inspect
41
+ the generated declarations for the exact names. Do not reconstruct transport
42
+ subjects or use handwritten contract metadata.
37
43
 
38
44
  Prepared events support durable publish flows. `prepare(...)` returns a
39
45
  `PreparedTrellisEvent`; services can persist prepared events in SQL or NATS KV
package/generated.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /** Portable runtime support for generated Trellis packages. */
2
2
  export { TrellisError } from "./errors/TrellisError.ts";
3
- export { apiDescriptor, type AppRequestDescriptor, type Codec, codecs, participantDescriptor, type SerializableErrorData, } from "./generated_support.ts";
3
+ export { apiDescriptor, type AppRequestDescriptor, type Codec, codecs, type JsonValue, participantDescriptor, type SerializableErrorData, } from "./generated_support.ts";
4
4
  export type { ParticipantJobsFromResources, ParticipantKvFromResources, RuntimeApiFromGenerated, } from "./participant_runtime/participant.ts";
@@ -17,10 +17,12 @@ type CodecValue<C> = C extends {
17
17
  type OpenEnum<T extends string> = T | (string & {
18
18
  readonly __openEnum?: never;
19
19
  });
20
- type Timestamp = string & {
20
+ /** An IDL `timestamp`: a canonical UTC RFC 3339 string. */
21
+ export type Timestamp = string & {
21
22
  readonly __timestamp: unique symbol;
22
23
  };
23
- type Ulid = string & {
24
+ /** An IDL `ulid`: a canonical ULID string. */
25
+ export type Ulid = string & {
24
26
  readonly __ulid: unique symbol;
25
27
  };
26
28
  type OptionalCodec<T> = Codec<T | undefined> & Readonly<{
@@ -32,6 +34,17 @@ type ModelValue<F extends Readonly<Record<string, ModelField>>> = {
32
34
  } & {
33
35
  [K in keyof F as F[K] extends OptionalCodec<unknown> ? K : never]?: Exclude<CodecValue<F[K]>, undefined>;
34
36
  };
37
+ /** Declared IDL constraints a generated codec enforces. */
38
+ type Limits = Readonly<{
39
+ min?: number | bigint;
40
+ max?: number | bigint;
41
+ minCount?: number;
42
+ maxCount?: number;
43
+ }>;
44
+ /** A value the IDL `json` type carries unchecked. */
45
+ export type JsonValue = null | boolean | number | string | JsonValue[] | {
46
+ [key: string]: JsonValue;
47
+ };
35
48
  /** Browser-safe codec vocabulary consumed by generated TypeScript packages. */
36
49
  export declare const codecs: Readonly<{
37
50
  string: Readonly<{
@@ -74,6 +87,11 @@ export declare const codecs: Readonly<{
74
87
  decode(value: unknown): Ulid;
75
88
  encode(value: Ulid): unknown;
76
89
  }>;
90
+ json: Readonly<{
91
+ decode(value: unknown): JsonValue;
92
+ encode(value: JsonValue): unknown;
93
+ }>;
94
+ bounded<T>(inner: Codec<T>, limits: Limits): Codec<T>;
77
95
  openEnum<const T extends string>(values: readonly T[]): Codec<OpenEnum<T>>;
78
96
  model<const F extends Readonly<Record<string, ModelField>>>(fields: F): Codec<ModelValue<F>>;
79
97
  named<T, Named extends T>(_name: string, value: Codec<T>): Codec<Named>;
@@ -83,6 +83,49 @@ function timestamp(value) {
83
83
  return `${canonical}${digits ? `.${digits}` : ""}Z`;
84
84
  }
85
85
  const ulidPattern = /^[0-7][0-9A-HJKMNP-TV-Z]{25}$/;
86
+ /**
87
+ * Enforce declared bounds in both directions, so a provider never hands a
88
+ * handler an out-of-bounds input and a caller never sends one. String length
89
+ * counts Unicode code points, as JSON Schema does.
90
+ */
91
+ function checkLimits(value, limits) {
92
+ const count = typeof value === "string"
93
+ ? [...value].length
94
+ : Array.isArray(value)
95
+ ? value.length
96
+ : undefined;
97
+ if (count !== undefined) {
98
+ if (limits.minCount !== undefined && count < limits.minCount)
99
+ fail(`at least ${limits.minCount} ${typeof value === "string" ? "characters" : "items"}`);
100
+ if (limits.maxCount !== undefined && count > limits.maxCount)
101
+ fail(`at most ${limits.maxCount} ${typeof value === "string" ? "characters" : "items"}`);
102
+ }
103
+ if (typeof value === "number" || typeof value === "bigint") {
104
+ if (limits.min !== undefined && value < limits.min)
105
+ fail(`a value of at least ${limits.min}`);
106
+ if (limits.max !== undefined && value > limits.max)
107
+ fail(`a value of at most ${limits.max}`);
108
+ }
109
+ }
110
+ /** Accept only values JSON can represent, so `json` round-trips exactly. */
111
+ function jsonValue(value) {
112
+ if (value === null || typeof value === "boolean" || typeof value === "string")
113
+ return value;
114
+ if (typeof value === "number")
115
+ return Number.isFinite(value) ? value : fail("finite JSON number");
116
+ if (Array.isArray(value))
117
+ return value.map(jsonValue);
118
+ const prototype = typeof value === "object" ? Object.getPrototypeOf(value) : undefined;
119
+ if (prototype === Object.prototype || prototype === null) {
120
+ const result = {};
121
+ for (const [key, item] of Object.entries(value)) {
122
+ if (item !== undefined)
123
+ result[key] = jsonValue(item);
124
+ }
125
+ return result;
126
+ }
127
+ return fail("JSON value");
128
+ }
86
129
  /** Browser-safe codec vocabulary consumed by generated TypeScript packages. */
87
130
  export const codecs = Object.freeze({
88
131
  string: stringCodec,
@@ -97,6 +140,17 @@ export const codecs = Object.freeze({
97
140
  ulid: codec((value) => typeof value === "string" && ulidPattern.test(value)
98
141
  ? value
99
142
  : fail("canonical ULID")),
143
+ json: codec(jsonValue),
144
+ bounded(inner, limits) {
145
+ return codec((value) => {
146
+ const decoded = inner.decode(value);
147
+ checkLimits(decoded, limits);
148
+ return decoded;
149
+ }, (value) => {
150
+ checkLimits(value, limits);
151
+ return inner.encode(value);
152
+ });
153
+ },
100
154
  openEnum(values) {
101
155
  if (values.some((value) => typeof value !== "string")) {
102
156
  fail("generated string enum values");