@maravilla-labs/types 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.ts +248 -0
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -83,6 +83,87 @@ export interface KvStore {
83
83
 
84
84
  // Database Types
85
85
 
86
+ /** MongoDB-style key direction: `1` ascending, `-1` descending. */
87
+ export type IndexDirection = 1 | -1;
88
+
89
+ /** Whether an index is a regular document index or a vector index. */
90
+ export type IndexKind = 'document' | 'vector';
91
+
92
+ export interface IndexSpec {
93
+ name?: string;
94
+ keys: Array<[string, IndexDirection]> | Record<string, IndexDirection>;
95
+ unique?: boolean;
96
+ sparse?: boolean;
97
+ partial?: Record<string, unknown>;
98
+ expireAfterSeconds?: number;
99
+ }
100
+
101
+ export interface IndexDescriptor {
102
+ collection: string;
103
+ name: string;
104
+ keys: Array<[string, IndexDirection]>;
105
+ unique: boolean;
106
+ sparse: boolean;
107
+ partial?: Record<string, unknown>;
108
+ expireAfterSeconds?: number;
109
+ kind: IndexKind;
110
+ }
111
+
112
+ /** Distance metric used to compare vectors. */
113
+ export type VectorMetric = 'cosine' | 'l2' | 'hamming';
114
+
115
+ /**
116
+ * On-disk storage precision for vectors.
117
+ * - `float32` (default): 4 bytes per dim
118
+ * - `int8`: 1 byte per dim, 4× smaller, typically <2% accuracy loss
119
+ * - `bit`: 1 bit per dim, 32× smaller; requires metric='hamming'
120
+ */
121
+ export type VectorStorage = 'float32' | 'int8' | 'bit';
122
+
123
+ /** Query shape: single vector or an array of vectors (ColBERT-style). */
124
+ export type VectorQueryMode = 'single' | 'late-interaction';
125
+
126
+ /** How multi-vector distances are aggregated per document. */
127
+ export type VectorAggregation = 'max-sim' | 'sum';
128
+
129
+ /** Spec used to declare a vector index on a collection field. */
130
+ export interface VectorIndexSpec {
131
+ field: string;
132
+ dimensions: number;
133
+ metric?: VectorMetric;
134
+ storage?: VectorStorage;
135
+ matryoshka?: boolean;
136
+ multiVector?: boolean;
137
+ }
138
+
139
+ /** Metadata for a registered vector index. */
140
+ export interface VectorIndexDescriptor {
141
+ collection: string;
142
+ field: string;
143
+ dimensions: number;
144
+ metric: VectorMetric;
145
+ storage: VectorStorage;
146
+ matryoshka: boolean;
147
+ multiVector: boolean;
148
+ }
149
+
150
+ /** Vector search clause riding inside DbFindOptions. */
151
+ export interface VectorQuery {
152
+ field: string;
153
+ value: number[] | number[][];
154
+ k: number;
155
+ metric?: VectorMetric;
156
+ minScore?: number;
157
+ queryMode?: VectorQueryMode;
158
+ aggregation?: VectorAggregation;
159
+ }
160
+
161
+ /** Document returned by a vector search with similarity metadata attached. */
162
+ export type VectorSearchHit = Record<string, any> & {
163
+ _score: number;
164
+ _distance: number;
165
+ };
166
+
86
167
  /**
87
168
  * Database find options
88
169
  */
@@ -91,6 +172,8 @@ export interface DbFindOptions {
91
172
  skip?: number;
92
173
  sort?: Record<string, 1 | -1>;
93
174
  projection?: Record<string, 1 | 0>;
175
+ /** Hybrid metadata + vector search clause. */
176
+ vector?: VectorQuery;
94
177
  }
95
178
 
96
179
  /**
@@ -234,6 +317,138 @@ export interface Storage {
234
317
  getMetadata(key: string): Promise<StorageMetadata>;
235
318
  }
236
319
 
320
+ // Stewardship Types
321
+
322
+ /** Delegation mode for stewardship overrides */
323
+ export type DelegationMode = 'full' | 'scoped';
324
+
325
+ /** Status of a stewardship override */
326
+ export type StewardshipStatus = 'active' | 'suspended' | 'revoked' | 'expired';
327
+
328
+ /** A scoped permission entry */
329
+ export interface ScopedPermission {
330
+ /** Resource name */
331
+ resource: string;
332
+ /** Allowed actions on the resource */
333
+ actions: string[];
334
+ }
335
+
336
+ /** A stewardship override record */
337
+ export interface StewardshipOverride {
338
+ id: string;
339
+ steward_id: string;
340
+ ward_id: string;
341
+ delegation_mode: DelegationMode;
342
+ scoped_permissions: ScopedPermission[];
343
+ valid_from?: number;
344
+ valid_until?: number;
345
+ status: StewardshipStatus;
346
+ reason?: string;
347
+ source: string;
348
+ source_circle_id?: string;
349
+ source_relation_type_id?: string;
350
+ created_at: number;
351
+ updated_at: number;
352
+ }
353
+
354
+ /** Options for creating a stewardship override */
355
+ export interface CreateStewardshipOverrideRequest {
356
+ steward_id: string;
357
+ ward_id: string;
358
+ delegation_mode?: DelegationMode;
359
+ scoped_permissions?: ScopedPermission[];
360
+ valid_from?: number;
361
+ valid_until?: number;
362
+ reason?: string;
363
+ }
364
+
365
+ /** Result of resolving stewardship for a user */
366
+ export interface StewardshipResolution {
367
+ /** Users who are stewards of this user */
368
+ stewards: StewardshipOverride[];
369
+ /** Users this user is a steward of */
370
+ wards: StewardshipOverride[];
371
+ }
372
+
373
+ /** Context for acting as another user */
374
+ export interface ActAsContext {
375
+ steward_id: string;
376
+ ward_id: string;
377
+ delegation_mode: DelegationMode;
378
+ scoped_permissions: ScopedPermission[];
379
+ session_token: string;
380
+ expires_at: number;
381
+ }
382
+
383
+ /** An entry in the stewardship audit log */
384
+ export interface StewardshipAuditEntry {
385
+ id: string;
386
+ performed_by: string;
387
+ on_behalf_of: string;
388
+ action: string;
389
+ resource?: string;
390
+ details?: Record<string, any>;
391
+ created_at: number;
392
+ }
393
+
394
+ /** Options for listing audit log entries */
395
+ export interface AuditListOptions {
396
+ limit?: number;
397
+ offset?: number;
398
+ }
399
+
400
+ /** Stewardship service interface */
401
+ export interface Stewardship {
402
+ resolve(userId: string): Promise<StewardshipResolution>;
403
+ createOverride(options: CreateStewardshipOverrideRequest): Promise<StewardshipOverride>;
404
+ revoke(id: string): Promise<void>;
405
+ checkPermission(stewardId: string, wardId: string, resource: string, action: string): Promise<boolean>;
406
+ createActAs(stewardId: string, wardId: string): Promise<ActAsContext>;
407
+ listAudit(userId: string, options?: AuditListOptions): Promise<StewardshipAuditEntry[]>;
408
+ }
409
+
410
+ // Resource Types
411
+
412
+ /** A platform resource definition */
413
+ export interface Resource {
414
+ id: string;
415
+ resource_name: string;
416
+ title: string;
417
+ description?: string;
418
+ actions: string[];
419
+ created_at: number;
420
+ updated_at: number;
421
+ }
422
+
423
+ /** Options for creating a resource */
424
+ export interface CreateResourceRequest {
425
+ resource_name: string;
426
+ title: string;
427
+ description?: string;
428
+ actions?: string[];
429
+ }
430
+
431
+ // Circle Types
432
+
433
+ /** Circle membership entry */
434
+ export interface CircleMembership {
435
+ user_id: string;
436
+ email: string;
437
+ relationship: string;
438
+ is_primary_contact: boolean;
439
+ joined_at: number;
440
+ }
441
+
442
+ /** A circle */
443
+ export interface Circle {
444
+ id: string;
445
+ name: string;
446
+ metadata?: Record<string, any>;
447
+ member_count: number;
448
+ created_at: number;
449
+ updated_at: number;
450
+ }
451
+
237
452
  // Platform Types
238
453
 
239
454
  /**
@@ -246,6 +461,39 @@ export interface Platform {
246
461
  db: Database;
247
462
  /** Storage service instance */
248
463
  storage: Storage;
464
+ /** Auth service with stewardship, resources, and circle helpers */
465
+ auth: {
466
+ register(options: { email: string; password: string; profile?: Record<string, any> }): Promise<any>;
467
+ login(options: { email: string; password: string }): Promise<any>;
468
+ validate(accessToken: string): Promise<any>;
469
+ refresh(refreshToken: string): Promise<any>;
470
+ logout(sessionId: string): Promise<void>;
471
+ getUser(userId: string): Promise<any>;
472
+ listUsers(filter?: Record<string, any>): Promise<any>;
473
+ updateUser(userId: string, update: Record<string, any>): Promise<any>;
474
+ deleteUser(userId: string): Promise<void>;
475
+ sendVerification(userId: string): Promise<any>;
476
+ verifyEmail(token: string): Promise<void>;
477
+ sendPasswordReset(email: string): Promise<any>;
478
+ resetPassword(token: string, newPassword: string): Promise<void>;
479
+ changePassword(userId: string, oldPassword: string, newPassword: string): Promise<void>;
480
+ getFieldConfig(): Promise<any>;
481
+ getOAuthUrl(provider: string, options?: { redirectUri?: string }): Promise<any>;
482
+ handleOAuthCallback(provider: string, params: { code: string; state: string }): Promise<any>;
483
+
484
+ /** Stewardship (guardian/ward delegation) */
485
+ stewardship: Stewardship;
486
+
487
+ /** List available resources */
488
+ listResources(): Promise<Resource[]>;
489
+ /** Create a resource definition */
490
+ createResource(options: CreateResourceRequest): Promise<Resource>;
491
+
492
+ /** Get circle members */
493
+ getCircleMembers(circleId: string): Promise<CircleMembership[]>;
494
+ /** Get circles a user belongs to */
495
+ getUserCircles(userId: string): Promise<Circle[]>;
496
+ };
249
497
  /** Legacy aliases for compatibility */
250
498
  env: {
251
499
  KV: KvStore;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maravilla-labs/types",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "TypeScript definitions for Maravilla Runtime platform APIs",
5
5
  "main": "index.ts",
6
6
  "types": "index.ts",