@oatscenter/trellis 0.100.0-rc.5 → 0.100.0-rc.7

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.
Files changed (34) hide show
  1. package/README.md +17 -11
  2. package/auth/authority.js +22 -0
  3. package/auth/protocol_wasm/provider/trellis_protocol_wasm_bg.wasm +0 -0
  4. package/auth/protocol_wasm.d.ts +15 -0
  5. package/generated.d.ts +1 -1
  6. package/generated_support.d.ts +20 -2
  7. package/generated_support.js +34 -0
  8. package/internal_sdk/generated/apis/auth/mod.d.ts +10 -7
  9. package/internal_sdk/generated/apis/auth/mod.js +52 -31
  10. package/internal_sdk/generated/apis/core/mod.d.ts +5 -5
  11. package/internal_sdk/generated/apis/core/mod.js +33 -17
  12. package/internal_sdk/generated/apis/events/mod.d.ts +20 -15
  13. package/internal_sdk/generated/apis/events/mod.js +118 -67
  14. package/internal_sdk/generated/apis/health/mod.d.ts +8 -7
  15. package/internal_sdk/generated/apis/health/mod.js +50 -27
  16. package/internal_sdk/generated/apis/jobs/mod.d.ts +8 -7
  17. package/internal_sdk/generated/apis/jobs/mod.js +50 -27
  18. package/internal_sdk/generated/apis/state/mod.d.ts +13 -9
  19. package/internal_sdk/generated/apis/state/mod.js +69 -41
  20. package/internal_sdk/generated/package.json +2 -2
  21. package/internal_sdk/generated/participants/eventsRuntime/mod.js +1 -1
  22. package/internal_sdk/generated/participants/healthRuntime/mod.js +1 -1
  23. package/internal_sdk/generated/participants/jobsRuntime/mod.js +1 -1
  24. package/internal_sdk/generated/participants/platform/mod.js +1 -1
  25. package/internal_sdk/generated/types/_internal/p0.js +550 -400
  26. package/package.json +2 -2
  27. package/portable.d.ts +2 -0
  28. package/portable.js +1 -0
  29. package/service/mod.d.ts +2 -1
  30. package/service/runtime/service.d.ts +14 -12
  31. package/service/runtime/service.js +48 -13
  32. package/session/wire.js +19 -2
  33. package/values.d.ts +33 -0
  34. package/values.js +52 -0
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/auth/authority.js CHANGED
@@ -44,6 +44,27 @@ export class VerifiedAuthority {
44
44
  /** Verified logical caller identity usable by all SDK adapters. */
45
45
  get caller() {
46
46
  const authority = this.#entry.authority;
47
+ // Auth signs the user's own profile into a user principal's authority.
48
+ const profile = authority.principalKind === "user"
49
+ ? authority.extensions["trellis.user.v1"]
50
+ : undefined;
51
+ const text = (value) => typeof value === "string" ? value : undefined;
52
+ const user = profile !== null &&
53
+ typeof profile === "object" &&
54
+ !Array.isArray(profile) &&
55
+ typeof profile.displayName === "string"
56
+ ? {
57
+ displayName: profile.displayName,
58
+ ...(text(profile.givenName) && {
59
+ givenName: text(profile.givenName),
60
+ }),
61
+ ...(text(profile.familyName) && {
62
+ familyName: text(profile.familyName),
63
+ }),
64
+ ...(text(profile.email) && { email: text(profile.email) }),
65
+ emailVerified: profile.emailVerified === true,
66
+ }
67
+ : undefined;
47
68
  return {
48
69
  authorityDigest: this.digest,
49
70
  principalId: authority.principalId,
@@ -57,6 +78,7 @@ export class VerifiedAuthority {
57
78
  oauthGrantId: authority.oauthGrantId,
58
79
  capabilities: authority.capabilities,
59
80
  apis: authority.apis,
81
+ ...(user && { user }),
60
82
  };
61
83
  }
62
84
  /** Time and observed retirement are checked again immediately before authorized work. */
@@ -172,6 +172,21 @@ export type AuthenticatedCaller = {
172
172
  oauthGrantId?: string;
173
173
  capabilities: CapabilityAuthority[];
174
174
  apis: AuthorityApi[];
175
+ /** The user's own profile, for user principals. */
176
+ user?: CallerUser;
177
+ };
178
+ /**
179
+ * Auth's profile of a user caller, as of the authority's issuance.
180
+ *
181
+ * Identification only: the stable key is `principalId`, and names and email
182
+ * are neither unique nor authorization.
183
+ */
184
+ export type CallerUser = {
185
+ displayName: string;
186
+ givenName?: string;
187
+ familyName?: string;
188
+ email?: string;
189
+ emailVerified: boolean;
175
190
  };
176
191
  /** Cryptographically authenticated request binding, before dispatch authorization. */
177
192
  export type VerifySessionRequestResult = {
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, type JsonValue, participantDescriptor, type SerializableErrorData, } from "./generated_support.ts";
3
+ export { apiDescriptor, type AppRequestDescriptor, type Codec, codecs, type DeclaredErrorOptions, type JsonValue, participantDescriptor, type SerializableErrorData, } from "./generated_support.ts";
4
4
  export type { ParticipantJobsFromResources, ParticipantKvFromResources, RuntimeApiFromGenerated, } from "./participant_runtime/participant.ts";
@@ -3,6 +3,14 @@ export type Codec<T> = Readonly<{
3
3
  decode(value: unknown): T;
4
4
  encode(value: T): unknown;
5
5
  }>;
6
+ /** Optional fields when constructing a generated declared error. */
7
+ export type DeclaredErrorOptions = ErrorOptions & {
8
+ /** Human-readable message; defaults to the declared error's name. */
9
+ message?: string;
10
+ context?: Record<string, unknown>;
11
+ id?: string;
12
+ traceId?: string;
13
+ };
6
14
  /** Serializable fields shared by generated declared errors. */
7
15
  export type SerializableErrorData = {
8
16
  id: string;
@@ -17,10 +25,12 @@ type CodecValue<C> = C extends {
17
25
  type OpenEnum<T extends string> = T | (string & {
18
26
  readonly __openEnum?: never;
19
27
  });
20
- type Timestamp = string & {
28
+ /** An IDL `timestamp`: a canonical UTC RFC 3339 string. */
29
+ export type Timestamp = string & {
21
30
  readonly __timestamp: unique symbol;
22
31
  };
23
- type Ulid = string & {
32
+ /** An IDL `ulid`: a canonical ULID string. */
33
+ export type Ulid = string & {
24
34
  readonly __ulid: unique symbol;
25
35
  };
26
36
  type OptionalCodec<T> = Codec<T | undefined> & Readonly<{
@@ -32,6 +42,13 @@ type ModelValue<F extends Readonly<Record<string, ModelField>>> = {
32
42
  } & {
33
43
  [K in keyof F as F[K] extends OptionalCodec<unknown> ? K : never]?: Exclude<CodecValue<F[K]>, undefined>;
34
44
  };
45
+ /** Declared IDL constraints a generated codec enforces. */
46
+ type Limits = Readonly<{
47
+ min?: number | bigint;
48
+ max?: number | bigint;
49
+ minCount?: number;
50
+ maxCount?: number;
51
+ }>;
35
52
  /** A value the IDL `json` type carries unchecked. */
36
53
  export type JsonValue = null | boolean | number | string | JsonValue[] | {
37
54
  [key: string]: JsonValue;
@@ -82,6 +99,7 @@ export declare const codecs: Readonly<{
82
99
  decode(value: unknown): JsonValue;
83
100
  encode(value: JsonValue): unknown;
84
101
  }>;
102
+ bounded<T>(inner: Codec<T>, limits: Limits): Codec<T>;
85
103
  openEnum<const T extends string>(values: readonly T[]): Codec<OpenEnum<T>>;
86
104
  model<const F extends Readonly<Record<string, ModelField>>>(fields: F): Codec<ModelValue<F>>;
87
105
  named<T, Named extends T>(_name: string, value: Codec<T>): Codec<Named>;
@@ -83,6 +83,30 @@ 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
+ }
86
110
  /** Accept only values JSON can represent, so `json` round-trips exactly. */
87
111
  function jsonValue(value) {
88
112
  if (value === null || typeof value === "boolean" || typeof value === "string")
@@ -117,6 +141,16 @@ export const codecs = Object.freeze({
117
141
  ? value
118
142
  : fail("canonical ULID")),
119
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
+ },
120
154
  openEnum(values) {
121
155
  if (values.some((value) => typeof value !== "string")) {
122
156
  fail("generated string enum values");
@@ -1,6 +1,6 @@
1
1
  // Generated by Trellis. Do not edit.
2
2
  import { TrellisError } from "@oatscenter/trellis/generated";
3
- import type { SerializableErrorData } from "@oatscenter/trellis/generated";
3
+ import type { DeclaredErrorOptions, SerializableErrorData } from "@oatscenter/trellis/generated";
4
4
  import * as Types0 from "../../types/_internal/p0.js";
5
5
  export type AuthErrorData = SerializableErrorData & {
6
6
  readonly type: "trellis.auth@v1::AuthError";
@@ -9,8 +9,9 @@ export declare class AuthError extends TrellisError<AuthErrorData> {
9
9
  static readonly type: "trellis.auth@v1::AuthError";
10
10
  static readonly payloadCodec: typeof Types0.AuthErrorDetailsCodec;
11
11
  override readonly name: "AuthError";
12
- readonly data: AuthErrorData;
13
- constructor(data: AuthErrorData);
12
+ readonly payload: Types0.AuthErrorDetails;
13
+ constructor(payload: Types0.AuthErrorDetails, options?: DeclaredErrorOptions);
14
+ get data(): AuthErrorData;
14
15
  static fromSerializable(data: unknown): AuthError;
15
16
  override toSerializable(): AuthErrorData;
16
17
  }
@@ -21,8 +22,9 @@ export declare class UnexpectedError extends TrellisError<UnexpectedErrorData> {
21
22
  static readonly type: "trellis.auth@v1::UnexpectedError";
22
23
  static readonly payloadCodec: typeof Types0.AuthErrorDetailsCodec;
23
24
  override readonly name: "UnexpectedError";
24
- readonly data: UnexpectedErrorData;
25
- constructor(data: UnexpectedErrorData);
25
+ readonly payload: Types0.AuthErrorDetails;
26
+ constructor(payload: Types0.AuthErrorDetails, options?: DeclaredErrorOptions);
27
+ get data(): UnexpectedErrorData;
26
28
  static fromSerializable(data: unknown): UnexpectedError;
27
29
  override toSerializable(): UnexpectedErrorData;
28
30
  }
@@ -33,8 +35,9 @@ export declare class ValidationError extends TrellisError<ValidationErrorData> {
33
35
  static readonly type: "trellis.auth@v1::ValidationError";
34
36
  static readonly payloadCodec: typeof Types0.AuthErrorDetailsCodec;
35
37
  override readonly name: "ValidationError";
36
- readonly data: ValidationErrorData;
37
- constructor(data: ValidationErrorData);
38
+ readonly payload: Types0.AuthErrorDetails;
39
+ constructor(payload: Types0.AuthErrorDetails, options?: DeclaredErrorOptions);
40
+ get data(): ValidationErrorData;
38
41
  static fromSerializable(data: unknown): ValidationError;
39
42
  override toSerializable(): ValidationErrorData;
40
43
  }