@valon-technologies/gestalt 0.0.1-alpha.33 → 0.0.1-alpha.35

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.
@@ -1,5 +1,4 @@
1
1
  import { create } from "@bufbuild/protobuf";
2
- import { EmptySchema } from "@bufbuild/protobuf/wkt";
3
2
  import {
4
3
  Code,
5
4
  ConnectError,
@@ -9,662 +8,393 @@ import {
9
8
  } from "@connectrpc/connect";
10
9
 
11
10
  import {
12
- AccessDecisionSchema,
13
- AccessEvaluationRequestSchema,
14
- AccessEvaluationsRequestSchema,
15
- AccessEvaluationsResponseSchema,
16
- ActionSearchRequestSchema,
17
- ActionSearchResponseSchema,
18
- ActionSchema,
19
- AuthorizationMetadataSchema,
11
+ AddRelationshipResponseSchema,
20
12
  AuthorizationModelRefSchema,
21
- AuthorizationProvider as AuthorizationProviderService,
22
- EffectiveSubjectSearchRequestSchema,
23
- EffectiveSubjectSearchResponseSchema,
24
- ExpandNodeSchema,
25
- ExpandRequestSchema,
26
- ExpandResponseSchema,
27
- GetActiveModelResponseSchema,
28
- ListModelsRequestSchema,
29
- ListModelsResponseSchema,
30
- ReadRelationshipsRequestSchema,
31
- ReadRelationshipsResponseSchema,
32
- RelationshipKeySchema,
13
+ AuthorizationModelResourceTypeSchema,
14
+ CheckAccessManyResponseSchema,
15
+ CheckAccessResponseSchema,
16
+ DefaultAccessPolicy as ProtoDefaultAccessPolicy,
17
+ DeleteRelationshipResponseSchema,
18
+ GetActiveModelRefResponseSchema,
19
+ ListRelationshipsRequestSchema,
20
+ ListActiveModelResourceTypesResponseSchema,
21
+ ListRelationshipsResponseSchema,
22
+ ModelActionSchema,
23
+ ModelAllowedTargetSchema,
24
+ ModelRelationSchema,
33
25
  RelationshipSchema,
34
26
  RelationshipTargetSchema,
27
+ RelationshipTargetType as ProtoRelationshipTargetType,
28
+ RelationshipTupleSchema,
35
29
  ResourceSchema,
36
- ResourceSearchRequestSchema,
37
- ResourceSearchResponseSchema,
30
+ SetActiveModelResponseSchema,
31
+ SetAuthorizationStateResponseSchema,
32
+ SourceLayer as ProtoSourceLayer,
38
33
  SubjectSchema,
39
- SubjectSearchRequestSchema,
40
- SubjectSearchResponseSchema,
41
34
  SubjectSetSchema,
42
- WriteModelRequestSchema,
43
- WriteRelationshipsRequestSchema,
44
- type AccessDecision as ProtoAccessDecision,
45
- type AccessEvaluationRequest as ProtoAccessEvaluationRequest,
46
- type AccessEvaluationsRequest as ProtoAccessEvaluationsRequest,
47
- type AccessEvaluationsResponse as ProtoAccessEvaluationsResponse,
48
- type Action as ProtoAction,
49
- type ActionSearchRequest as ProtoActionSearchRequest,
50
- type ActionSearchResponse as ProtoActionSearchResponse,
51
- type AuthorizationMetadata as ProtoAuthorizationMetadata,
35
+ SubjectSetTypeSchema,
36
+ AuthorizationProvider as AuthorizationProviderService,
37
+ type AddRelationshipRequest as ProtoAddRelationshipRequest,
52
38
  type AuthorizationModel as ProtoAuthorizationModel,
53
- type AuthorizationModelAction as ProtoAuthorizationModelAction,
54
- type AuthorizationModelAllowedTarget as ProtoAuthorizationModelAllowedTarget,
55
- type AuthorizationModelComputedUserset as ProtoAuthorizationModelComputedUserset,
56
- type AuthorizationModelRef as ProtoAuthorizationModelRef,
57
- type AuthorizationModelRelation as ProtoAuthorizationModelRelation,
58
39
  type AuthorizationModelResourceType as ProtoAuthorizationModelResourceType,
59
- type AuthorizationModelRewrite as ProtoAuthorizationModelRewrite,
60
- type AuthorizationModelRewriteUnion as ProtoAuthorizationModelRewriteUnion,
61
- type AuthorizationModelSubjectSetTarget as ProtoAuthorizationModelSubjectSetTarget,
62
- type AuthorizationModelTupleToUserset as ProtoAuthorizationModelTupleToUserset,
63
- type EffectiveSubjectSearchRequest as ProtoEffectiveSubjectSearchRequest,
64
- type EffectiveSubjectSearchResponse as ProtoEffectiveSubjectSearchResponse,
65
- type ExpandNode as ProtoExpandNode,
66
- type ExpandRequest as ProtoExpandRequest,
67
- type ExpandResponse as ProtoExpandResponse,
68
- type GetActiveModelResponse as ProtoGetActiveModelResponse,
69
- type ListModelsRequest as ProtoListModelsRequest,
70
- type ListModelsResponse as ProtoListModelsResponse,
71
- type ReadRelationshipsRequest as ProtoReadRelationshipsRequest,
72
- type ReadRelationshipsResponse as ProtoReadRelationshipsResponse,
40
+ type CheckAccessManyRequest as ProtoCheckAccessManyRequest,
41
+ type CheckAccessRequest as ProtoCheckAccessRequest,
42
+ type DeleteRelationshipRequest as ProtoDeleteRelationshipRequest,
43
+ type ListActiveModelResourceTypesRequest as ProtoListActiveModelResourceTypesRequest,
44
+ type ListRelationshipsRequest as ProtoListRelationshipsRequest,
45
+ type ListRelationshipsResponse as ProtoListRelationshipsResponse,
46
+ type ModelAllowedTarget as ProtoModelAllowedTarget,
73
47
  type Relationship as ProtoRelationship,
74
- type RelationshipKey as ProtoRelationshipKey,
48
+ type RelationshipFilter as ProtoRelationshipFilter,
75
49
  type RelationshipTarget as ProtoRelationshipTarget,
76
- type Resource as ProtoResource,
77
- type ResourceSearchRequest as ProtoResourceSearchRequest,
78
- type ResourceSearchResponse as ProtoResourceSearchResponse,
79
- type Subject as ProtoSubject,
80
- type SubjectSearchRequest as ProtoSubjectSearchRequest,
81
- type SubjectSearchResponse as ProtoSubjectSearchResponse,
50
+ type RelationshipTuple as ProtoRelationshipTuple,
51
+ type SetActiveModelRequest as ProtoSetActiveModelRequest,
52
+ type SetAuthorizationStateRequest as ProtoSetAuthorizationStateRequest,
82
53
  type SubjectSet as ProtoSubjectSet,
83
- type WriteModelRequest as ProtoWriteModelRequest,
84
- type WriteRelationshipsRequest as ProtoWriteRelationshipsRequest,
85
54
  } from "./internal/gen/v1/authorization_pb.ts";
55
+ import { errorMessage, type MaybePromise } from "./api.ts";
56
+ import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
86
57
  import {
87
- dateFromTimestamp,
58
+ jsonObjectFromStruct,
59
+ structFromObject,
88
60
  timestampFromDate,
89
61
  type JsonObjectInput,
90
62
  } from "./protocol.ts";
91
- import {
92
- optionalObjectFromStruct,
93
- optionalStruct,
94
- } from "./protocol-internal.ts";
95
- import type { MaybePromise } from "./api.ts";
96
- import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
97
63
  import {
98
64
  createHostServiceGrpcTransport,
99
65
  hostServiceMetadataInterceptors,
100
66
  parseHostServiceTarget,
101
- ENV_HOST_SERVICE_SOCKET,
102
- ENV_HOST_SERVICE_TOKEN,
67
+ requireHostServiceTarget,
103
68
  } from "./host-service.ts";
104
69
 
105
- type AuthorizationProviderServiceImpl = Partial<
106
- ServiceImpl<typeof AuthorizationProviderService>
107
- >;
108
-
109
- /** Subject type used for canonical Gestalt subject ids in managed grants. */
110
- export const AUTHORIZATION_SUBJECT_TYPE_SUBJECT = "subject";
70
+ export const RelationshipTargetType = {
71
+ UNSPECIFIED: ProtoRelationshipTargetType.UNSPECIFIED,
72
+ SUBJECT: ProtoRelationshipTargetType.SUBJECT,
73
+ RESOURCE: ProtoRelationshipTargetType.RESOURCE,
74
+ SUBJECT_SET: ProtoRelationshipTargetType.SUBJECT_SET,
75
+ } as const;
76
+ export type RelationshipTargetType =
77
+ (typeof RelationshipTargetType)[keyof typeof RelationshipTargetType];
78
+
79
+ export const SourceLayer = {
80
+ UNSPECIFIED: ProtoSourceLayer.UNSPECIFIED,
81
+ STATIC_CONFIG: ProtoSourceLayer.STATIC_CONFIG,
82
+ RUNTIME: ProtoSourceLayer.RUNTIME,
83
+ } as const;
84
+ export type SourceLayer = (typeof SourceLayer)[keyof typeof SourceLayer];
85
+
86
+ export const DefaultAccessPolicy = {
87
+ DENY: ProtoDefaultAccessPolicy.DENY,
88
+ ALLOW: ProtoDefaultAccessPolicy.ALLOW,
89
+ } as const;
90
+ export type DefaultAccessPolicy =
91
+ (typeof DefaultAccessPolicy)[keyof typeof DefaultAccessPolicy];
111
92
 
112
93
  export interface AuthorizationSubject {
113
- type: string;
114
- id: string;
94
+ type?: string | undefined;
95
+ id?: string | undefined;
115
96
  properties?: JsonObjectInput | undefined;
116
97
  }
117
98
 
118
- export interface AuthorizationResource {
119
- type: string;
120
- id: string;
99
+ export interface AuthorizationAction {
100
+ name?: string | undefined;
121
101
  properties?: JsonObjectInput | undefined;
122
102
  }
123
103
 
124
- export interface AuthorizationSubjectSet {
125
- resource?: AuthorizationResource | undefined;
126
- relation: string;
127
- }
128
-
129
- export type AuthorizationRelationshipTargetKind =
130
- | { case: "subject"; value: AuthorizationSubject }
131
- | { case: "resource"; value: AuthorizationResource }
132
- | { case: "subjectSet"; value: AuthorizationSubjectSet }
133
- | { case: undefined; value?: undefined };
134
-
135
- export interface AuthorizationRelationshipTarget {
136
- kind: AuthorizationRelationshipTargetKind;
137
- }
138
-
139
- export interface AuthorizationAction {
140
- name: string;
104
+ export interface AuthorizationResource {
105
+ type?: string | undefined;
106
+ id?: string | undefined;
141
107
  properties?: JsonObjectInput | undefined;
142
108
  }
143
109
 
144
- export interface AuthorizationEvaluateInput {
110
+ export interface CheckAccessRequest {
145
111
  subject?: AuthorizationSubject | undefined;
146
112
  action?: AuthorizationAction | undefined;
147
113
  resource?: AuthorizationResource | undefined;
148
- context?: JsonObjectInput | undefined;
149
114
  }
150
115
 
151
- export interface AuthorizationDecision {
116
+ export interface CheckAccessResponse {
152
117
  allowed?: boolean | undefined;
153
- context?: JsonObjectInput | undefined;
154
118
  modelId?: string | undefined;
155
119
  }
156
120
 
157
- export interface AuthorizationEvaluateManyInput {
158
- requests: readonly AuthorizationEvaluateInput[];
121
+ export interface CheckAccessManyRequest {
122
+ requests?: readonly CheckAccessRequest[] | undefined;
159
123
  }
160
124
 
161
- export interface AuthorizationEvaluationsResponse {
162
- decisions: readonly AuthorizationDecision[];
125
+ export interface CheckAccessManyResponse {
126
+ decisions?: readonly CheckAccessResponse[] | undefined;
163
127
  }
164
128
 
165
- export interface AuthorizationSearchResourcesInput {
166
- subject?: AuthorizationSubject | undefined;
167
- action?: AuthorizationAction | undefined;
129
+ export interface RelationshipFilter {
130
+ target?: RelationshipTarget | undefined;
131
+ relation?: string | undefined;
132
+ resource?: AuthorizationResource | undefined;
133
+ targetType?: RelationshipTargetType | undefined;
134
+ targetEntityType?: string | undefined;
168
135
  resourceType?: string | undefined;
169
- context?: JsonObjectInput | undefined;
170
- pageSize?: number | undefined;
171
- pageToken?: string | undefined;
136
+ sourceLayer?: SourceLayer | undefined;
172
137
  }
173
138
 
174
- export interface AuthorizationResourceSearch {
175
- resources: readonly AuthorizationResource[];
176
- nextPageToken?: string | undefined;
177
- modelId?: string | undefined;
178
- }
179
-
180
- export interface AuthorizationSearchSubjectsInput {
181
- resource?: AuthorizationResource | undefined;
182
- action?: AuthorizationAction | undefined;
183
- subjectType?: string | undefined;
184
- context?: JsonObjectInput | undefined;
139
+ export interface ListRelationshipsRequest {
140
+ filter?: RelationshipFilter | undefined;
185
141
  pageSize?: number | undefined;
186
142
  pageToken?: string | undefined;
187
143
  }
188
144
 
189
- export interface AuthorizationSubjectSearch {
190
- subjects: readonly AuthorizationSubject[];
145
+ export interface ListRelationshipsResponse {
146
+ relationships?: readonly Relationship[] | undefined;
191
147
  nextPageToken?: string | undefined;
192
- modelId?: string | undefined;
193
148
  }
194
149
 
195
- export interface AuthorizationEffectiveSearchSubjectsInput {
196
- resource?: AuthorizationResource | undefined;
197
- action?: AuthorizationAction | undefined;
198
- context?: JsonObjectInput | undefined;
199
- pageSize?: number | undefined;
200
- pageToken?: string | undefined;
150
+ export interface AddRelationshipRequest {
151
+ relationship?: Relationship | undefined;
201
152
  }
202
153
 
203
- export interface AuthorizationEffectiveSubjectSearch {
204
- targets: readonly AuthorizationRelationshipTarget[];
205
- nextPageToken?: string | undefined;
206
- modelId?: string | undefined;
207
- truncated?: boolean | undefined;
154
+ export interface AddRelationshipResponse {
155
+ relationship?: Relationship | undefined;
208
156
  }
209
157
 
210
- export interface AuthorizationSearchActionsInput {
211
- subject?: AuthorizationSubject | undefined;
212
- resource?: AuthorizationResource | undefined;
213
- context?: JsonObjectInput | undefined;
214
- pageSize?: number | undefined;
215
- pageToken?: string | undefined;
158
+ export interface DeleteRelationshipRequest {
159
+ relationshipTuple?: RelationshipTuple | undefined;
216
160
  }
217
161
 
218
- export interface AuthorizationActionSearch {
219
- actions: readonly AuthorizationAction[];
220
- nextPageToken?: string | undefined;
221
- modelId?: string | undefined;
162
+ export interface DeleteRelationshipResponse {}
163
+
164
+ export interface SetAuthorizationStateRequest {
165
+ model?: AuthorizationModel | undefined;
166
+ relationships?: readonly Relationship[] | undefined;
222
167
  }
223
168
 
224
- export interface AuthorizationMetadata {
225
- capabilities?: readonly string[] | undefined;
226
- activeModelId?: string | undefined;
169
+ export interface SetAuthorizationStateResponse {
170
+ activeModel?: AuthorizationModelRef | undefined;
227
171
  }
228
172
 
229
- export interface AuthorizationRelationship {
230
- subject?: AuthorizationSubject | undefined;
231
- relation: string;
232
- resource?: AuthorizationResource | undefined;
173
+ export interface Relationship {
174
+ tuple?: RelationshipTuple | undefined;
233
175
  properties?: JsonObjectInput | undefined;
234
- target?: AuthorizationRelationshipTarget | undefined;
176
+ sourceLayer?: SourceLayer | undefined;
235
177
  }
236
178
 
237
- export interface AuthorizationRelationshipKey {
238
- subject?: AuthorizationSubject | undefined;
239
- relation: string;
179
+ export interface RelationshipTuple {
180
+ target?: RelationshipTarget | undefined;
181
+ relation?: string | undefined;
240
182
  resource?: AuthorizationResource | undefined;
241
- target?: AuthorizationRelationshipTarget | undefined;
242
183
  }
243
184
 
244
- export interface AuthorizationReadRelationshipsInput {
185
+ export interface RelationshipTarget {
245
186
  subject?: AuthorizationSubject | undefined;
246
- relation?: string | undefined;
247
187
  resource?: AuthorizationResource | undefined;
248
- pageSize?: number | undefined;
249
- pageToken?: string | undefined;
250
- modelId?: string | undefined;
251
- target?: AuthorizationRelationshipTarget | undefined;
252
- }
253
-
254
- export interface AuthorizationReadRelationships {
255
- relationships: readonly AuthorizationRelationship[];
256
- nextPageToken?: string | undefined;
257
- modelId?: string | undefined;
188
+ subjectSet?: SubjectSet | undefined;
258
189
  }
259
190
 
260
- export interface AuthorizationWriteRelationshipsInput {
261
- writes?: readonly AuthorizationRelationship[] | undefined;
262
- deletes?: readonly AuthorizationRelationshipKey[] | undefined;
263
- modelId?: string | undefined;
191
+ export interface SubjectSet {
192
+ resource?: AuthorizationResource | undefined;
193
+ relation?: string | undefined;
264
194
  }
265
195
 
266
196
  export interface AuthorizationModel {
267
- version?: number | undefined;
197
+ id?: string | undefined;
198
+ version?: string | undefined;
268
199
  resourceTypes?: readonly AuthorizationModelResourceType[] | undefined;
269
200
  }
270
201
 
271
202
  export interface AuthorizationModelResourceType {
272
- name: string;
273
- relations?: readonly AuthorizationModelRelation[] | undefined;
274
- actions?: readonly AuthorizationModelAction[] | undefined;
203
+ name?: string | undefined;
204
+ relations?: readonly ModelRelation[] | undefined;
205
+ actions?: readonly ModelAction[] | undefined;
206
+ sourceLayer?: SourceLayer | undefined;
207
+ defaultAccessPolicy?: DefaultAccessPolicy | undefined;
275
208
  }
276
209
 
277
- export interface AuthorizationModelRelation {
278
- name: string;
279
- subjectTypes?: readonly string[] | undefined;
280
- allowedTargets?: readonly AuthorizationModelAllowedTarget[] | undefined;
281
- rewrite?: AuthorizationModelRewrite | undefined;
210
+ export interface ModelRelation {
211
+ name?: string | undefined;
212
+ allowedTargets?: readonly ModelAllowedTarget[] | undefined;
282
213
  }
283
214
 
284
- export interface AuthorizationModelAction {
285
- name: string;
215
+ export interface ModelAction {
216
+ name?: string | undefined;
286
217
  relations?: readonly string[] | undefined;
287
- rewrite?: AuthorizationModelRewrite | undefined;
288
- }
289
-
290
- export type AuthorizationModelAllowedTargetKind =
291
- | { case: "subjectType"; value: string }
292
- | { case: "resourceType"; value: string }
293
- | { case: "subjectSet"; value: AuthorizationModelSubjectSetTarget }
294
- | { case: undefined; value?: undefined };
295
-
296
- export interface AuthorizationModelAllowedTarget {
297
- kind: AuthorizationModelAllowedTargetKind;
298
- }
299
-
300
- export interface AuthorizationModelSubjectSetTarget {
301
- resourceType: string;
302
- relation: string;
303
- }
304
-
305
- export type AuthorizationModelRewriteKind =
306
- | { case: "this"; value: AuthorizationModelRewriteThis }
307
- | { case: "computedUserset"; value: AuthorizationModelComputedUserset }
308
- | { case: "tupleToUserset"; value: AuthorizationModelTupleToUserset }
309
- | { case: "union"; value: AuthorizationModelRewriteUnion }
310
- | { case: undefined; value?: undefined };
311
-
312
- export interface AuthorizationModelRewrite {
313
- kind: AuthorizationModelRewriteKind;
314
- }
315
-
316
- export interface AuthorizationModelRewriteThis {}
317
-
318
- export interface AuthorizationModelComputedUserset {
319
- relation: string;
320
218
  }
321
219
 
322
- export interface AuthorizationModelTupleToUserset {
323
- tuplesetRelation: string;
324
- computedRelation: string;
220
+ export interface ModelAllowedTarget {
221
+ subjectType?: string | undefined;
222
+ resourceType?: string | undefined;
223
+ subjectSetType?: SubjectSetType | undefined;
325
224
  }
326
225
 
327
- export interface AuthorizationModelRewriteUnion {
328
- children?: readonly AuthorizationModelRewrite[] | undefined;
226
+ export interface SubjectSetType {
227
+ resourceType?: string | undefined;
228
+ relation?: string | undefined;
329
229
  }
330
230
 
331
231
  export interface AuthorizationModelRef {
332
- id: string;
333
- version: string;
232
+ id?: string | undefined;
233
+ version?: string | undefined;
334
234
  createdAt?: Date | undefined;
335
235
  }
336
236
 
337
- export interface AuthorizationExpandInput {
338
- resource?: AuthorizationResource | undefined;
339
- relation?: string | undefined;
340
- context?: JsonObjectInput | undefined;
341
- maxDepth?: number | undefined;
342
- modelId?: string | undefined;
237
+ export interface GetActiveModelRefResponse {
238
+ model?: AuthorizationModelRef | undefined;
343
239
  }
344
240
 
345
- export interface AuthorizationExpandNode {
346
- target?: AuthorizationRelationshipTarget | undefined;
347
- relation?: string | undefined;
348
- children?: readonly AuthorizationExpandNode[] | undefined;
241
+ export interface SetActiveModelRequest {
242
+ model?: AuthorizationModel | undefined;
349
243
  }
350
244
 
351
- export interface AuthorizationExpand {
352
- root?: AuthorizationExpandNode | undefined;
353
- truncated?: boolean | undefined;
354
- cycleDetected?: boolean | undefined;
355
- maxDepthReached?: boolean | undefined;
356
- modelId?: string | undefined;
245
+ export interface SetActiveModelResponse {
246
+ model?: AuthorizationModelRef | undefined;
357
247
  }
358
248
 
359
- export interface AuthorizationGetActiveModel {
360
- model?: AuthorizationModelRef | undefined;
249
+ export interface AuthorizationModelResourceTypeFilter {
250
+ name?: string | undefined;
251
+ sourceLayer?: SourceLayer | undefined;
361
252
  }
362
253
 
363
- export interface AuthorizationListModelsInput {
254
+ export interface ListActiveModelResourceTypesRequest {
255
+ filter?: AuthorizationModelResourceTypeFilter | undefined;
364
256
  pageSize?: number | undefined;
365
257
  pageToken?: string | undefined;
366
258
  }
367
259
 
368
- export interface AuthorizationListModels {
369
- models?: readonly AuthorizationModelRef[] | undefined;
260
+ export interface ListActiveModelResourceTypesResponse {
261
+ resourceTypes?: readonly AuthorizationModelResourceType[] | undefined;
370
262
  nextPageToken?: string | undefined;
263
+ modelId?: string | undefined;
371
264
  }
372
265
 
373
- export interface AuthorizationWriteModelInput {
374
- model?: AuthorizationModel | undefined;
266
+ export interface Authorization {
267
+ listRelationships(
268
+ request: ListRelationshipsRequest,
269
+ ): Promise<ListRelationshipsResponse>;
375
270
  }
376
271
 
377
- const sharedAuthorizationTransport: {
378
- target: string;
379
- token: string;
380
- client: AuthorizationImpl | undefined;
381
- } = {
382
- target: "",
383
- token: "",
384
- client: undefined,
385
- };
386
-
387
- /**
388
- * Fakeable contract for authorization calls.
389
- */
390
- export interface Authorization {
391
- evaluate(request: AuthorizationEvaluateInput): Promise<AuthorizationDecision>;
392
- evaluateMany(
393
- request: AuthorizationEvaluateManyInput,
394
- ): Promise<AuthorizationEvaluationsResponse>;
395
- searchResources(
396
- request: AuthorizationSearchResourcesInput,
397
- ): Promise<AuthorizationResourceSearch>;
398
- searchSubjects(
399
- request: AuthorizationSearchSubjectsInput,
400
- ): Promise<AuthorizationSubjectSearch>;
401
- effectiveSearchResources(
402
- request: AuthorizationSearchResourcesInput,
403
- ): Promise<AuthorizationResourceSearch>;
404
- effectiveSearchSubjects(
405
- request: AuthorizationEffectiveSearchSubjectsInput,
406
- ): Promise<AuthorizationEffectiveSubjectSearch>;
407
- searchActions(
408
- request: AuthorizationSearchActionsInput,
409
- ): Promise<AuthorizationActionSearch>;
410
- expand(request: AuthorizationExpandInput): Promise<AuthorizationExpand>;
411
- readRelationships(
412
- request: AuthorizationReadRelationshipsInput,
413
- ): Promise<AuthorizationReadRelationships>;
414
- writeRelationships(
415
- request: AuthorizationWriteRelationshipsInput,
416
- ): Promise<void>;
417
- getMetadata(): Promise<AuthorizationMetadata>;
418
- getActiveModel(): Promise<AuthorizationGetActiveModel>;
419
- listModels(
420
- request?: AuthorizationListModelsInput,
421
- ): Promise<AuthorizationListModels>;
422
- writeModel(
423
- request: AuthorizationWriteModelInput,
424
- ): Promise<AuthorizationModelRef>;
425
- }
426
-
427
- /**
428
- * Client for the configured authorization provider.
429
- *
430
- * The client accepts plain SDK request objects and keeps transport message
431
- * construction inside the SDK.
432
- */
433
272
  class AuthorizationImpl implements Authorization {
434
273
  private readonly client: Client<typeof AuthorizationProviderService>;
435
274
 
436
- constructor(
437
- socketTarget?: string,
438
- relayToken = process.env[ENV_HOST_SERVICE_TOKEN]?.trim() ?? "",
439
- ) {
440
- const resolvedTarget = resolveAuthorizationSocketTarget(socketTarget);
275
+ constructor(target?: string, relayToken?: string) {
276
+ const host = target
277
+ ? { target, token: relayToken?.trim() ?? "" }
278
+ : requireHostServiceTarget("authorization");
441
279
  const transport = createHostServiceGrpcTransport(
442
- parseHostServiceTarget("authorization", resolvedTarget),
443
- hostServiceMetadataInterceptors(relayToken, ""),
280
+ parseHostServiceTarget("authorization", host.target),
281
+ hostServiceMetadataInterceptors(host.token, ""),
444
282
  );
445
283
  this.client = createClient(AuthorizationProviderService, transport);
446
284
  }
447
285
 
448
- async evaluate(
449
- request: AuthorizationEvaluateInput,
450
- ): Promise<AuthorizationDecision> {
451
- return authorizationDecisionFromProto(
452
- await this.client.evaluate(authorizationEvaluateInputToProto(request)),
453
- );
454
- }
455
-
456
- async evaluateMany(
457
- request: AuthorizationEvaluateManyInput,
458
- ): Promise<AuthorizationEvaluationsResponse> {
459
- return authorizationEvaluationsResponseFromProto(
460
- await this.client.evaluateMany(authorizationEvaluateManyInputToProto(request)),
461
- );
462
- }
463
-
464
- async searchResources(
465
- request: AuthorizationSearchResourcesInput,
466
- ): Promise<AuthorizationResourceSearch> {
467
- return authorizationResourceSearchFromProto(
468
- await this.client.searchResources(authorizationSearchResourcesInputToProto(request)),
469
- );
470
- }
471
-
472
- async searchSubjects(
473
- request: AuthorizationSearchSubjectsInput,
474
- ): Promise<AuthorizationSubjectSearch> {
475
- return authorizationSubjectSearchFromProto(
476
- await this.client.searchSubjects(authorizationSearchSubjectsInputToProto(request)),
477
- );
478
- }
479
-
480
- async effectiveSearchResources(
481
- request: AuthorizationSearchResourcesInput,
482
- ): Promise<AuthorizationResourceSearch> {
483
- return authorizationResourceSearchFromProto(
484
- await this.client.effectiveSearchResources(authorizationSearchResourcesInputToProto(request)),
485
- );
486
- }
487
-
488
- async effectiveSearchSubjects(
489
- request: AuthorizationEffectiveSearchSubjectsInput,
490
- ): Promise<AuthorizationEffectiveSubjectSearch> {
491
- return authorizationEffectiveSubjectSearchFromProto(
492
- await this.client.effectiveSearchSubjects(authorizationEffectiveSearchSubjectsInputToProto(request)),
493
- );
494
- }
495
-
496
- async searchActions(
497
- request: AuthorizationSearchActionsInput,
498
- ): Promise<AuthorizationActionSearch> {
499
- return authorizationActionSearchFromProto(
500
- await this.client.searchActions(authorizationSearchActionsInputToProto(request)),
501
- );
502
- }
503
-
504
- async expand(
505
- request: AuthorizationExpandInput,
506
- ): Promise<AuthorizationExpand> {
507
- return authorizationExpandFromProto(
508
- await this.client.expand(authorizationExpandInputToProto(request)),
286
+ async listRelationships(
287
+ request: ListRelationshipsRequest,
288
+ ): Promise<ListRelationshipsResponse> {
289
+ return listRelationshipsResponseFromProto(
290
+ await this.client.listRelationships(listRelationshipsRequestToProto(request)),
509
291
  );
510
292
  }
293
+ }
511
294
 
512
- async readRelationships(
513
- request: AuthorizationReadRelationshipsInput,
514
- ): Promise<AuthorizationReadRelationships> {
515
- return authorizationReadRelationshipsFromProto(
516
- await this.client.readRelationships(authorizationReadRelationshipsInputToProto(request)),
517
- );
518
- }
519
-
520
- /** Writes and deletes authorization relationships. */
521
- async writeRelationships(
522
- request: AuthorizationWriteRelationshipsInput,
523
- ): Promise<void> {
524
- await this.client.writeRelationships(authorizationWriteRelationshipsInputToProto(request));
525
- }
526
-
527
- async getMetadata(): Promise<AuthorizationMetadata> {
528
- return authorizationMetadataFromProto(await this.client.getMetadata({}));
529
- }
530
-
531
- async getActiveModel(): Promise<AuthorizationGetActiveModel> {
532
- return authorizationGetActiveModelFromProto(await this.client.getActiveModel({}));
533
- }
295
+ let sharedAuthorization:
296
+ | { target: string; token: string; client: Authorization }
297
+ | undefined;
534
298
 
535
- async listModels(
536
- request: AuthorizationListModelsInput = {},
537
- ): Promise<AuthorizationListModels> {
538
- return authorizationListModelsFromProto(
539
- await this.client.listModels(authorizationListModelsInputToProto(request)),
540
- );
299
+ export function Authorization(): Authorization {
300
+ const { target, token } = requireHostServiceTarget("authorization");
301
+ if (
302
+ sharedAuthorization &&
303
+ sharedAuthorization.target === target &&
304
+ sharedAuthorization.token === token
305
+ ) {
306
+ return sharedAuthorization.client;
541
307
  }
542
308
 
543
- async writeModel(
544
- request: AuthorizationWriteModelInput,
545
- ): Promise<AuthorizationModelRef> {
546
- return authorizationModelRefFromProtoRequired(
547
- await this.client.writeModel(authorizationWriteModelInputToProto(request)),
548
- );
549
- }
309
+ const client = new AuthorizationImpl(target, token);
310
+ sharedAuthorization = { target, token, client };
311
+ return client;
550
312
  }
551
313
 
552
314
  export interface AuthorizationProviderOptions extends ProviderBaseOptions {
553
- evaluate: (
554
- request: AuthorizationEvaluateInput,
555
- ) => MaybePromise<AuthorizationDecision>;
556
- evaluateMany: (
557
- request: AuthorizationEvaluateManyInput,
558
- ) => MaybePromise<AuthorizationEvaluationsResponse>;
559
- searchResources: (
560
- request: AuthorizationSearchResourcesInput,
561
- ) => MaybePromise<AuthorizationResourceSearch>;
562
- searchSubjects: (
563
- request: AuthorizationSearchSubjectsInput,
564
- ) => MaybePromise<AuthorizationSubjectSearch>;
565
- effectiveSearchResources?: (
566
- request: AuthorizationSearchResourcesInput,
567
- ) => MaybePromise<AuthorizationResourceSearch>;
568
- effectiveSearchSubjects?: (
569
- request: AuthorizationEffectiveSearchSubjectsInput,
570
- ) => MaybePromise<AuthorizationEffectiveSubjectSearch>;
571
- searchActions: (
572
- request: AuthorizationSearchActionsInput,
573
- ) => MaybePromise<AuthorizationActionSearch>;
574
- expand?: (
575
- request: AuthorizationExpandInput,
576
- ) => MaybePromise<AuthorizationExpand>;
577
- getMetadata: () => MaybePromise<AuthorizationMetadata>;
578
- readRelationships: (
579
- request: AuthorizationReadRelationshipsInput,
580
- ) => MaybePromise<AuthorizationReadRelationships>;
581
- writeRelationships: (
582
- request: AuthorizationWriteRelationshipsInput,
583
- ) => MaybePromise<void>;
584
- getActiveModel: () => MaybePromise<AuthorizationGetActiveModel>;
585
- listModels: (
586
- request: AuthorizationListModelsInput,
587
- ) => MaybePromise<AuthorizationListModels>;
588
- writeModel: (
589
- request: AuthorizationWriteModelInput,
590
- ) => MaybePromise<AuthorizationModelRef>;
315
+ checkAccess: (request: CheckAccessRequest) => MaybePromise<CheckAccessResponse>;
316
+ checkAccessMany: (
317
+ request: CheckAccessManyRequest,
318
+ ) => MaybePromise<CheckAccessManyResponse>;
319
+ listRelationships: (
320
+ request: ListRelationshipsRequest,
321
+ ) => MaybePromise<ListRelationshipsResponse>;
322
+ addRelationship: (
323
+ request: AddRelationshipRequest,
324
+ ) => MaybePromise<AddRelationshipResponse>;
325
+ deleteRelationship: (
326
+ request: DeleteRelationshipRequest,
327
+ ) => MaybePromise<DeleteRelationshipResponse | void>;
328
+ setAuthorizationState: (
329
+ request: SetAuthorizationStateRequest,
330
+ ) => MaybePromise<SetAuthorizationStateResponse>;
331
+ getActiveModelRef: () => MaybePromise<GetActiveModelRefResponse>;
332
+ setActiveModel: (
333
+ request: SetActiveModelRequest,
334
+ ) => MaybePromise<SetActiveModelResponse>;
335
+ listActiveModelResourceTypes: (
336
+ request: ListActiveModelResourceTypesRequest,
337
+ ) => MaybePromise<ListActiveModelResourceTypesResponse>;
591
338
  }
592
339
 
593
340
  export class AuthorizationProvider extends ProviderBase {
594
341
  readonly kind = "authorization" as const;
595
342
 
596
- private readonly options: AuthorizationProviderOptions;
343
+ private readonly handlers: AuthorizationProviderOptions;
597
344
 
598
345
  constructor(options: AuthorizationProviderOptions) {
599
346
  super(options);
600
- this.options = options;
601
- }
602
-
603
- async evaluate(request: AuthorizationEvaluateInput) {
604
- return await this.options.evaluate(request);
605
- }
606
-
607
- async evaluateMany(request: AuthorizationEvaluateManyInput) {
608
- return await this.options.evaluateMany(request);
609
- }
610
-
611
- async searchResources(request: AuthorizationSearchResourcesInput) {
612
- return await this.options.searchResources(request);
613
- }
614
-
615
- async searchSubjects(request: AuthorizationSearchSubjectsInput) {
616
- return await this.options.searchSubjects(request);
617
- }
618
-
619
- supportsEffectiveSearch(): boolean {
620
- return (
621
- this.options.effectiveSearchResources !== undefined &&
622
- this.options.effectiveSearchSubjects !== undefined
623
- );
347
+ this.handlers = options;
624
348
  }
625
349
 
626
- async effectiveSearchResources(request: AuthorizationSearchResourcesInput) {
627
- return await this.options.effectiveSearchResources?.(request);
350
+ checkAccess(request: CheckAccessRequest): Promise<CheckAccessResponse> {
351
+ return Promise.resolve(this.handlers.checkAccess(request));
628
352
  }
629
353
 
630
- async effectiveSearchSubjects(request: AuthorizationEffectiveSearchSubjectsInput) {
631
- return await this.options.effectiveSearchSubjects?.(request);
354
+ checkAccessMany(
355
+ request: CheckAccessManyRequest,
356
+ ): Promise<CheckAccessManyResponse> {
357
+ return Promise.resolve(this.handlers.checkAccessMany(request));
632
358
  }
633
359
 
634
- async searchActions(request: AuthorizationSearchActionsInput) {
635
- return await this.options.searchActions(request);
360
+ listRelationships(
361
+ request: ListRelationshipsRequest,
362
+ ): Promise<ListRelationshipsResponse> {
363
+ return Promise.resolve(this.handlers.listRelationships(request));
636
364
  }
637
365
 
638
- supportsExpand(): boolean {
639
- return this.options.expand !== undefined;
366
+ addRelationship(
367
+ request: AddRelationshipRequest,
368
+ ): Promise<AddRelationshipResponse> {
369
+ return Promise.resolve(this.handlers.addRelationship(request));
640
370
  }
641
371
 
642
- async expand(request: AuthorizationExpandInput) {
643
- return await this.options.expand?.(request);
372
+ deleteRelationship(
373
+ request: DeleteRelationshipRequest,
374
+ ): Promise<DeleteRelationshipResponse | void> {
375
+ return Promise.resolve(this.handlers.deleteRelationship(request));
644
376
  }
645
377
 
646
- async getMetadata() {
647
- return await this.options.getMetadata();
378
+ setAuthorizationState(
379
+ request: SetAuthorizationStateRequest,
380
+ ): Promise<SetAuthorizationStateResponse> {
381
+ return Promise.resolve(this.handlers.setAuthorizationState(request));
648
382
  }
649
383
 
650
- async readRelationships(request: AuthorizationReadRelationshipsInput) {
651
- return await this.options.readRelationships(request);
384
+ getActiveModelRef(): Promise<GetActiveModelRefResponse> {
385
+ return Promise.resolve(this.handlers.getActiveModelRef());
652
386
  }
653
387
 
654
- async writeRelationships(request: AuthorizationWriteRelationshipsInput): Promise<void> {
655
- await this.options.writeRelationships(request);
388
+ setActiveModel(
389
+ request: SetActiveModelRequest,
390
+ ): Promise<SetActiveModelResponse> {
391
+ return Promise.resolve(this.handlers.setActiveModel(request));
656
392
  }
657
393
 
658
- async getActiveModel() {
659
- return await this.options.getActiveModel();
660
- }
661
-
662
- async listModels(request: AuthorizationListModelsInput) {
663
- return await this.options.listModels(request);
664
- }
665
-
666
- async writeModel(request: AuthorizationWriteModelInput) {
667
- return await this.options.writeModel(request);
394
+ listActiveModelResourceTypes(
395
+ request: ListActiveModelResourceTypesRequest,
396
+ ): Promise<ListActiveModelResourceTypesResponse> {
397
+ return Promise.resolve(this.handlers.listActiveModelResourceTypes(request));
668
398
  }
669
399
  }
670
400
 
@@ -683,1086 +413,631 @@ export function isAuthorizationProvider(
683
413
  value !== null &&
684
414
  "kind" in value &&
685
415
  String((value as { kind?: unknown }).kind ?? "") === "authorization" &&
686
- "evaluate" in value &&
687
- "evaluateMany" in value &&
688
- "searchResources" in value &&
689
- "searchSubjects" in value &&
690
- "searchActions" in value &&
691
- "getMetadata" in value &&
692
- "readRelationships" in value &&
693
- "writeRelationships" in value &&
694
- "getActiveModel" in value &&
695
- "listModels" in value &&
696
- "writeModel" in value)
416
+ "checkAccess" in value &&
417
+ "checkAccessMany" in value &&
418
+ "listRelationships" in value &&
419
+ "addRelationship" in value &&
420
+ "deleteRelationship" in value &&
421
+ "setAuthorizationState" in value &&
422
+ "getActiveModelRef" in value &&
423
+ "setActiveModel" in value &&
424
+ "listActiveModelResourceTypes" in value)
697
425
  );
698
426
  }
699
427
 
700
428
  export function createAuthorizationProviderService(
701
429
  provider: AuthorizationProvider,
702
- ): AuthorizationProviderServiceImpl {
430
+ ): Partial<ServiceImpl<typeof AuthorizationProviderService>> {
703
431
  return {
704
- async evaluate(request) {
705
- return authorizationDecisionToProto(
706
- requiredAuthorizationResponse(
707
- await provider.evaluate(authorizationEvaluateInputFromProto(request)),
708
- "evaluate",
709
- ),
710
- );
711
- },
712
- async evaluateMany(request) {
713
- return authorizationEvaluationsResponseToProto(
714
- requiredAuthorizationResponse(
715
- await provider.evaluateMany(authorizationEvaluateManyInputFromProto(request)),
716
- "evaluate many",
717
- ),
718
- );
719
- },
720
- async searchResources(request) {
721
- return authorizationResourceSearchToProto(
722
- requiredAuthorizationResponse(
723
- await provider.searchResources(authorizationSearchResourcesInputFromProto(request)),
724
- "search resources",
725
- ),
726
- );
727
- },
728
- async searchSubjects(request) {
729
- return authorizationSubjectSearchToProto(
730
- requiredAuthorizationResponse(
731
- await provider.searchSubjects(authorizationSearchSubjectsInputFromProto(request)),
732
- "search subjects",
733
- ),
734
- );
735
- },
736
- async effectiveSearchResources(request) {
737
- if (!provider.supportsEffectiveSearch()) {
738
- throw new ConnectError(
739
- "authorization provider does not support effective search",
740
- Code.Unimplemented,
432
+ async checkAccess(request) {
433
+ try {
434
+ return checkAccessResponseToProto(
435
+ await provider.checkAccess(checkAccessRequestFromProto(request)),
741
436
  );
437
+ } catch (error) {
438
+ throw authorizationRuntimeError("check access", error);
742
439
  }
743
- return authorizationResourceSearchToProto(
744
- requiredAuthorizationResponse(
745
- await provider.effectiveSearchResources(authorizationSearchResourcesInputFromProto(request)),
746
- "effective search resources",
747
- ),
748
- );
749
440
  },
750
- async effectiveSearchSubjects(request) {
751
- if (!provider.supportsEffectiveSearch()) {
752
- throw new ConnectError(
753
- "authorization provider does not support effective search",
754
- Code.Unimplemented,
441
+ async checkAccessMany(request) {
442
+ try {
443
+ return checkAccessManyResponseToProto(
444
+ await provider.checkAccessMany(checkAccessManyRequestFromProto(request)),
755
445
  );
446
+ } catch (error) {
447
+ throw authorizationRuntimeError("check access many", error);
756
448
  }
757
- return authorizationEffectiveSubjectSearchToProto(
758
- requiredAuthorizationResponse(
759
- await provider.effectiveSearchSubjects(authorizationEffectiveSearchSubjectsInputFromProto(request)),
760
- "effective search subjects",
761
- ),
762
- );
763
449
  },
764
- async searchActions(request) {
765
- return authorizationActionSearchToProto(
766
- requiredAuthorizationResponse(
767
- await provider.searchActions(authorizationSearchActionsInputFromProto(request)),
768
- "search actions",
769
- ),
770
- );
771
- },
772
- async expand(request) {
773
- if (!provider.supportsExpand()) {
774
- throw new ConnectError(
775
- "authorization provider does not support expansion",
776
- Code.Unimplemented,
450
+ async listRelationships(request) {
451
+ try {
452
+ return listRelationshipsResponseToProto(
453
+ await provider.listRelationships(listRelationshipsRequestFromProto(request)),
777
454
  );
455
+ } catch (error) {
456
+ throw authorizationRuntimeError("list relationships", error);
778
457
  }
779
- return authorizationExpandToProto(
780
- requiredAuthorizationResponse(
781
- await provider.expand(authorizationExpandInputFromProto(request)),
782
- "expand",
783
- ),
784
- );
785
458
  },
786
- async getMetadata() {
787
- const metadata = authorizationMetadataToProto(
788
- requiredAuthorizationResponse(await provider.getMetadata(), "metadata"),
789
- );
790
- if (provider.supportsEffectiveSearch()) {
791
- pushCapability(metadata.capabilities, "effective_search_resources");
792
- pushCapability(metadata.capabilities, "effective_search_subjects");
793
- }
794
- if (provider.supportsExpand()) {
795
- pushCapability(metadata.capabilities, "expand");
459
+ async addRelationship(request) {
460
+ try {
461
+ return addRelationshipResponseToProto(
462
+ await provider.addRelationship(addRelationshipRequestFromProto(request)),
463
+ );
464
+ } catch (error) {
465
+ throw authorizationRuntimeError("add relationship", error);
796
466
  }
797
- return metadata;
798
- },
799
- async readRelationships(request) {
800
- return authorizationReadRelationshipsToProto(
801
- requiredAuthorizationResponse(
802
- await provider.readRelationships(authorizationReadRelationshipsInputFromProto(request)),
803
- "read relationships",
804
- ),
805
- );
806
467
  },
807
- async writeRelationships(request) {
808
- await provider.writeRelationships(authorizationWriteRelationshipsInputFromProto(request));
809
- return create(EmptySchema, {});
468
+ async deleteRelationship(request) {
469
+ try {
470
+ await provider.deleteRelationship(deleteRelationshipRequestFromProto(request));
471
+ return create(DeleteRelationshipResponseSchema);
472
+ } catch (error) {
473
+ throw authorizationRuntimeError("delete relationship", error);
474
+ }
810
475
  },
811
- async getActiveModel() {
812
- return authorizationGetActiveModelToProto(
813
- requiredAuthorizationResponse(
814
- await provider.getActiveModel(),
815
- "get active model",
816
- ),
817
- );
476
+ async setAuthorizationState(request) {
477
+ try {
478
+ return setAuthorizationStateResponseToProto(
479
+ await provider.setAuthorizationState(
480
+ setAuthorizationStateRequestFromProto(request),
481
+ ),
482
+ );
483
+ } catch (error) {
484
+ throw authorizationRuntimeError("set authorization state", error);
485
+ }
818
486
  },
819
- async listModels(request) {
820
- return authorizationListModelsToProto(
821
- requiredAuthorizationResponse(
822
- await provider.listModels(authorizationListModelsInputFromProto(request)),
823
- "list models",
824
- ),
825
- );
487
+ async getActiveModelRef() {
488
+ try {
489
+ return getActiveModelRefResponseToProto(await provider.getActiveModelRef());
490
+ } catch (error) {
491
+ throw authorizationRuntimeError("get active model ref", error);
492
+ }
826
493
  },
827
- async writeModel(request) {
828
- return authorizationModelRefToProto(
829
- requiredAuthorizationResponse(
830
- await provider.writeModel(authorizationWriteModelInputFromProto(request)),
831
- "write model",
832
- ),
833
- );
494
+ async setActiveModel(request) {
495
+ try {
496
+ return setActiveModelResponseToProto(
497
+ await provider.setActiveModel(setActiveModelRequestFromProto(request)),
498
+ );
499
+ } catch (error) {
500
+ throw authorizationRuntimeError("set active model", error);
501
+ }
834
502
  },
835
- };
836
- }
837
-
838
- function requiredAuthorizationResponse<T>(
839
- value: T | null | undefined,
840
- label: string,
841
- ): T {
842
- if (value === null || value === undefined) {
843
- throw new ConnectError(
844
- `authorization provider returned nil ${label} response`,
845
- Code.Internal,
846
- );
847
- }
848
- return value;
849
- }
850
-
851
- /**
852
- * Returns a shared authorization capability for authored providers.
853
- */
854
- export function Authorization(): Authorization {
855
- const target = resolveAuthorizationSocketTarget();
856
- const token = process.env[ENV_HOST_SERVICE_TOKEN]?.trim() ?? "";
857
- if (
858
- sharedAuthorizationTransport.client &&
859
- sharedAuthorizationTransport.target === target &&
860
- sharedAuthorizationTransport.token === token
861
- ) {
862
- return sharedAuthorizationTransport.client;
863
- }
864
-
865
- const client = new AuthorizationImpl(target, token);
866
- sharedAuthorizationTransport.target = target;
867
- sharedAuthorizationTransport.token = token;
868
- sharedAuthorizationTransport.client = client;
869
- return client;
870
- }
871
-
872
- /** Creates an authorization subject reference. */
873
- export function authorizationSubject(
874
- type: string,
875
- id: string,
876
- properties?: JsonObjectInput,
877
- ): AuthorizationSubject {
878
- return properties === undefined ? { type, id } : { type, id, properties };
879
- }
880
-
881
- /** Creates an authorization resource reference. */
882
- export function authorizationResource(
883
- type: string,
884
- id: string,
885
- properties?: JsonObjectInput,
886
- ): AuthorizationResource {
887
- return properties === undefined ? { type, id } : { type, id, properties };
888
- }
889
-
890
- /** Creates an authorization subject-set reference. */
891
- export function authorizationSubjectSet(
892
- resource: AuthorizationResource,
893
- relation: string,
894
- ): AuthorizationSubjectSet {
895
- return { resource, relation };
896
- }
897
-
898
- /** Creates a relationship target from a subject. */
899
- export function authorizationSubjectTarget(
900
- subject: AuthorizationSubject,
901
- ): AuthorizationRelationshipTarget {
902
- return { kind: { case: "subject", value: subject } };
903
- }
904
-
905
- /** Creates a relationship target from a resource. */
906
- export function authorizationResourceTarget(
907
- resource: AuthorizationResource,
908
- ): AuthorizationRelationshipTarget {
909
- return { kind: { case: "resource", value: resource } };
910
- }
911
-
912
- /** Creates a relationship target from a subject set. */
913
- export function authorizationSubjectSetTarget(
914
- resource: AuthorizationResource,
915
- relation: string,
916
- ): AuthorizationRelationshipTarget {
917
- return {
918
- kind: {
919
- case: "subjectSet",
920
- value: authorizationSubjectSet(resource, relation),
503
+ async listActiveModelResourceTypes(request) {
504
+ try {
505
+ return listActiveModelResourceTypesResponseToProto(
506
+ await provider.listActiveModelResourceTypes(
507
+ listActiveModelResourceTypesRequestFromProto(request),
508
+ ),
509
+ );
510
+ } catch (error) {
511
+ throw authorizationRuntimeError("list active model resource types", error);
512
+ }
921
513
  },
922
514
  };
923
515
  }
924
516
 
925
- /** Creates an authorization action reference. */
926
- export function authorizationAction(
927
- name: string,
928
- properties?: JsonObjectInput,
929
- ): AuthorizationAction {
930
- return properties === undefined ? { name } : { name, properties };
931
- }
932
-
933
- /** Creates a relationship tuple for authorization writes. */
934
- export function authorizationRelationship(
935
- subject: AuthorizationSubject,
936
- relation: string,
937
- resource: AuthorizationResource,
938
- properties?: JsonObjectInput,
939
- ): AuthorizationRelationship {
940
- return properties === undefined
941
- ? { subject, relation, resource }
942
- : { subject, relation, resource, properties };
943
- }
944
-
945
- /** Creates a generalized relationship tuple for authorization writes. */
946
- export function authorizationRelationshipWithTarget(
947
- target: AuthorizationRelationshipTarget,
948
- relation: string,
949
- resource: AuthorizationResource,
950
- properties?: JsonObjectInput,
951
- ): AuthorizationRelationship {
952
- return properties === undefined
953
- ? { target, relation, resource }
954
- : { target, relation, resource, properties };
955
- }
956
-
957
- /** Creates a relationship key for authorization deletes. */
958
- export function authorizationRelationshipKey(
959
- subject: AuthorizationSubject,
960
- relation: string,
961
- resource: AuthorizationResource,
962
- ): AuthorizationRelationshipKey {
963
- return { subject, relation, resource };
964
- }
965
-
966
- /** Creates a generalized relationship key for authorization deletes. */
967
- export function authorizationRelationshipKeyWithTarget(
968
- target: AuthorizationRelationshipTarget,
969
- relation: string,
970
- resource: AuthorizationResource,
971
- ): AuthorizationRelationshipKey {
972
- return { target, relation, resource };
973
- }
974
-
975
- function authorizationEvaluateInputToProto(input: AuthorizationEvaluateInput) {
976
- return create(AccessEvaluationRequestSchema, {
977
- subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
978
- action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
979
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
980
- context: optionalStruct(input.context),
981
- });
982
- }
983
-
984
- function authorizationEvaluateInputFromProto(
985
- input: ProtoAccessEvaluationRequest,
986
- ): AuthorizationEvaluateInput {
517
+ function checkAccessRequestFromProto(
518
+ value: ProtoCheckAccessRequest,
519
+ ): CheckAccessRequest {
987
520
  return {
988
- subject: authorizationSubjectFromProto(input.subject),
989
- action: authorizationActionFromProto(input.action),
990
- resource: authorizationResourceFromProto(input.resource),
991
- context: optionalObjectFromStruct(input.context),
521
+ subject: subjectFromProto(value.subject),
522
+ action: value.action
523
+ ? {
524
+ name: value.action.name,
525
+ properties: jsonObjectFromStruct(value.action.properties),
526
+ }
527
+ : undefined,
528
+ resource: resourceFromProto(value.resource),
992
529
  };
993
530
  }
994
531
 
995
- function authorizationEvaluateManyInputToProto(input: AuthorizationEvaluateManyInput) {
996
- return create(AccessEvaluationsRequestSchema, {
997
- requests: input.requests?.map(authorizationEvaluateInputToProto) ?? [],
998
- });
999
- }
1000
-
1001
- function authorizationEvaluateManyInputFromProto(
1002
- input: ProtoAccessEvaluationsRequest,
1003
- ): AuthorizationEvaluateManyInput {
1004
- return { requests: input.requests.map(authorizationEvaluateInputFromProto) };
1005
- }
1006
-
1007
- function authorizationSearchResourcesInputToProto(input: AuthorizationSearchResourcesInput) {
1008
- return create(ResourceSearchRequestSchema, {
1009
- subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
1010
- action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
1011
- resourceType: input.resourceType ?? "",
1012
- context: optionalStruct(input.context),
1013
- pageSize: input.pageSize ?? 0,
1014
- pageToken: input.pageToken ?? "",
1015
- });
1016
- }
1017
-
1018
- function authorizationSearchResourcesInputFromProto(
1019
- input: ProtoResourceSearchRequest,
1020
- ): AuthorizationSearchResourcesInput {
1021
- return {
1022
- subject: authorizationSubjectFromProto(input.subject),
1023
- action: authorizationActionFromProto(input.action),
1024
- resourceType: input.resourceType,
1025
- context: optionalObjectFromStruct(input.context),
1026
- pageSize: input.pageSize,
1027
- pageToken: input.pageToken,
1028
- };
1029
- }
1030
-
1031
- function authorizationSearchSubjectsInputToProto(input: AuthorizationSearchSubjectsInput) {
1032
- return create(SubjectSearchRequestSchema, {
1033
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
1034
- action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
1035
- subjectType: input.subjectType ?? "",
1036
- context: optionalStruct(input.context),
1037
- pageSize: input.pageSize ?? 0,
1038
- pageToken: input.pageToken ?? "",
532
+ function checkAccessResponseToProto(value: CheckAccessResponse | undefined) {
533
+ if (!value) {
534
+ throw new ConnectError(
535
+ "authorization provider returned nil response",
536
+ Code.Internal,
537
+ );
538
+ }
539
+ return create(CheckAccessResponseSchema, {
540
+ allowed: value.allowed ?? false,
541
+ modelId: value.modelId ?? "",
1039
542
  });
1040
543
  }
1041
544
 
1042
- function authorizationSearchSubjectsInputFromProto(
1043
- input: ProtoSubjectSearchRequest,
1044
- ): AuthorizationSearchSubjectsInput {
545
+ function checkAccessManyRequestFromProto(
546
+ value: ProtoCheckAccessManyRequest,
547
+ ): CheckAccessManyRequest {
1045
548
  return {
1046
- resource: authorizationResourceFromProto(input.resource),
1047
- action: authorizationActionFromProto(input.action),
1048
- subjectType: input.subjectType,
1049
- context: optionalObjectFromStruct(input.context),
1050
- pageSize: input.pageSize,
1051
- pageToken: input.pageToken,
549
+ requests: value.requests.map(checkAccessRequestFromProto),
1052
550
  };
1053
551
  }
1054
552
 
1055
- function authorizationEffectiveSearchSubjectsInputToProto(
1056
- input: AuthorizationEffectiveSearchSubjectsInput,
553
+ function checkAccessManyResponseToProto(
554
+ value: CheckAccessManyResponse | undefined,
1057
555
  ) {
1058
- return create(EffectiveSubjectSearchRequestSchema, {
1059
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
1060
- action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
1061
- context: optionalStruct(input.context),
1062
- pageSize: input.pageSize ?? 0,
1063
- pageToken: input.pageToken ?? "",
1064
- });
1065
- }
1066
-
1067
- function authorizationEffectiveSearchSubjectsInputFromProto(
1068
- input: ProtoEffectiveSubjectSearchRequest,
1069
- ): AuthorizationEffectiveSearchSubjectsInput {
1070
- return {
1071
- resource: authorizationResourceFromProto(input.resource),
1072
- action: authorizationActionFromProto(input.action),
1073
- context: optionalObjectFromStruct(input.context),
1074
- pageSize: input.pageSize,
1075
- pageToken: input.pageToken,
1076
- };
1077
- }
1078
-
1079
- function authorizationSearchActionsInputToProto(input: AuthorizationSearchActionsInput) {
1080
- return create(ActionSearchRequestSchema, {
1081
- subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
1082
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
1083
- context: optionalStruct(input.context),
1084
- pageSize: input.pageSize ?? 0,
1085
- pageToken: input.pageToken ?? "",
1086
- });
1087
- }
1088
-
1089
- function authorizationSearchActionsInputFromProto(
1090
- input: ProtoActionSearchRequest,
1091
- ): AuthorizationSearchActionsInput {
1092
- return {
1093
- subject: authorizationSubjectFromProto(input.subject),
1094
- resource: authorizationResourceFromProto(input.resource),
1095
- context: optionalObjectFromStruct(input.context),
1096
- pageSize: input.pageSize,
1097
- pageToken: input.pageToken,
1098
- };
1099
- }
1100
-
1101
- function authorizationExpandInputToProto(input: AuthorizationExpandInput) {
1102
- return create(ExpandRequestSchema, {
1103
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
1104
- relation: input.relation ?? "",
1105
- context: optionalStruct(input.context),
1106
- maxDepth: input.maxDepth ?? 0,
1107
- modelId: input.modelId ?? "",
1108
- });
1109
- }
1110
-
1111
- function authorizationExpandInputFromProto(input: ProtoExpandRequest): AuthorizationExpandInput {
1112
- return {
1113
- resource: authorizationResourceFromProto(input.resource),
1114
- relation: input.relation,
1115
- context: optionalObjectFromStruct(input.context),
1116
- maxDepth: input.maxDepth,
1117
- modelId: input.modelId,
1118
- };
1119
- }
1120
-
1121
- function authorizationReadRelationshipsInputToProto(input: AuthorizationReadRelationshipsInput) {
1122
- return create(ReadRelationshipsRequestSchema, {
1123
- subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
1124
- relation: input.relation ?? "",
1125
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
1126
- pageSize: input.pageSize ?? 0,
1127
- pageToken: input.pageToken ?? "",
1128
- modelId: input.modelId ?? "",
1129
- target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
556
+ if (!value) {
557
+ throw new ConnectError(
558
+ "authorization provider returned nil response",
559
+ Code.Internal,
560
+ );
561
+ }
562
+ return create(CheckAccessManyResponseSchema, {
563
+ decisions: (value.decisions ?? []).map(checkAccessResponseToProto),
1130
564
  });
1131
565
  }
1132
566
 
1133
- function authorizationReadRelationshipsInputFromProto(
1134
- input: ProtoReadRelationshipsRequest,
1135
- ): AuthorizationReadRelationshipsInput {
567
+ function listRelationshipsRequestFromProto(
568
+ value: ProtoListRelationshipsRequest,
569
+ ): ListRelationshipsRequest {
1136
570
  return {
1137
- subject: authorizationSubjectFromProto(input.subject),
1138
- relation: input.relation,
1139
- resource: authorizationResourceFromProto(input.resource),
1140
- pageSize: input.pageSize,
1141
- pageToken: input.pageToken,
1142
- modelId: input.modelId,
1143
- target: authorizationRelationshipTargetFromProto(input.target),
571
+ filter: relationshipFilterFromProto(value.filter),
572
+ pageSize: value.pageSize,
573
+ pageToken: value.pageToken,
1144
574
  };
1145
575
  }
1146
576
 
1147
- function authorizationWriteRelationshipsInputToProto(input: AuthorizationWriteRelationshipsInput) {
1148
- return create(WriteRelationshipsRequestSchema, {
1149
- writes: input.writes?.map(authorizationRelationshipToProto) ?? [],
1150
- deletes: input.deletes?.map(authorizationRelationshipKeyToProto) ?? [],
1151
- modelId: input.modelId ?? "",
577
+ function listRelationshipsRequestToProto(
578
+ value: ListRelationshipsRequest,
579
+ ) {
580
+ return create(ListRelationshipsRequestSchema, {
581
+ filter: relationshipFilterToProto(value.filter),
582
+ pageSize: value.pageSize ?? 0,
583
+ pageToken: value.pageToken ?? "",
1152
584
  });
1153
585
  }
1154
586
 
1155
- function authorizationWriteRelationshipsInputFromProto(
1156
- input: ProtoWriteRelationshipsRequest,
1157
- ): AuthorizationWriteRelationshipsInput {
587
+ function listRelationshipsResponseFromProto(
588
+ value: ProtoListRelationshipsResponse,
589
+ ): ListRelationshipsResponse {
1158
590
  return {
1159
- writes: input.writes.map(authorizationRelationshipFromProto),
1160
- deletes: input.deletes.map(authorizationRelationshipKeyFromProto),
1161
- modelId: input.modelId,
591
+ relationships: value.relationships.map(relationshipFromProtoRequired),
592
+ nextPageToken: value.nextPageToken,
1162
593
  };
1163
594
  }
1164
595
 
1165
- function authorizationListModelsInputToProto(input: AuthorizationListModelsInput) {
1166
- return create(ListModelsRequestSchema, {
1167
- pageSize: input.pageSize ?? 0,
1168
- pageToken: input.pageToken ?? "",
596
+ function listRelationshipsResponseToProto(
597
+ value: ListRelationshipsResponse | undefined,
598
+ ) {
599
+ if (!value) {
600
+ throw new ConnectError(
601
+ "authorization provider returned nil response",
602
+ Code.Internal,
603
+ );
604
+ }
605
+ return create(ListRelationshipsResponseSchema, {
606
+ relationships: (value.relationships ?? []).map(relationshipToProtoRequired),
607
+ nextPageToken: value.nextPageToken ?? "",
1169
608
  });
1170
609
  }
1171
610
 
1172
- function authorizationListModelsInputFromProto(input: ProtoListModelsRequest): AuthorizationListModelsInput {
611
+ function addRelationshipRequestFromProto(
612
+ value: ProtoAddRelationshipRequest,
613
+ ): AddRelationshipRequest {
1173
614
  return {
1174
- pageSize: input.pageSize,
1175
- pageToken: input.pageToken,
615
+ relationship: relationshipFromProto(value.relationship),
1176
616
  };
1177
617
  }
1178
618
 
1179
- function authorizationWriteModelInputToProto(input: AuthorizationWriteModelInput) {
1180
- return create(WriteModelRequestSchema, {
1181
- model: input.model === undefined ? undefined : authorizationModelToProto(input.model),
619
+ function addRelationshipResponseToProto(
620
+ value: AddRelationshipResponse | undefined,
621
+ ) {
622
+ if (!value) {
623
+ throw new ConnectError(
624
+ "authorization provider returned nil response",
625
+ Code.Internal,
626
+ );
627
+ }
628
+ return create(AddRelationshipResponseSchema, {
629
+ relationship: value.relationship
630
+ ? relationshipToProto(value.relationship)
631
+ : undefined,
1182
632
  });
1183
633
  }
1184
634
 
1185
- function authorizationWriteModelInputFromProto(input: ProtoWriteModelRequest): AuthorizationWriteModelInput {
635
+ function deleteRelationshipRequestFromProto(
636
+ value: ProtoDeleteRelationshipRequest,
637
+ ): DeleteRelationshipRequest {
1186
638
  return {
1187
- model: authorizationModelFromProto(input.model),
639
+ relationshipTuple: relationshipTupleFromProto(value.relationshipTuple),
1188
640
  };
1189
641
  }
1190
642
 
1191
- function authorizationDecisionToProto(input: AuthorizationDecision) {
1192
- return create(AccessDecisionSchema, {
1193
- allowed: input.allowed ?? false,
1194
- context: optionalStruct(input.context),
1195
- modelId: input.modelId ?? "",
1196
- });
1197
- }
1198
-
1199
- function authorizationDecisionFromProto(input: ProtoAccessDecision): AuthorizationDecision {
643
+ function setAuthorizationStateRequestFromProto(
644
+ value: ProtoSetAuthorizationStateRequest,
645
+ ): SetAuthorizationStateRequest {
1200
646
  return {
1201
- allowed: input.allowed,
1202
- context: optionalObjectFromStruct(input.context),
1203
- modelId: input.modelId,
647
+ model: authorizationModelFromProto(value.model),
648
+ relationships: value.relationships.map(relationshipFromProtoRequired),
1204
649
  };
1205
650
  }
1206
651
 
1207
- function authorizationEvaluationsResponseToProto(input: AuthorizationEvaluationsResponse) {
1208
- return create(AccessEvaluationsResponseSchema, {
1209
- decisions: input.decisions?.map(authorizationDecisionToProto) ?? [],
1210
- });
1211
- }
1212
-
1213
- function authorizationEvaluationsResponseFromProto(
1214
- input: ProtoAccessEvaluationsResponse,
1215
- ): AuthorizationEvaluationsResponse {
1216
- return { decisions: input.decisions.map(authorizationDecisionFromProto) };
1217
- }
1218
-
1219
- function authorizationResourceSearchToProto(input: AuthorizationResourceSearch) {
1220
- return create(ResourceSearchResponseSchema, {
1221
- resources: input.resources?.map(authorizationResourceToProto) ?? [],
1222
- nextPageToken: input.nextPageToken ?? "",
1223
- modelId: input.modelId ?? "",
652
+ function setAuthorizationStateResponseToProto(
653
+ value: SetAuthorizationStateResponse | undefined,
654
+ ) {
655
+ if (!value) {
656
+ throw new ConnectError(
657
+ "authorization provider returned nil response",
658
+ Code.Internal,
659
+ );
660
+ }
661
+ return create(SetAuthorizationStateResponseSchema, {
662
+ activeModel: value.activeModel
663
+ ? authorizationModelRefToProto(value.activeModel)
664
+ : undefined,
1224
665
  });
1225
666
  }
1226
667
 
1227
- function authorizationResourceSearchFromProto(input: ProtoResourceSearchResponse): AuthorizationResourceSearch {
1228
- return {
1229
- resources: input.resources.map(authorizationResourceFromProtoRequired),
1230
- nextPageToken: input.nextPageToken,
1231
- modelId: input.modelId,
1232
- };
1233
- }
1234
-
1235
- function authorizationSubjectSearchToProto(input: AuthorizationSubjectSearch) {
1236
- return create(SubjectSearchResponseSchema, {
1237
- subjects: input.subjects?.map(authorizationSubjectToProto) ?? [],
1238
- nextPageToken: input.nextPageToken ?? "",
1239
- modelId: input.modelId ?? "",
668
+ function getActiveModelRefResponseToProto(
669
+ value: GetActiveModelRefResponse | undefined,
670
+ ) {
671
+ if (!value) {
672
+ throw new ConnectError(
673
+ "authorization provider returned nil response",
674
+ Code.Internal,
675
+ );
676
+ }
677
+ return create(GetActiveModelRefResponseSchema, {
678
+ model: value.model ? authorizationModelRefToProto(value.model) : undefined,
1240
679
  });
1241
680
  }
1242
681
 
1243
- function authorizationSubjectSearchFromProto(input: ProtoSubjectSearchResponse): AuthorizationSubjectSearch {
682
+ function setActiveModelRequestFromProto(
683
+ value: ProtoSetActiveModelRequest,
684
+ ): SetActiveModelRequest {
1244
685
  return {
1245
- subjects: input.subjects.map(authorizationSubjectFromProtoRequired),
1246
- nextPageToken: input.nextPageToken,
1247
- modelId: input.modelId,
686
+ model: authorizationModelFromProto(value.model),
1248
687
  };
1249
688
  }
1250
689
 
1251
- function authorizationEffectiveSubjectSearchToProto(input: AuthorizationEffectiveSubjectSearch) {
1252
- return create(EffectiveSubjectSearchResponseSchema, {
1253
- targets: input.targets?.map(authorizationRelationshipTargetToProto) ?? [],
1254
- nextPageToken: input.nextPageToken ?? "",
1255
- modelId: input.modelId ?? "",
1256
- truncated: input.truncated ?? false,
690
+ function setActiveModelResponseToProto(value: SetActiveModelResponse | undefined) {
691
+ if (!value) {
692
+ throw new ConnectError(
693
+ "authorization provider returned nil response",
694
+ Code.Internal,
695
+ );
696
+ }
697
+ return create(SetActiveModelResponseSchema, {
698
+ model: value.model ? authorizationModelRefToProto(value.model) : undefined,
1257
699
  });
1258
700
  }
1259
701
 
1260
- function authorizationEffectiveSubjectSearchFromProto(
1261
- input: ProtoEffectiveSubjectSearchResponse,
1262
- ): AuthorizationEffectiveSubjectSearch {
702
+ function listActiveModelResourceTypesRequestFromProto(
703
+ value: ProtoListActiveModelResourceTypesRequest,
704
+ ): ListActiveModelResourceTypesRequest {
1263
705
  return {
1264
- targets: input.targets.map(authorizationRelationshipTargetFromProtoRequired),
1265
- nextPageToken: input.nextPageToken,
1266
- modelId: input.modelId,
1267
- truncated: input.truncated,
706
+ filter: value.filter
707
+ ? {
708
+ name: value.filter.name,
709
+ sourceLayer: value.filter.sourceLayer,
710
+ }
711
+ : undefined,
712
+ pageSize: value.pageSize,
713
+ pageToken: value.pageToken,
1268
714
  };
1269
715
  }
1270
716
 
1271
- function authorizationActionSearchToProto(input: AuthorizationActionSearch) {
1272
- return create(ActionSearchResponseSchema, {
1273
- actions: input.actions?.map(authorizationActionToProto) ?? [],
1274
- nextPageToken: input.nextPageToken ?? "",
1275
- modelId: input.modelId ?? "",
717
+ function listActiveModelResourceTypesResponseToProto(
718
+ value: ListActiveModelResourceTypesResponse | undefined,
719
+ ) {
720
+ if (!value) {
721
+ throw new ConnectError(
722
+ "authorization provider returned nil response",
723
+ Code.Internal,
724
+ );
725
+ }
726
+ return create(ListActiveModelResourceTypesResponseSchema, {
727
+ resourceTypes: (value.resourceTypes ?? []).map(
728
+ authorizationModelResourceTypeToProto,
729
+ ),
730
+ nextPageToken: value.nextPageToken ?? "",
731
+ modelId: value.modelId ?? "",
1276
732
  });
1277
733
  }
1278
734
 
1279
- function authorizationActionSearchFromProto(input: ProtoActionSearchResponse): AuthorizationActionSearch {
735
+ function subjectFromProto(value: ProtoCheckAccessRequest["subject"]): AuthorizationSubject | undefined {
736
+ if (!value) {
737
+ return undefined;
738
+ }
1280
739
  return {
1281
- actions: input.actions.map(authorizationActionFromProtoRequired),
1282
- nextPageToken: input.nextPageToken,
1283
- modelId: input.modelId,
740
+ type: value.type,
741
+ id: value.id,
742
+ properties: jsonObjectFromStruct(value.properties),
1284
743
  };
1285
744
  }
1286
745
 
1287
- function authorizationMetadataToProto(input: AuthorizationMetadata) {
1288
- return create(AuthorizationMetadataSchema, {
1289
- capabilities: [...(input.capabilities ?? [])],
1290
- activeModelId: input.activeModelId ?? "",
746
+ function subjectToProto(value: AuthorizationSubject | undefined) {
747
+ if (!value) {
748
+ return undefined;
749
+ }
750
+ return create(SubjectSchema, {
751
+ type: value.type ?? "",
752
+ id: value.id ?? "",
753
+ properties: value.properties === undefined
754
+ ? undefined
755
+ : structFromObject(value.properties),
1291
756
  });
1292
757
  }
1293
758
 
1294
- function authorizationMetadataFromProto(input: ProtoAuthorizationMetadata): AuthorizationMetadata {
759
+ function resourceFromProto(value: ProtoRelationshipFilter["resource"]): AuthorizationResource | undefined {
760
+ if (!value) {
761
+ return undefined;
762
+ }
1295
763
  return {
1296
- capabilities: [...input.capabilities],
1297
- activeModelId: input.activeModelId,
764
+ type: value.type,
765
+ id: value.id,
766
+ properties: jsonObjectFromStruct(value.properties),
1298
767
  };
1299
768
  }
1300
769
 
1301
- function authorizationReadRelationshipsToProto(input: AuthorizationReadRelationships) {
1302
- return create(ReadRelationshipsResponseSchema, {
1303
- relationships: input.relationships?.map(authorizationRelationshipToProto) ?? [],
1304
- nextPageToken: input.nextPageToken ?? "",
1305
- modelId: input.modelId ?? "",
770
+ function resourceToProto(value: AuthorizationResource | undefined) {
771
+ if (!value) {
772
+ return undefined;
773
+ }
774
+ return create(ResourceSchema, {
775
+ type: value.type ?? "",
776
+ id: value.id ?? "",
777
+ properties: value.properties === undefined
778
+ ? undefined
779
+ : structFromObject(value.properties),
1306
780
  });
1307
781
  }
1308
782
 
1309
- function authorizationReadRelationshipsFromProto(
1310
- input: ProtoReadRelationshipsResponse,
1311
- ): AuthorizationReadRelationships {
783
+ function relationshipFilterFromProto(
784
+ value: ProtoRelationshipFilter | undefined,
785
+ ): RelationshipFilter | undefined {
786
+ if (!value) {
787
+ return undefined;
788
+ }
1312
789
  return {
1313
- relationships: input.relationships.map(authorizationRelationshipFromProto),
1314
- nextPageToken: input.nextPageToken,
1315
- modelId: input.modelId,
790
+ target: relationshipTargetFromProto(value.target),
791
+ relation: value.relation,
792
+ resource: resourceFromProto(value.resource),
793
+ targetType: value.targetType,
794
+ targetEntityType: value.targetEntityType,
795
+ resourceType: value.resourceType,
796
+ sourceLayer: value.sourceLayer,
1316
797
  };
1317
798
  }
1318
799
 
1319
- function authorizationGetActiveModelToProto(input: AuthorizationGetActiveModel) {
1320
- return create(GetActiveModelResponseSchema, {
1321
- model: input.model === undefined ? undefined : authorizationModelRefToProto(input.model),
1322
- });
1323
- }
1324
-
1325
- function authorizationGetActiveModelFromProto(input: ProtoGetActiveModelResponse): AuthorizationGetActiveModel {
800
+ function relationshipFilterToProto(value: RelationshipFilter | undefined) {
801
+ if (!value) {
802
+ return undefined;
803
+ }
1326
804
  return {
1327
- model: authorizationModelRefFromProto(input.model),
805
+ target: relationshipTargetToProto(value.target),
806
+ relation: value.relation ?? "",
807
+ resource: resourceToProto(value.resource),
808
+ targetType: value.targetType ?? RelationshipTargetType.UNSPECIFIED,
809
+ targetEntityType: value.targetEntityType ?? "",
810
+ resourceType: value.resourceType ?? "",
811
+ sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
1328
812
  };
1329
813
  }
1330
814
 
1331
- function authorizationListModelsToProto(input: AuthorizationListModels) {
1332
- return create(ListModelsResponseSchema, {
1333
- models: input.models?.map(authorizationModelRefToProto) ?? [],
1334
- nextPageToken: input.nextPageToken ?? "",
1335
- });
1336
- }
1337
-
1338
- function authorizationListModelsFromProto(input: ProtoListModelsResponse): AuthorizationListModels {
815
+ function relationshipFromProto(
816
+ value: ProtoRelationship | undefined,
817
+ ): Relationship | undefined {
818
+ if (!value) {
819
+ return undefined;
820
+ }
1339
821
  return {
1340
- models: input.models.map(authorizationModelRefFromProtoRequired),
1341
- nextPageToken: input.nextPageToken,
822
+ tuple: relationshipTupleFromProto(value.tuple),
823
+ properties: jsonObjectFromStruct(value.properties),
824
+ sourceLayer: value.sourceLayer,
1342
825
  };
1343
826
  }
1344
827
 
1345
- function authorizationSubjectToProto(input: AuthorizationSubject) {
1346
- return create(SubjectSchema, {
1347
- type: input.type,
1348
- id: input.id,
1349
- properties: optionalStruct(input.properties),
1350
- });
1351
- }
1352
-
1353
- function authorizationSubjectFromProto(input?: ProtoSubject | undefined): AuthorizationSubject | undefined {
1354
- return input === undefined ? undefined : authorizationSubjectFromProtoRequired(input);
1355
- }
1356
-
1357
- function authorizationSubjectFromProtoRequired(input: ProtoSubject): AuthorizationSubject {
1358
- return {
1359
- type: input.type,
1360
- id: input.id,
1361
- properties: optionalObjectFromStruct(input.properties),
1362
- };
828
+ function relationshipFromProtoRequired(value: ProtoRelationship): Relationship {
829
+ return relationshipFromProto(value)!;
1363
830
  }
1364
831
 
1365
- function authorizationResourceToProto(input: AuthorizationResource) {
1366
- return create(ResourceSchema, {
1367
- type: input.type,
1368
- id: input.id,
1369
- properties: optionalStruct(input.properties),
832
+ function relationshipToProto(value: Relationship | undefined) {
833
+ if (!value) {
834
+ return undefined;
835
+ }
836
+ return create(RelationshipSchema, {
837
+ tuple: relationshipTupleToProto(value.tuple),
838
+ properties: value.properties === undefined
839
+ ? undefined
840
+ : structFromObject(value.properties),
841
+ sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
1370
842
  });
1371
843
  }
1372
844
 
1373
- function authorizationResourceFromProto(input?: ProtoResource | undefined): AuthorizationResource | undefined {
1374
- return input === undefined ? undefined : authorizationResourceFromProtoRequired(input);
845
+ function relationshipToProtoRequired(value: Relationship) {
846
+ return relationshipToProto(value)!;
1375
847
  }
1376
848
 
1377
- function authorizationResourceFromProtoRequired(input: ProtoResource): AuthorizationResource {
849
+ function relationshipTupleFromProto(
850
+ value: ProtoRelationshipTuple | undefined,
851
+ ): RelationshipTuple | undefined {
852
+ if (!value) {
853
+ return undefined;
854
+ }
1378
855
  return {
1379
- type: input.type,
1380
- id: input.id,
1381
- properties: optionalObjectFromStruct(input.properties),
856
+ target: relationshipTargetFromProto(value.target),
857
+ relation: value.relation,
858
+ resource: resourceFromProto(value.resource),
1382
859
  };
1383
860
  }
1384
861
 
1385
- function authorizationSubjectSetToProto(input: AuthorizationSubjectSet) {
1386
- return create(SubjectSetSchema, {
1387
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
1388
- relation: input.relation,
862
+ function relationshipTupleToProto(value: RelationshipTuple | undefined) {
863
+ if (!value) {
864
+ return undefined;
865
+ }
866
+ return create(RelationshipTupleSchema, {
867
+ target: relationshipTargetToProto(value.target),
868
+ relation: value.relation ?? "",
869
+ resource: resourceToProto(value.resource),
1389
870
  });
1390
871
  }
1391
872
 
1392
- function authorizationSubjectSetFromProto(input?: ProtoSubjectSet | undefined): AuthorizationSubjectSet | undefined {
1393
- if (input === undefined) {
873
+ function relationshipTargetFromProto(
874
+ value: ProtoRelationshipTarget | undefined,
875
+ ): RelationshipTarget | undefined {
876
+ if (!value) {
1394
877
  return undefined;
1395
878
  }
1396
- return {
1397
- resource: authorizationResourceFromProto(input.resource),
1398
- relation: input.relation,
1399
- };
1400
- }
1401
-
1402
- function authorizationRelationshipTargetToProto(input: AuthorizationRelationshipTarget) {
1403
- switch (input.kind.case) {
879
+ switch (value.kind.case) {
1404
880
  case "subject":
1405
- return create(RelationshipTargetSchema, {
1406
- kind: { case: "subject", value: authorizationSubjectToProto(input.kind.value) },
1407
- });
881
+ return { subject: subjectFromProto(value.kind.value) };
1408
882
  case "resource":
1409
- return create(RelationshipTargetSchema, {
1410
- kind: { case: "resource", value: authorizationResourceToProto(input.kind.value) },
1411
- });
883
+ return { resource: resourceFromProto(value.kind.value) };
1412
884
  case "subjectSet":
1413
- return create(RelationshipTargetSchema, {
1414
- kind: { case: "subjectSet", value: authorizationSubjectSetToProto(input.kind.value) },
1415
- });
885
+ return { subjectSet: subjectSetFromProto(value.kind.value) };
1416
886
  default:
1417
- return create(RelationshipTargetSchema);
887
+ return {};
1418
888
  }
1419
889
  }
1420
890
 
1421
- function authorizationRelationshipTargetFromProto(
1422
- input?: ProtoRelationshipTarget | undefined,
1423
- ): AuthorizationRelationshipTarget | undefined {
1424
- return input === undefined ? undefined : authorizationRelationshipTargetFromProtoRequired(input);
1425
- }
1426
-
1427
- function authorizationRelationshipTargetFromProtoRequired(
1428
- input: ProtoRelationshipTarget,
1429
- ): AuthorizationRelationshipTarget {
1430
- switch (input.kind.case) {
1431
- case "subject":
1432
- return { kind: { case: "subject", value: authorizationSubjectFromProtoRequired(input.kind.value) } };
1433
- case "resource":
1434
- return { kind: { case: "resource", value: authorizationResourceFromProtoRequired(input.kind.value) } };
1435
- case "subjectSet":
1436
- return { kind: { case: "subjectSet", value: authorizationSubjectSetFromProto(input.kind.value)! } };
1437
- default:
1438
- return { kind: { case: undefined } };
891
+ function relationshipTargetToProto(value: RelationshipTarget | undefined) {
892
+ if (!value) {
893
+ return undefined;
1439
894
  }
895
+ if (value.subject) {
896
+ return create(RelationshipTargetSchema, {
897
+ kind: { case: "subject", value: subjectToProto(value.subject)! },
898
+ });
899
+ }
900
+ if (value.resource) {
901
+ return create(RelationshipTargetSchema, {
902
+ kind: { case: "resource", value: resourceToProto(value.resource)! },
903
+ });
904
+ }
905
+ if (value.subjectSet) {
906
+ return create(RelationshipTargetSchema, {
907
+ kind: { case: "subjectSet", value: subjectSetToProto(value.subjectSet) },
908
+ });
909
+ }
910
+ return create(RelationshipTargetSchema);
1440
911
  }
1441
912
 
1442
- function authorizationActionToProto(input: AuthorizationAction) {
1443
- return create(ActionSchema, {
1444
- name: input.name,
1445
- properties: optionalStruct(input.properties),
1446
- });
1447
- }
1448
-
1449
- function authorizationActionFromProto(input?: ProtoAction | undefined): AuthorizationAction | undefined {
1450
- return input === undefined ? undefined : authorizationActionFromProtoRequired(input);
1451
- }
1452
-
1453
- function authorizationActionFromProtoRequired(input: ProtoAction): AuthorizationAction {
1454
- return {
1455
- name: input.name,
1456
- properties: optionalObjectFromStruct(input.properties),
1457
- };
1458
- }
1459
-
1460
- function authorizationRelationshipToProto(input: AuthorizationRelationship) {
1461
- return create(RelationshipSchema, {
1462
- subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
1463
- relation: input.relation,
1464
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
1465
- properties: optionalStruct(input.properties),
1466
- target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
1467
- });
1468
- }
1469
-
1470
- function authorizationRelationshipFromProto(input: ProtoRelationship): AuthorizationRelationship {
913
+ function subjectSetFromProto(value: ProtoSubjectSet | undefined): SubjectSet | undefined {
914
+ if (!value) {
915
+ return undefined;
916
+ }
1471
917
  return {
1472
- subject: authorizationSubjectFromProto(input.subject),
1473
- relation: input.relation,
1474
- resource: authorizationResourceFromProto(input.resource),
1475
- properties: optionalObjectFromStruct(input.properties),
1476
- target: authorizationRelationshipTargetFromProto(input.target),
918
+ resource: resourceFromProto(value.resource),
919
+ relation: value.relation,
1477
920
  };
1478
921
  }
1479
922
 
1480
- function authorizationRelationshipKeyToProto(input: AuthorizationRelationshipKey) {
1481
- return create(RelationshipKeySchema, {
1482
- subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
1483
- relation: input.relation,
1484
- resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
1485
- target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
923
+ function subjectSetToProto(value: SubjectSet) {
924
+ return create(SubjectSetSchema, {
925
+ resource: resourceToProto(value.resource),
926
+ relation: value.relation ?? "",
1486
927
  });
1487
928
  }
1488
929
 
1489
- function authorizationRelationshipKeyFromProto(input: ProtoRelationshipKey): AuthorizationRelationshipKey {
1490
- return {
1491
- subject: authorizationSubjectFromProto(input.subject),
1492
- relation: input.relation,
1493
- resource: authorizationResourceFromProto(input.resource),
1494
- target: authorizationRelationshipTargetFromProto(input.target),
1495
- };
1496
- }
1497
-
1498
- function authorizationModelToProto(input: AuthorizationModel) {
1499
- return {
1500
- version: input.version ?? 0,
1501
- resourceTypes: input.resourceTypes?.map(authorizationModelResourceTypeToProto) ?? [],
1502
- };
1503
- }
1504
-
1505
- function authorizationModelFromProto(input?: ProtoAuthorizationModel | undefined): AuthorizationModel | undefined {
1506
- if (input === undefined) {
930
+ function authorizationModelFromProto(
931
+ value: ProtoAuthorizationModel | undefined,
932
+ ): AuthorizationModel | undefined {
933
+ if (!value) {
1507
934
  return undefined;
1508
935
  }
1509
936
  return {
1510
- version: input.version,
1511
- resourceTypes: input.resourceTypes.map(authorizationModelResourceTypeFromProto),
1512
- };
1513
- }
1514
-
1515
- function authorizationModelResourceTypeToProto(input: AuthorizationModelResourceType) {
1516
- return {
1517
- name: input.name,
1518
- relations: input.relations?.map(authorizationModelRelationToProto) ?? [],
1519
- actions: input.actions?.map(authorizationModelActionToProto) ?? [],
937
+ id: value.id,
938
+ version: value.version,
939
+ resourceTypes: value.resourceTypes.map(authorizationModelResourceTypeFromProto),
1520
940
  };
1521
941
  }
1522
942
 
1523
943
  function authorizationModelResourceTypeFromProto(
1524
- input: ProtoAuthorizationModelResourceType,
944
+ value: ProtoAuthorizationModelResourceType,
1525
945
  ): AuthorizationModelResourceType {
1526
946
  return {
1527
- name: input.name,
1528
- relations: input.relations.map(authorizationModelRelationFromProto),
1529
- actions: input.actions.map(authorizationModelActionFromProto),
1530
- };
1531
- }
1532
-
1533
- function authorizationModelRelationToProto(input: AuthorizationModelRelation) {
1534
- return {
1535
- name: input.name,
1536
- subjectTypes: [...(input.subjectTypes ?? [])],
1537
- allowedTargets: input.allowedTargets?.map(authorizationModelAllowedTargetToProto) ?? [],
1538
- rewrite: input.rewrite === undefined ? undefined : authorizationModelRewriteToProto(input.rewrite),
1539
- };
1540
- }
1541
-
1542
- function authorizationModelRelationFromProto(
1543
- input: ProtoAuthorizationModelRelation,
1544
- ): AuthorizationModelRelation {
1545
- return {
1546
- name: input.name,
1547
- subjectTypes: [...input.subjectTypes],
1548
- allowedTargets: input.allowedTargets.map(authorizationModelAllowedTargetFromProto),
1549
- rewrite: authorizationModelRewriteFromProto(input.rewrite),
947
+ name: value.name,
948
+ relations: value.relations.map((relation) => ({
949
+ name: relation.name,
950
+ allowedTargets: relation.allowedTargets.map(modelAllowedTargetFromProto),
951
+ })),
952
+ actions: value.actions.map((action) => ({
953
+ name: action.name,
954
+ relations: [...action.relations],
955
+ })),
956
+ sourceLayer: value.sourceLayer,
957
+ defaultAccessPolicy: value.defaultAccessPolicy,
1550
958
  };
1551
959
  }
1552
960
 
1553
- function authorizationModelActionToProto(input: AuthorizationModelAction) {
1554
- return {
1555
- name: input.name,
1556
- relations: [...(input.relations ?? [])],
1557
- rewrite: input.rewrite === undefined ? undefined : authorizationModelRewriteToProto(input.rewrite),
1558
- };
1559
- }
1560
-
1561
- function authorizationModelActionFromProto(input: ProtoAuthorizationModelAction): AuthorizationModelAction {
1562
- return {
1563
- name: input.name,
1564
- relations: [...input.relations],
1565
- rewrite: authorizationModelRewriteFromProto(input.rewrite),
1566
- };
1567
- }
1568
-
1569
- function authorizationModelAllowedTargetToProto(input: AuthorizationModelAllowedTarget) {
1570
- switch (input.kind.case) {
1571
- case "subjectType":
1572
- return { kind: { case: "subjectType" as const, value: input.kind.value } };
1573
- case "resourceType":
1574
- return { kind: { case: "resourceType" as const, value: input.kind.value } };
1575
- case "subjectSet":
1576
- return {
1577
- kind: {
1578
- case: "subjectSet" as const,
1579
- value: {
1580
- resourceType: input.kind.value.resourceType,
1581
- relation: input.kind.value.relation,
1582
- },
1583
- },
1584
- };
1585
- default:
1586
- return { kind: { case: undefined } };
1587
- }
961
+ function authorizationModelResourceTypeToProto(
962
+ value: AuthorizationModelResourceType,
963
+ ) {
964
+ return create(AuthorizationModelResourceTypeSchema, {
965
+ name: value.name ?? "",
966
+ relations: (value.relations ?? []).map((relation) =>
967
+ create(ModelRelationSchema, {
968
+ name: relation.name ?? "",
969
+ allowedTargets: (relation.allowedTargets ?? []).map(
970
+ modelAllowedTargetToProto,
971
+ ),
972
+ })
973
+ ),
974
+ actions: (value.actions ?? []).map((action) =>
975
+ create(ModelActionSchema, {
976
+ name: action.name ?? "",
977
+ relations: [...(action.relations ?? [])],
978
+ })
979
+ ),
980
+ sourceLayer: value.sourceLayer ?? SourceLayer.UNSPECIFIED,
981
+ defaultAccessPolicy: value.defaultAccessPolicy ?? DefaultAccessPolicy.DENY,
982
+ });
1588
983
  }
1589
984
 
1590
- function authorizationModelAllowedTargetFromProto(
1591
- input: ProtoAuthorizationModelAllowedTarget,
1592
- ): AuthorizationModelAllowedTarget {
1593
- switch (input.kind.case) {
985
+ function modelAllowedTargetFromProto(
986
+ value: ProtoModelAllowedTarget,
987
+ ): ModelAllowedTarget {
988
+ switch (value.kind.case) {
1594
989
  case "subjectType":
1595
- return { kind: { case: "subjectType", value: input.kind.value } };
990
+ return { subjectType: value.kind.value };
1596
991
  case "resourceType":
1597
- return { kind: { case: "resourceType", value: input.kind.value } };
1598
- case "subjectSet":
992
+ return { resourceType: value.kind.value };
993
+ case "subjectSetType":
1599
994
  return {
1600
- kind: {
1601
- case: "subjectSet",
1602
- value: authorizationModelSubjectSetTargetFromProto(input.kind.value),
995
+ subjectSetType: {
996
+ resourceType: value.kind.value.resourceType,
997
+ relation: value.kind.value.relation,
1603
998
  },
1604
999
  };
1605
1000
  default:
1606
- return { kind: { case: undefined } };
1001
+ return {};
1607
1002
  }
1608
1003
  }
1609
1004
 
1610
- function authorizationModelSubjectSetTargetFromProto(
1611
- input: ProtoAuthorizationModelSubjectSetTarget,
1612
- ): AuthorizationModelSubjectSetTarget {
1613
- return {
1614
- resourceType: input.resourceType,
1615
- relation: input.relation,
1616
- };
1617
- }
1618
-
1619
- function authorizationModelRewriteToProto(input: AuthorizationModelRewrite): ProtoAuthorizationModelRewrite {
1620
- switch (input.kind.case) {
1621
- case "this":
1622
- return { kind: { case: "this", value: {} } } as ProtoAuthorizationModelRewrite;
1623
- case "computedUserset":
1624
- return {
1625
- kind: {
1626
- case: "computedUserset",
1627
- value: { relation: input.kind.value.relation },
1628
- },
1629
- } as ProtoAuthorizationModelRewrite;
1630
- case "tupleToUserset":
1631
- return {
1632
- kind: {
1633
- case: "tupleToUserset",
1634
- value: {
1635
- tuplesetRelation: input.kind.value.tuplesetRelation,
1636
- computedRelation: input.kind.value.computedRelation,
1637
- },
1638
- },
1639
- } as ProtoAuthorizationModelRewrite;
1640
- case "union":
1641
- return {
1642
- kind: {
1643
- case: "union",
1644
- value: {
1645
- children: input.kind.value.children?.map(authorizationModelRewriteToProto) ?? [],
1646
- },
1647
- },
1648
- } as ProtoAuthorizationModelRewrite;
1649
- default:
1650
- return { kind: { case: undefined } } as ProtoAuthorizationModelRewrite;
1005
+ function modelAllowedTargetToProto(value: ModelAllowedTarget) {
1006
+ if (value.subjectType !== undefined) {
1007
+ return create(ModelAllowedTargetSchema, {
1008
+ kind: { case: "subjectType", value: value.subjectType },
1009
+ });
1651
1010
  }
1652
- }
1653
-
1654
- function authorizationModelRewriteFromProto(
1655
- input?: ProtoAuthorizationModelRewrite | undefined,
1656
- ): AuthorizationModelRewrite | undefined {
1657
- if (input === undefined) {
1658
- return undefined;
1011
+ if (value.resourceType !== undefined) {
1012
+ return create(ModelAllowedTargetSchema, {
1013
+ kind: { case: "resourceType", value: value.resourceType },
1014
+ });
1659
1015
  }
1660
- switch (input.kind.case) {
1661
- case "this":
1662
- return { kind: { case: "this", value: {} } };
1663
- case "computedUserset":
1664
- return { kind: { case: "computedUserset", value: authorizationComputedUsersetFromProto(input.kind.value) } };
1665
- case "tupleToUserset":
1666
- return { kind: { case: "tupleToUserset", value: authorizationTupleToUsersetFromProto(input.kind.value) } };
1667
- case "union":
1668
- return { kind: { case: "union", value: authorizationRewriteUnionFromProto(input.kind.value) } };
1669
- default:
1670
- return { kind: { case: undefined } };
1016
+ if (value.subjectSetType !== undefined) {
1017
+ return create(ModelAllowedTargetSchema, {
1018
+ kind: {
1019
+ case: "subjectSetType",
1020
+ value: create(SubjectSetTypeSchema, {
1021
+ resourceType: value.subjectSetType.resourceType ?? "",
1022
+ relation: value.subjectSetType.relation ?? "",
1023
+ }),
1024
+ },
1025
+ });
1671
1026
  }
1027
+ return create(ModelAllowedTargetSchema);
1672
1028
  }
1673
1029
 
1674
- function authorizationComputedUsersetFromProto(
1675
- input: ProtoAuthorizationModelComputedUserset,
1676
- ): AuthorizationModelComputedUserset {
1677
- return { relation: input.relation };
1678
- }
1679
-
1680
- function authorizationTupleToUsersetFromProto(
1681
- input: ProtoAuthorizationModelTupleToUserset,
1682
- ): AuthorizationModelTupleToUserset {
1683
- return {
1684
- tuplesetRelation: input.tuplesetRelation,
1685
- computedRelation: input.computedRelation,
1686
- };
1687
- }
1688
-
1689
- function authorizationRewriteUnionFromProto(
1690
- input: ProtoAuthorizationModelRewriteUnion,
1691
- ): AuthorizationModelRewriteUnion {
1692
- return { children: input.children.map((child) => authorizationModelRewriteFromProto(child)!) };
1693
- }
1694
-
1695
- function authorizationModelRefToProto(input: AuthorizationModelRef) {
1030
+ function authorizationModelRefToProto(value: AuthorizationModelRef) {
1696
1031
  return create(AuthorizationModelRefSchema, {
1697
- id: input.id,
1698
- version: input.version,
1699
- createdAt: input.createdAt === undefined ? undefined : timestampFromDate(input.createdAt),
1700
- });
1701
- }
1702
-
1703
- function authorizationModelRefFromProto(input?: ProtoAuthorizationModelRef | undefined): AuthorizationModelRef | undefined {
1704
- return input === undefined ? undefined : authorizationModelRefFromProtoRequired(input);
1705
- }
1706
-
1707
- function authorizationModelRefFromProtoRequired(input: ProtoAuthorizationModelRef): AuthorizationModelRef {
1708
- return {
1709
- id: input.id,
1710
- version: input.version,
1711
- createdAt: input.createdAt === undefined ? undefined : dateFromTimestamp(input.createdAt),
1712
- };
1713
- }
1714
-
1715
- function authorizationExpandToProto(input: AuthorizationExpand) {
1716
- return create(ExpandResponseSchema, {
1717
- root: input.root === undefined ? undefined : authorizationExpandNodeToProto(input.root),
1718
- truncated: input.truncated ?? false,
1719
- cycleDetected: input.cycleDetected ?? false,
1720
- maxDepthReached: input.maxDepthReached ?? false,
1721
- modelId: input.modelId ?? "",
1032
+ id: value.id ?? "",
1033
+ version: value.version ?? "",
1034
+ createdAt: value.createdAt ? timestampFromDate(value.createdAt) : undefined,
1722
1035
  });
1723
1036
  }
1724
1037
 
1725
- function authorizationExpandFromProto(input: ProtoExpandResponse): AuthorizationExpand {
1726
- return {
1727
- root: authorizationExpandNodeFromProto(input.root),
1728
- truncated: input.truncated,
1729
- cycleDetected: input.cycleDetected,
1730
- maxDepthReached: input.maxDepthReached,
1731
- modelId: input.modelId,
1732
- };
1733
- }
1734
-
1735
- function authorizationExpandNodeToProto(input: AuthorizationExpandNode): ProtoExpandNode {
1736
- return create(ExpandNodeSchema, {
1737
- target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
1738
- relation: input.relation ?? "",
1739
- children: input.children?.map(authorizationExpandNodeToProto) ?? [],
1740
- });
1741
- }
1742
-
1743
- function authorizationExpandNodeFromProto(input?: ProtoExpandNode | undefined): AuthorizationExpandNode | undefined {
1744
- if (input === undefined) {
1745
- return undefined;
1746
- }
1747
- return {
1748
- target: authorizationRelationshipTargetFromProto(input.target),
1749
- relation: input.relation,
1750
- children: input.children.map((child) => authorizationExpandNodeFromProto(child)!),
1751
- };
1752
- }
1753
-
1754
- function resolveAuthorizationSocketTarget(
1755
- socketPath = process.env[ENV_HOST_SERVICE_SOCKET],
1756
- ): string {
1757
- const trimmed = socketPath?.trim() ?? "";
1758
- if (!trimmed) {
1759
- throw new Error(`authorization: ${ENV_HOST_SERVICE_SOCKET} is not set`);
1760
- }
1761
- return trimmed;
1762
- }
1763
-
1764
- function pushCapability(capabilities: string[], capability: string): void {
1765
- if (!capabilities.includes(capability)) {
1766
- capabilities.push(capability);
1038
+ function authorizationRuntimeError(label: string, error: unknown): ConnectError {
1039
+ if (error instanceof ConnectError) {
1040
+ return error;
1767
1041
  }
1042
+ return new ConnectError(`${label}: ${errorMessage(error)}`, Code.Unknown);
1768
1043
  }