@qlever-llc/trellis 0.10.7 → 0.10.9

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 (57) hide show
  1. package/esm/auth/protocol.d.ts +120 -3
  2. package/esm/auth/protocol.d.ts.map +1 -1
  3. package/esm/auth/protocol.js +43 -1
  4. package/esm/contract_support/mod.d.ts +1 -1
  5. package/esm/contract_support/mod.d.ts.map +1 -1
  6. package/esm/contract_support/mod.js +1 -1
  7. package/esm/contract_support/protocol.d.ts +67 -0
  8. package/esm/contract_support/protocol.d.ts.map +1 -1
  9. package/esm/contract_support/protocol.js +90 -0
  10. package/esm/generated-sdk/auth/contract.d.ts +1 -1
  11. package/esm/generated-sdk/auth/contract.d.ts.map +1 -1
  12. package/esm/generated-sdk/auth/contract.js +2 -2
  13. package/esm/generated-sdk/auth/schemas.d.ts +329 -2
  14. package/esm/generated-sdk/auth/schemas.d.ts.map +1 -1
  15. package/esm/generated-sdk/auth/schemas.js +3 -3
  16. package/esm/generated-sdk/auth/types.d.ts +47 -3
  17. package/esm/generated-sdk/auth/types.d.ts.map +1 -1
  18. package/esm/generated-sdk/auth/types.js +1 -1
  19. package/esm/index.d.ts +2 -2
  20. package/esm/index.d.ts.map +1 -1
  21. package/esm/index.js +1 -1
  22. package/esm/server/service.d.ts +11 -2
  23. package/esm/server/service.d.ts.map +1 -1
  24. package/esm/server/service.js +28 -4
  25. package/package.json +2 -2
  26. package/script/auth/protocol.d.ts +120 -3
  27. package/script/auth/protocol.d.ts.map +1 -1
  28. package/script/auth/protocol.js +47 -5
  29. package/script/contract_support/mod.d.ts +1 -1
  30. package/script/contract_support/mod.d.ts.map +1 -1
  31. package/script/contract_support/mod.js +8 -1
  32. package/script/contract_support/protocol.d.ts +67 -0
  33. package/script/contract_support/protocol.d.ts.map +1 -1
  34. package/script/contract_support/protocol.js +96 -1
  35. package/script/generated-sdk/auth/contract.d.ts +1 -1
  36. package/script/generated-sdk/auth/contract.d.ts.map +1 -1
  37. package/script/generated-sdk/auth/contract.js +2 -2
  38. package/script/generated-sdk/auth/schemas.d.ts +329 -2
  39. package/script/generated-sdk/auth/schemas.d.ts.map +1 -1
  40. package/script/generated-sdk/auth/schemas.js +3 -3
  41. package/script/generated-sdk/auth/types.d.ts +47 -3
  42. package/script/generated-sdk/auth/types.d.ts.map +1 -1
  43. package/script/generated-sdk/auth/types.js +1 -1
  44. package/script/index.d.ts +2 -2
  45. package/script/index.d.ts.map +1 -1
  46. package/script/index.js +9 -2
  47. package/script/server/service.d.ts +11 -2
  48. package/script/server/service.d.ts.map +1 -1
  49. package/script/server/service.js +27 -3
  50. package/src/auth/protocol.ts +55 -1
  51. package/src/contract_support/mod.ts +12 -0
  52. package/src/contract_support/protocol.ts +137 -0
  53. package/src/index.ts +12 -0
  54. package/src/sdk/_generated/auth/contract.ts +2 -2
  55. package/src/sdk/_generated/auth/schemas.ts +3 -3
  56. package/src/sdk/_generated/auth/types.ts +4 -4
  57. package/src/server/service.ts +52 -3
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _StoreHandle_nc, _TrellisService_instances, _TrellisService_server, _TrellisService_handlerTrellis, _TrellisService_operationTransfer, _TrellisService_stopHealthPublishing, _TrellisService_managedJobWorkers, _TrellisService_waitPromise, _TrellisService_stopPromise, _TrellisService_createBoundEventFacade, _TrellisService_createHandleFacade, _TrellisService_createBoundHandleFacade, _TrellisService_operation;
13
+ var _StoreHandle_nc, _TrellisService_instances, _TrellisService_server, _TrellisService_handlerTrellis, _TrellisService_operationTransfer, _TrellisService_stopHealthPublishing, _TrellisService_managedJobWorkers, _TrellisService_waitPromise, _TrellisService_stopPromise, _TrellisService_createBoundHealth, _TrellisService_createBoundEventFacade, _TrellisService_createHandleFacade, _TrellisService_createBoundHandleFacade, _TrellisService_operation;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.TrellisService = exports.StoreHandle = void 0;
16
16
  exports.createConnectedService = createConnectedService;
@@ -1223,7 +1223,7 @@ class TrellisService {
1223
1223
  kv: this.kv,
1224
1224
  store: this.store,
1225
1225
  jobs: createBoundJobsFacade({ jobs: this.jobs, deps }),
1226
- health: this.health,
1226
+ health: __classPrivateFieldGet(this, _TrellisService_instances, "m", _TrellisService_createBoundHealth).call(this, deps),
1227
1227
  handle: __classPrivateFieldGet(this, _TrellisService_instances, "m", _TrellisService_createBoundHandleFacade).call(this, deps),
1228
1228
  connection: this.connection,
1229
1229
  createTransfer: (args) => this.createTransfer(args),
@@ -1388,7 +1388,31 @@ class TrellisService {
1388
1388
  }
1389
1389
  }
1390
1390
  exports.TrellisService = TrellisService;
1391
- _TrellisService_server = new WeakMap(), _TrellisService_handlerTrellis = new WeakMap(), _TrellisService_operationTransfer = new WeakMap(), _TrellisService_stopHealthPublishing = new WeakMap(), _TrellisService_managedJobWorkers = new WeakMap(), _TrellisService_waitPromise = new WeakMap(), _TrellisService_stopPromise = new WeakMap(), _TrellisService_instances = new WeakSet(), _TrellisService_createBoundEventFacade = function _TrellisService_createBoundEventFacade(deps) {
1391
+ _TrellisService_server = new WeakMap(), _TrellisService_handlerTrellis = new WeakMap(), _TrellisService_operationTransfer = new WeakMap(), _TrellisService_stopHealthPublishing = new WeakMap(), _TrellisService_managedJobWorkers = new WeakMap(), _TrellisService_waitPromise = new WeakMap(), _TrellisService_stopPromise = new WeakMap(), _TrellisService_instances = new WeakSet(), _TrellisService_createBoundHealth = function _TrellisService_createBoundHealth(deps) {
1392
+ const health = this.health;
1393
+ return {
1394
+ serviceName: health.serviceName,
1395
+ kind: health.kind,
1396
+ instanceId: health.instanceId,
1397
+ contractId: health.contractId,
1398
+ contractDigest: health.contractDigest,
1399
+ startedAt: health.startedAt,
1400
+ publishIntervalMs: health.publishIntervalMs,
1401
+ setInfo(info) {
1402
+ if (typeof info !== "function") {
1403
+ health.setInfo(info);
1404
+ return;
1405
+ }
1406
+ health.setInfo(() => info({ deps }));
1407
+ },
1408
+ add(name, check) {
1409
+ return health.add(name, () => check({ deps }));
1410
+ },
1411
+ checks: () => health.checks(),
1412
+ response: () => health.response(),
1413
+ heartbeat: () => health.heartbeat(),
1414
+ };
1415
+ }, _TrellisService_createBoundEventFacade = function _TrellisService_createBoundEventFacade(deps) {
1392
1416
  const event = {};
1393
1417
  const source = this.event;
1394
1418
  for (const [groupName, leaves] of Object.entries(source)) {
@@ -173,6 +173,14 @@ export type DeploymentAuthorityCapability = StaticDecode<
173
173
  typeof DeploymentAuthorityCapabilitySchema
174
174
  >;
175
175
 
176
+ export const DeploymentAuthorityCapabilityDirectionSchema = Type.Union([
177
+ Type.Literal("creates"),
178
+ Type.Literal("given"),
179
+ ]);
180
+ export type DeploymentAuthorityCapabilityDirection = StaticDecode<
181
+ typeof DeploymentAuthorityCapabilityDirectionSchema
182
+ >;
183
+
176
184
  export const DeploymentAuthorityResourceSchema = Type.Object({
177
185
  kind: DeploymentAuthorityResourceKindSchema,
178
186
  alias: Type.String({ minLength: 1 }),
@@ -254,6 +262,50 @@ export type DeploymentResourceBinding = StaticDecode<
254
262
  typeof DeploymentResourceBindingSchema
255
263
  >;
256
264
 
265
+ export const MaterializedAuthoritySurfaceGrantSchema = Type.Object({
266
+ kind: Type.Literal("surface"),
267
+ contractId: Type.String({ minLength: 1 }),
268
+ surfaceKind: DeploymentAuthoritySurfaceKindSchema,
269
+ name: Type.String({ minLength: 1 }),
270
+ action: Type.Optional(DeploymentAuthoritySurfaceActionSchema),
271
+ });
272
+
273
+ export const MaterializedAuthorityCapabilityGrantSchema = Type.Object({
274
+ kind: Type.Literal("capability"),
275
+ capability: DeploymentAuthorityCapabilitySchema,
276
+ });
277
+
278
+ export const MaterializedAuthorityNatsGrantSourceSchema = Type.Union([
279
+ Type.Literal("owned-surface"),
280
+ Type.Literal("used-surface"),
281
+ Type.Literal("resource-binding"),
282
+ Type.Literal("platform-service"),
283
+ Type.Literal("transfer"),
284
+ ]);
285
+
286
+ export const MaterializedAuthorityNatsGrantSchema = Type.Object({
287
+ kind: Type.Literal("nats"),
288
+ direction: Type.Union([Type.Literal("publish"), Type.Literal("subscribe")]),
289
+ subject: Type.String({ minLength: 1 }),
290
+ surface: Type.Optional(Type.Object({
291
+ contractId: Type.String({ minLength: 1 }),
292
+ kind: DeploymentAuthoritySurfaceKindSchema,
293
+ name: Type.String({ minLength: 1 }),
294
+ action: Type.Optional(DeploymentAuthoritySurfaceActionSchema),
295
+ })),
296
+ requiredCapabilities: Type.Array(Type.String({ minLength: 1 })),
297
+ grantSource: MaterializedAuthorityNatsGrantSourceSchema,
298
+ });
299
+
300
+ export const MaterializedAuthorityGrantSchema = Type.Union([
301
+ MaterializedAuthorityCapabilityGrantSchema,
302
+ MaterializedAuthoritySurfaceGrantSchema,
303
+ MaterializedAuthorityNatsGrantSchema,
304
+ ]);
305
+ export type MaterializedAuthorityGrant = StaticDecode<
306
+ typeof MaterializedAuthorityGrantSchema
307
+ >;
308
+
257
309
  export const DeploymentAuthorityMaterializationSchema = Type.Object({
258
310
  deploymentId: Type.String({ minLength: 1 }),
259
311
  desiredVersion: Type.String({ minLength: 1 }),
@@ -263,7 +315,7 @@ export const DeploymentAuthorityMaterializationSchema = Type.Object({
263
315
  Type.Literal("failed"),
264
316
  ]),
265
317
  resourceBindings: Type.Array(DeploymentResourceBindingSchema),
266
- grants: Type.Array(OpenObjectSchema),
318
+ grants: Type.Array(MaterializedAuthorityGrantSchema),
267
319
  reconciledAt: Type.Union([IsoDateStringSchema, Type.Null()]),
268
320
  error: Type.Optional(Type.String({ minLength: 1 })),
269
321
  });
@@ -1615,6 +1667,7 @@ export const AuthUsersAccountFlowCreateResponseSchema = Type.Object({
1615
1667
  });
1616
1668
 
1617
1669
  export const CapabilityDefinitionSchema = Type.Object({
1670
+ deploymentId: Type.Optional(Type.String({ minLength: 1 })),
1618
1671
  key: Type.String({ minLength: 1 }),
1619
1672
  displayName: Type.String({ minLength: 1 }),
1620
1673
  description: Type.String({ minLength: 1 }),
@@ -1623,6 +1676,7 @@ export const CapabilityDefinitionSchema = Type.Object({
1623
1676
  contractId: Type.Optional(Type.String({ minLength: 1 })),
1624
1677
  contractDigest: Type.Optional(DigestSchema),
1625
1678
  contractDisplayName: Type.Optional(Type.String({ minLength: 1 })),
1679
+ direction: Type.Optional(DeploymentAuthorityCapabilityDirectionSchema),
1626
1680
  });
1627
1681
 
1628
1682
  export const AuthCapabilitiesListSchema = Type.Object({
@@ -68,6 +68,8 @@ import {
68
68
  } from "./protocol.js";
69
69
 
70
70
  export {
71
+ buildCursorPage,
72
+ buildPageResponse,
71
73
  type ContractEventConsumerEvent,
72
74
  ContractEventConsumerEventSchema,
73
75
  type ContractEventConsumerGroup,
@@ -83,6 +85,13 @@ export {
83
85
  ContractStateSchema,
84
86
  ContractStateStoreSchema,
85
87
  ContractStoreResourceSchema,
88
+ type CursorPage,
89
+ type CursorPageInfo,
90
+ CursorPageInfoSchema,
91
+ CursorPageSchema,
92
+ type CursorQuery,
93
+ type CursorQueryOptions,
94
+ CursorQuerySchema,
86
95
  type EventConsumerResourceBinding,
87
96
  EventConsumerResourceBindingSchema,
88
97
  type EventHeader,
@@ -96,6 +105,9 @@ export {
96
105
  JobsResourceBindingSchema,
97
106
  type KvResourceBinding,
98
107
  KvResourceBindingSchema,
108
+ normalizeCursorQuery,
109
+ type NormalizedCursorQuery,
110
+ normalizePageQuery,
99
111
  type PageRequest,
100
112
  PageRequestSchema,
101
113
  type PageResponse,
@@ -280,3 +280,140 @@ export type PageResponse<TEntry> = {
280
280
  limit: number;
281
281
  nextOffset?: number;
282
282
  };
283
+
284
+ /**
285
+ * Validates and normalizes an offset pagination query.
286
+ *
287
+ * Ensures `offset` and `limit` are non-negative integers within bounds. Throws
288
+ * `RangeError` on invalid input.
289
+ */
290
+ export function normalizePageQuery(
291
+ query: PageRequest,
292
+ maxLimit: number = Number.MAX_SAFE_INTEGER,
293
+ ): Required<PageRequest> {
294
+ if (!Number.isInteger(query.limit) || query.limit < 0) {
295
+ throw new RangeError("list limit must be a non-negative integer");
296
+ }
297
+ if (query.limit > maxLimit) {
298
+ throw new RangeError(`list limit must be <= ${maxLimit}`);
299
+ }
300
+ const offset = query.offset ?? 0;
301
+ if (!Number.isInteger(offset) || offset < 0) {
302
+ throw new RangeError("list offset must be a non-negative integer");
303
+ }
304
+ return { offset, limit: query.limit };
305
+ }
306
+
307
+ /**
308
+ * Builds a {@link PageResponse} from a pre-sliced offset page.
309
+ *
310
+ * @param entries - The entries for the current page, already sliced by the caller.
311
+ * @param totalCount - Total number of matching entries before slicing.
312
+ * @param query - The original pagination query used to produce the page.
313
+ * @param maxLimit - Optional maximum limit accepted by the endpoint.
314
+ */
315
+ export function buildPageResponse<T>(
316
+ entries: T[],
317
+ totalCount: number,
318
+ query: PageRequest,
319
+ maxLimit?: number,
320
+ ): PageResponse<T> {
321
+ const { offset, limit } = normalizePageQuery(query, maxLimit);
322
+ return {
323
+ entries,
324
+ count: totalCount,
325
+ offset,
326
+ limit,
327
+ nextOffset: limit <= 0 || offset + limit >= totalCount
328
+ ? undefined
329
+ : offset + limit,
330
+ };
331
+ }
332
+
333
+ /** Schema for a cursor pagination query. */
334
+ export const CursorQuerySchema = Type.Object({
335
+ cursor: Type.Optional(Type.String({ minLength: 1 })),
336
+ limit: Type.Optional(Type.Integer({ minimum: 0 })),
337
+ });
338
+
339
+ /** Cursor pagination query. */
340
+ export type CursorQuery = Static<typeof CursorQuerySchema>;
341
+
342
+ /** Schema for cursor pagination response metadata. */
343
+ export const CursorPageInfoSchema = Type.Object({
344
+ nextCursor: Type.Optional(Type.String({ minLength: 1 })),
345
+ });
346
+
347
+ /** Cursor pagination response metadata. */
348
+ export type CursorPageInfo = Static<typeof CursorPageInfoSchema>;
349
+
350
+ /** Create a schema for a cursor page response with typed items. */
351
+ export function CursorPageSchema<TItem extends TSchema>(item: TItem) {
352
+ return Type.Object({
353
+ items: Type.Array(item, { default: [] }),
354
+ page: CursorPageInfoSchema,
355
+ });
356
+ }
357
+
358
+ /** Cursor pagination response with typed items. */
359
+ export type CursorPage<TItem> = {
360
+ items: TItem[];
361
+ page: CursorPageInfo;
362
+ };
363
+
364
+ /** Options for normalizing a cursor pagination query. */
365
+ export type CursorQueryOptions = {
366
+ /** Limit used when the query does not specify one. Defaults to `100`. */
367
+ defaultLimit?: number;
368
+ /** Maximum accepted limit. Defaults to `500`. */
369
+ maxLimit?: number;
370
+ };
371
+
372
+ /** Cursor query after defaults and validation have been applied. */
373
+ export type NormalizedCursorQuery = {
374
+ cursor?: string;
375
+ limit: number;
376
+ };
377
+
378
+ /**
379
+ * Validates and normalizes a cursor pagination query.
380
+ *
381
+ * Defaults `limit` to `100`, rejects limits above `500` unless `maxLimit` is
382
+ * overridden, and preserves a non-empty optional cursor.
383
+ */
384
+ export function normalizeCursorQuery(
385
+ query: CursorQuery,
386
+ options: CursorQueryOptions = {},
387
+ ): NormalizedCursorQuery {
388
+ const maxLimit = options.maxLimit ?? 500;
389
+ const limit = query.limit ?? options.defaultLimit ?? 100;
390
+ if (!Number.isInteger(limit) || limit < 0) {
391
+ throw new RangeError("list limit must be a non-negative integer");
392
+ }
393
+ if (limit > maxLimit) {
394
+ throw new RangeError(`list limit must be <= ${maxLimit}`);
395
+ }
396
+ if (query.cursor === undefined) {
397
+ return { limit };
398
+ }
399
+ if (query.cursor.length === 0) {
400
+ throw new RangeError("list cursor must be a non-empty string");
401
+ }
402
+ return { cursor: query.cursor, limit };
403
+ }
404
+
405
+ /**
406
+ * Builds a {@link CursorPage} from items and an optional next cursor.
407
+ *
408
+ * @param items - The items for the current page.
409
+ * @param nextCursor - Cursor clients can use to request the next page.
410
+ */
411
+ export function buildCursorPage<T>(
412
+ items: T[],
413
+ nextCursor?: string,
414
+ ): CursorPage<T> {
415
+ return {
416
+ items,
417
+ page: nextCursor === undefined ? {} : { nextCursor },
418
+ };
419
+ }
package/src/index.ts CHANGED
@@ -57,12 +57,24 @@ export {
57
57
  } from "./health.js";
58
58
  export { defineError } from "./contract_support/mod.js";
59
59
  export {
60
+ buildCursorPage,
61
+ buildPageResponse,
62
+ CursorPageInfoSchema,
63
+ CursorPageSchema,
64
+ CursorQuerySchema,
65
+ normalizeCursorQuery,
66
+ normalizePageQuery,
60
67
  PageRequestSchema,
61
68
  PageResponseSchema,
62
69
  } from "./contract_support/mod.js";
63
70
  export type {
71
+ CursorPage,
72
+ CursorPageInfo,
73
+ CursorQuery,
74
+ CursorQueryOptions,
64
75
  ErrorClass,
65
76
  InferRuntimeRpcError,
77
+ NormalizedCursorQuery,
66
78
  PageRequest,
67
79
  PageResponse,
68
80
  RpcErrorClass,