@stigmer/sdk 3.11.0 → 3.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,381 +0,0 @@
1
- // Code generated by stigmer-codegen. DO NOT EDIT.
2
-
3
- import { wrapError } from "./errors.js";
4
- import { stripUndefined } from "./proto-utils.js";
5
- import { type DeleteResourceInput, type ListParams, type ListResult, type ResourceRef } from "./types.js";
6
- import { create, fromJson, type JsonValue } from "@bufbuild/protobuf";
7
- import { ValueSchema } from "@bufbuild/protobuf/wkt";
8
- import { createClient, type Client, type Transport } from "@connectrpc/connect";
9
- import { DatastoreSchema, type Datastore } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/api_pb";
10
- import { DatastoreCommandController } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/command_pb";
11
- import { DatastoreQueryController } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/query_pb";
12
- import { DatastoreRecordCommandController } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/record_command_pb";
13
- import { InsertRecordRequestSchema, RecordEnvelopeSchema, UpdateRecordRequestSchema, DeleteRecordRequestSchema, FindRecordsRequestSchema, RecordListSchema, DescribeDatastoreRequestSchema, DatastoreDescriptionSchema, type InsertRecordRequest, type RecordEnvelope, type UpdateRecordRequest, type DeleteRecordRequest, type FindRecordsRequest, type RecordList, type DescribeDatastoreRequest, type DatastoreDescription } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/record_io_pb";
14
- import { DatastoreRecordQueryController } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/record_query_pb";
15
- import { DatastoreSpecSchema, FieldType, DatastoreVerb, DatastoreGrantScope, DatastoreRoleSchema, ChannelSenderSubjectSchema, DatastoreSubjectSchema, DatastoreRoleBindingSchema, DatastoreAuthorizationSchema, FieldDeclarationSchema, UniqueWhereSchema, UniqueConstraintSchema, CheckConstraintSchema, ExistsConstraintSchema, DatastoreGrantSchema, CollectionDeclarationSchema } from "@stigmer/protos/ai/stigmer/agentic/datastore/v1/spec_pb";
16
- import { ApiResourceKind } from "@stigmer/protos/ai/stigmer/commons/apiresource/apiresourcekind/api_resource_kind_pb";
17
- import { ApiResourceVisibility } from "@stigmer/protos/ai/stigmer/commons/apiresource/enum_pb";
18
- import { ApiResourceIdSchema, ApiResourceReferenceSchema, ApiResourceDeleteInputSchema, type UpdateVisibilityInput } from "@stigmer/protos/ai/stigmer/commons/apiresource/io_pb";
19
- import { ApiResourceMetadataSchema } from "@stigmer/protos/ai/stigmer/commons/apiresource/metadata_pb";
20
- import { PageInfoSchema } from "@stigmer/protos/ai/stigmer/commons/rpc/pagination_pb";
21
- import { ApiResourceRefSchema } from "@stigmer/protos/ai/stigmer/iam/iampolicy/v1/spec_pb";
22
- import { SearchRequestSchema } from "@stigmer/protos/ai/stigmer/search/v1/io_pb";
23
- import { SearchService } from "@stigmer/protos/ai/stigmer/search/v1/query_pb";
24
-
25
- /** Provides operations on datastore resources. */
26
- export class DatastoreClient {
27
- private readonly command: Client<typeof DatastoreCommandController>;
28
- private readonly query: Client<typeof DatastoreQueryController>;
29
- private readonly datastoreRecordCommand: Client<typeof DatastoreRecordCommandController>;
30
- private readonly datastoreRecordQuery: Client<typeof DatastoreRecordQueryController>;
31
- private readonly search: Client<typeof SearchService>;
32
-
33
- constructor(transport: Transport) {
34
- this.command = createClient(DatastoreCommandController, transport);
35
- this.query = createClient(DatastoreQueryController, transport);
36
- this.datastoreRecordCommand = createClient(DatastoreRecordCommandController, transport);
37
- this.datastoreRecordQuery = createClient(DatastoreRecordQueryController, transport);
38
- this.search = createClient(SearchService, transport);
39
- }
40
-
41
- async apply(input: DatastoreInput): Promise<Datastore> {
42
- try {
43
- return await this.command.apply(buildDatastoreProto(input));
44
- } catch (e) { throw wrapError(e); }
45
- }
46
-
47
- async create(input: DatastoreInput): Promise<Datastore> {
48
- try {
49
- return await this.command.create(buildDatastoreProto(input));
50
- } catch (e) { throw wrapError(e); }
51
- }
52
-
53
- async update(input: DatastoreInput): Promise<Datastore> {
54
- try {
55
- return await this.command.update(buildDatastoreProto(input));
56
- } catch (e) { throw wrapError(e); }
57
- }
58
-
59
- async updateVisibility(input: UpdateVisibilityInput): Promise<Datastore> {
60
- try {
61
- return await this.command.updateVisibility(input);
62
- } catch (e) { throw wrapError(e); }
63
- }
64
-
65
- async delete(input: DeleteResourceInput): Promise<Datastore> {
66
- try {
67
- return await this.command.delete(create(ApiResourceDeleteInputSchema, {
68
- resourceId: input.resourceId,
69
- versionMessage: input.versionMessage,
70
- force: input.force,
71
- }));
72
- } catch (e) { throw wrapError(e); }
73
- }
74
-
75
- async get(id: string): Promise<Datastore> {
76
- try {
77
- return await this.query.get(create(ApiResourceIdSchema, { value: id }));
78
- } catch (e) { throw wrapError(e); }
79
- }
80
-
81
- async getByReference(ref: ResourceRef): Promise<Datastore> {
82
- try {
83
- return await this.query.getByReference(create(ApiResourceReferenceSchema, { ...ref, kind: ApiResourceKind.datastore }));
84
- } catch (e) { throw wrapError(e); }
85
- }
86
-
87
- async insertRecord(input: InsertRecordRequest): Promise<RecordEnvelope> {
88
- try {
89
- return await this.datastoreRecordCommand.insertRecord(input);
90
- } catch (e) { throw wrapError(e); }
91
- }
92
-
93
- async updateRecord(input: UpdateRecordRequest): Promise<RecordEnvelope> {
94
- try {
95
- return await this.datastoreRecordCommand.updateRecord(input);
96
- } catch (e) { throw wrapError(e); }
97
- }
98
-
99
- async deleteRecord(input: DeleteRecordRequest): Promise<RecordEnvelope> {
100
- try {
101
- return await this.datastoreRecordCommand.deleteRecord(input);
102
- } catch (e) { throw wrapError(e); }
103
- }
104
-
105
- async findRecords(input: FindRecordsRequest): Promise<RecordList> {
106
- try {
107
- return await this.datastoreRecordQuery.findRecords(input);
108
- } catch (e) { throw wrapError(e); }
109
- }
110
-
111
- async describeDatastore(input: DescribeDatastoreRequest): Promise<DatastoreDescription> {
112
- try {
113
- return await this.datastoreRecordQuery.describeDatastore(input);
114
- } catch (e) { throw wrapError(e); }
115
- }
116
-
117
- async list(params: ListParams): Promise<ListResult> {
118
- try {
119
- const resp = await this.search.search(create(SearchRequestSchema, {
120
- kinds: [ApiResourceKind.datastore],
121
- query: params.query,
122
- org: params.org,
123
- excludePublic: params.excludePublic ?? false,
124
- crossOrgPublic: params.crossOrgPublic ?? false,
125
- page: params.page ? create(PageInfoSchema, params.page) : undefined,
126
- }));
127
- return {
128
- entries: resp.entries,
129
- totalCount: resp.totalCount,
130
- totalPages: resp.totalPages,
131
- };
132
- } catch (e) { throw wrapError(e); }
133
- }
134
- }
135
-
136
- /** Input for creating/updating a Datastore. */
137
- export interface DatastoreInput {
138
- name: string;
139
- slug?: string;
140
- org: string;
141
- labels?: Record<string, string>;
142
- visibility?: ApiResourceVisibility;
143
- description?: string;
144
- timezone?: string;
145
- authorization?: DatastoreAuthorizationInput;
146
- collections?: CollectionDeclarationInput[];
147
- }
148
-
149
- /** SDK input type for DatastoreAuthorization. */
150
- export interface DatastoreAuthorizationInput {
151
- roles?: DatastoreRoleInput[];
152
- bindings?: DatastoreRoleBindingInput[];
153
- defaultRole?: string;
154
- }
155
-
156
- /** SDK input type for DatastoreRole. */
157
- export interface DatastoreRoleInput {
158
- name: string;
159
- }
160
-
161
- /** SDK input type for DatastoreRoleBinding. */
162
- export interface DatastoreRoleBindingInput {
163
- subject: DatastoreSubjectInput;
164
- role: string;
165
- }
166
-
167
- /** SDK input type for DatastoreSubject. */
168
- export interface DatastoreSubjectInput {
169
- channelSender?: ChannelSenderSubjectInput;
170
- principal?: ApiResourceRefInput;
171
- }
172
-
173
- /** SDK input type for ChannelSenderSubject. */
174
- export interface ChannelSenderSubjectInput {
175
- senderKind: string;
176
- value: string;
177
- }
178
-
179
- /** SDK input type for ApiResourceRef. */
180
- export interface ApiResourceRefInput {
181
- kind: string;
182
- id: string;
183
- relation?: string;
184
- }
185
-
186
- /** SDK input type for CollectionDeclaration. */
187
- export interface CollectionDeclarationInput {
188
- name: string;
189
- description?: string;
190
- fields?: FieldDeclarationInput[];
191
- uniques?: UniqueConstraintInput[];
192
- checks?: CheckConstraintInput[];
193
- exists?: ExistsConstraintInput[];
194
- notExists?: ExistsConstraintInput[];
195
- grants?: DatastoreGrantInput[];
196
- }
197
-
198
- /** SDK input type for FieldDeclaration. */
199
- export interface FieldDeclarationInput {
200
- name: string;
201
- type: FieldType;
202
- required?: boolean;
203
- default?: JsonValue;
204
- enumValues?: string[];
205
- description?: string;
206
- }
207
-
208
- /** SDK input type for UniqueConstraint. */
209
- export interface UniqueConstraintInput {
210
- name: string;
211
- fields?: string[];
212
- where?: UniqueWhereInput;
213
- message: string;
214
- }
215
-
216
- /** SDK input type for UniqueWhere. */
217
- export interface UniqueWhereInput {
218
- field: string;
219
- equals: JsonValue;
220
- }
221
-
222
- /** SDK input type for CheckConstraint. */
223
- export interface CheckConstraintInput {
224
- name: string;
225
- expression: string;
226
- when?: string;
227
- message: string;
228
- }
229
-
230
- /** SDK input type for ExistsConstraint. */
231
- export interface ExistsConstraintInput {
232
- name: string;
233
- collection: string;
234
- where: string;
235
- when?: string;
236
- message: string;
237
- }
238
-
239
- /** SDK input type for DatastoreGrant. */
240
- export interface DatastoreGrantInput {
241
- role: string;
242
- verbs?: DatastoreVerb[];
243
- scope?: DatastoreGrantScope;
244
- readFields?: string[];
245
- }
246
-
247
- function buildDatastoreRoleProto(input: DatastoreRoleInput) {
248
- return Object.assign(create(DatastoreRoleSchema), stripUndefined({
249
- name: input.name,
250
- }));
251
- }
252
-
253
- function buildChannelSenderSubjectProto(input: ChannelSenderSubjectInput) {
254
- return Object.assign(create(ChannelSenderSubjectSchema), stripUndefined({
255
- senderKind: input.senderKind,
256
- value: input.value,
257
- }));
258
- }
259
-
260
- function buildApiResourceRefProto(input: ApiResourceRefInput) {
261
- return Object.assign(create(ApiResourceRefSchema), stripUndefined({
262
- kind: input.kind,
263
- id: input.id,
264
- relation: input.relation,
265
- }));
266
- }
267
-
268
- function buildDatastoreSubjectProto(input: DatastoreSubjectInput) {
269
- const msg = create(DatastoreSubjectSchema);
270
- if (input.channelSender) {
271
- msg.kind = { case: "channelSender", value: buildChannelSenderSubjectProto(input.channelSender) };
272
- } else if (input.principal) {
273
- msg.kind = { case: "principal", value: buildApiResourceRefProto(input.principal) };
274
- }
275
- return msg;
276
- }
277
-
278
- function buildDatastoreRoleBindingProto(input: DatastoreRoleBindingInput) {
279
- const msg = create(DatastoreRoleBindingSchema);
280
- if (input.subject) msg.subject = buildDatastoreSubjectProto(input.subject);
281
- if (input.role !== undefined) msg.role = input.role;
282
- return msg;
283
- }
284
-
285
- function buildDatastoreAuthorizationProto(input: DatastoreAuthorizationInput) {
286
- const msg = create(DatastoreAuthorizationSchema);
287
- if (input.roles) msg.roles = input.roles.map(buildDatastoreRoleProto);
288
- if (input.bindings) msg.bindings = input.bindings.map(buildDatastoreRoleBindingProto);
289
- if (input.defaultRole !== undefined) msg.defaultRole = input.defaultRole;
290
- return msg;
291
- }
292
-
293
- function buildFieldDeclarationProto(input: FieldDeclarationInput) {
294
- const msg = create(FieldDeclarationSchema);
295
- if (input.name !== undefined) msg.name = input.name;
296
- if (input.type !== undefined) msg.type = input.type;
297
- if (input.required !== undefined) msg.required = input.required;
298
- if (input.default !== undefined) msg.default = fromJson(ValueSchema, input.default);
299
- if (input.enumValues) msg.enumValues = input.enumValues;
300
- if (input.description !== undefined) msg.description = input.description;
301
- return msg;
302
- }
303
-
304
- function buildUniqueWhereProto(input: UniqueWhereInput) {
305
- const msg = create(UniqueWhereSchema);
306
- if (input.field !== undefined) msg.field = input.field;
307
- if (input.equals !== undefined) msg.equals = fromJson(ValueSchema, input.equals);
308
- return msg;
309
- }
310
-
311
- function buildUniqueConstraintProto(input: UniqueConstraintInput) {
312
- const msg = create(UniqueConstraintSchema);
313
- if (input.name !== undefined) msg.name = input.name;
314
- if (input.fields) msg.fields = input.fields;
315
- if (input.where) msg.where = buildUniqueWhereProto(input.where);
316
- if (input.message !== undefined) msg.message = input.message;
317
- return msg;
318
- }
319
-
320
- function buildCheckConstraintProto(input: CheckConstraintInput) {
321
- return Object.assign(create(CheckConstraintSchema), stripUndefined({
322
- name: input.name,
323
- expression: input.expression,
324
- when: input.when,
325
- message: input.message,
326
- }));
327
- }
328
-
329
- function buildExistsConstraintProto(input: ExistsConstraintInput) {
330
- return Object.assign(create(ExistsConstraintSchema), stripUndefined({
331
- name: input.name,
332
- collection: input.collection,
333
- where: input.where,
334
- when: input.when,
335
- message: input.message,
336
- }));
337
- }
338
-
339
- function buildDatastoreGrantProto(input: DatastoreGrantInput) {
340
- return Object.assign(create(DatastoreGrantSchema), stripUndefined({
341
- role: input.role,
342
- verbs: input.verbs,
343
- scope: input.scope,
344
- readFields: input.readFields,
345
- }));
346
- }
347
-
348
- function buildCollectionDeclarationProto(input: CollectionDeclarationInput) {
349
- const msg = create(CollectionDeclarationSchema);
350
- if (input.name !== undefined) msg.name = input.name;
351
- if (input.description !== undefined) msg.description = input.description;
352
- if (input.fields) msg.fields = input.fields.map(buildFieldDeclarationProto);
353
- if (input.uniques) msg.uniques = input.uniques.map(buildUniqueConstraintProto);
354
- if (input.checks) msg.checks = input.checks.map(buildCheckConstraintProto);
355
- if (input.exists) msg.exists = input.exists.map(buildExistsConstraintProto);
356
- if (input.notExists) msg.notExists = input.notExists.map(buildExistsConstraintProto);
357
- if (input.grants) msg.grants = input.grants.map(buildDatastoreGrantProto);
358
- return msg;
359
- }
360
-
361
- export function buildDatastoreProto(input: DatastoreInput): Datastore {
362
- const authorization = input.authorization ? buildDatastoreAuthorizationProto(input.authorization) : undefined;
363
- const collections = input.collections?.map(buildCollectionDeclarationProto);
364
- return Object.assign(create(DatastoreSchema), {
365
- apiVersion: "agentic.stigmer.ai/v1",
366
- kind: "Datastore",
367
- metadata: Object.assign(create(ApiResourceMetadataSchema), {
368
- name: input.name,
369
- org: input.org,
370
- ...(input.slug && { slug: input.slug }),
371
- ...(input.labels && { labels: input.labels }),
372
- ...(input.visibility && { visibility: input.visibility }),
373
- }),
374
- spec: Object.assign(create(DatastoreSpecSchema), stripUndefined({
375
- description: input.description,
376
- timezone: input.timezone,
377
- authorization,
378
- collections,
379
- })),
380
- }) as Datastore;
381
- }