@vibase/sdk 0.0.0-stage → 0.3.1

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.
@@ -0,0 +1,119 @@
1
+ import type { FilterArgs, FilterSpecs } from './filters.js';
2
+ /** Helper types the generated `BuiltInOperations` is written with: openapi-typescript's `operations` entry to the flat arguments, result and item (DX603 D3, D5). */
3
+ type Empty = Record<never, never>;
4
+ type Simplify<T> = {
5
+ [K in keyof T]: T[K];
6
+ } & Empty;
7
+ type Parameters_<Op, Place extends 'path' | 'query'> = Op extends {
8
+ parameters: {
9
+ [P in Place]?: infer X;
10
+ };
11
+ } ? [NonNullable<X>] extends [never] ? Empty : NonNullable<X> : Empty;
12
+ type Body<Op> = Op extends {
13
+ requestBody?: infer R;
14
+ } ? [NonNullable<R>] extends [never] ? Empty : NonNullable<R> extends {
15
+ content: {
16
+ 'application/json': infer B;
17
+ };
18
+ } ? B : Empty : Empty;
19
+ /** Path, query and body fields in one object: the shape MCP tools and action requests already take. */
20
+ export type ArgsOf<Op> = Simplify<Parameters_<Op, 'path'> & Parameters_<Op, 'query'> & Body<Op>>;
21
+ /** The parsed JSON body of the response with this status. */
22
+ export type ResultOf<Op, Status extends number> = Op extends {
23
+ responses: {
24
+ [S in Status]: {
25
+ content: {
26
+ 'application/json': infer R;
27
+ };
28
+ };
29
+ };
30
+ } ? R : never;
31
+ /** One item of a paginated result's `data`. */
32
+ export type ItemOf<Result> = Result extends {
33
+ data: readonly (infer I)[];
34
+ } ? I : never;
35
+ /** The arguments with each filter parameter retyped as its `Filter` (DX608 D9); the document's own type for them is dropped. */
36
+ export type WithFilters<Args, F extends FilterSpecs> = Simplify<FilterArgs<Args, F>>;
37
+ /** What an aggregate operation says about its fields (DX616 D2): the field names each function and `group_by` take (`never` for none), each field's filter kind, and the money fields. */
38
+ export interface AggregateShape {
39
+ fields: {
40
+ sum: string;
41
+ avg: string;
42
+ min: string;
43
+ max: string;
44
+ group_by: string;
45
+ };
46
+ kinds: {
47
+ [field: string]: string;
48
+ };
49
+ money: {
50
+ [field: string]: string;
51
+ };
52
+ }
53
+ type Fn = 'sum' | 'avg' | 'min' | 'max';
54
+ type AggParam = Fn | 'group_by';
55
+ /** One field name of a function's list, or a readonly array of them (D3). */
56
+ type OneOrMany<F extends string> = F | readonly F[];
57
+ /** `group_by`: one groupable field, or a tuple of one or two (the server's cap, CORE207 D3). */
58
+ type GroupArg<F extends string> = F | readonly [F] | readonly [F, F];
59
+ /** The argument object: the operation's filters as typed (DX608 D9), then each function that has fields. */
60
+ type AggregateArgs<Args, S extends AggregateShape> = Omit<Args, AggParam> & {
61
+ [P in Fn as [S['fields'][P]] extends [never] ? never : P]?: OneOrMany<S['fields'][P]>;
62
+ } & ([S['fields']['group_by']] extends [never] ? unknown : {
63
+ group_by?: GroupArg<S['fields']['group_by']>;
64
+ });
65
+ /** The field names an argument value names. */
66
+ type Names<V> = Exclude<V, undefined> extends infer X ? (X extends readonly (infer E)[] ? E : X) : never;
67
+ /** Whether the argument may be absent. */
68
+ type Maybe<V> = undefined extends V ? true : false;
69
+ type Kind<S extends AggregateShape, F> = F extends keyof S['kinds'] ? S['kinds'][F] : never;
70
+ type Num = number | null;
71
+ type ValueOf<S extends AggregateShape, P extends Fn, F> = P extends 'sum' | 'avg' ? Num : Kind<S, F> extends 'integer' ? Num : string | null;
72
+ type KeyOf<S extends AggregateShape, F> = (Kind<S, F> extends 'integer' ? number : Kind<S, F> extends 'boolean' ? boolean : string) | null;
73
+ type Flat<T> = {
74
+ [K in keyof T]: T[K];
75
+ } & Empty;
76
+ /** The function keys asked in `A`: each as `{ [field]: value }`, optional when the argument may be undefined. */
77
+ type FunctionKeys<A, S extends AggregateShape> = {
78
+ [P in Fn as P extends keyof A ? (true extends Maybe<A[P]> ? never : P) : never]: P extends keyof A ? {
79
+ [F in Names<A[P]> & string]: ValueOf<S, P, F>;
80
+ } : never;
81
+ } & {
82
+ [P in Fn as P extends keyof A ? (true extends Maybe<A[P]> ? P : never) : never]?: P extends keyof A ? {
83
+ [F in Names<A[P]> & string]: ValueOf<S, P, F>;
84
+ } : never;
85
+ };
86
+ type FieldsOf<A, P extends Fn> = P extends keyof A ? Names<A[P]> & string : never;
87
+ type MoneyOf<A, S extends AggregateShape> = Extract<FieldsOf<A, Fn>, keyof S['money'] & string>;
88
+ type CurrencyKey<A, S extends AggregateShape> = [MoneyOf<A, S>] extends [never] ? unknown : {
89
+ currency: {
90
+ [F in MoneyOf<A, S>]: string | null;
91
+ };
92
+ };
93
+ type Asked<A, S extends AggregateShape> = FunctionKeys<A, S> & CurrencyKey<A, S>;
94
+ type Ungrouped<A, S extends AggregateShape> = Flat<{
95
+ count: number;
96
+ } & Asked<A, S>>;
97
+ type Grouped<A, S extends AggregateShape, GB> = {
98
+ count: number;
99
+ groups: Flat<{
100
+ key: {
101
+ [F in Names<GB> & string]: KeyOf<S, F>;
102
+ };
103
+ count: number;
104
+ } & Asked<A, S>>[];
105
+ };
106
+ /** The answer typed by what was asked (D4): ungrouped, grouped, or the union where `group_by` may be undefined. */
107
+ export type AggregateAnswer<A, S extends AggregateShape> = 'group_by' extends keyof A ? [Exclude<A['group_by' & keyof A], undefined>] extends [never] ? Ungrouped<A, S> : true extends Maybe<A['group_by' & keyof A]> ? Ungrouped<A, S> | Grouped<A, S, A['group_by' & keyof A]> : Grouped<A, S, A['group_by' & keyof A]> : Ungrouped<A, S>;
108
+ /** The one generic member of an aggregate operation (D3): `const` arguments decide the answer, and a name the operation does not take is refused. */
109
+ export type AggregateMethod<Args, S extends AggregateShape> = {
110
+ (args?: undefined, options?: {
111
+ signal?: AbortSignal;
112
+ }): Promise<Ungrouped<Record<never, never>, S>>;
113
+ <const A extends AggregateArgs<Args, S>>(args: A & {
114
+ [K in Exclude<keyof A, keyof AggregateArgs<Args, S>>]: never;
115
+ }, options?: {
116
+ signal?: AbortSignal;
117
+ }): Promise<AggregateAnswer<A, S>>;
118
+ };
119
+ export {};
package/dist/typing.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "@vibase/sdk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.3.1",
4
+ "description": "The Vibase TypeScript client: typed methods for every operation of the REST API of a Vibase deployment.",
5
+ "license": "MIT",
6
+ "homepage": "https://docs.vibase.ai",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/benocodes/crm.git",
10
+ "directory": "packages/sdk"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/benocodes/crm/issues"
14
+ },
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "engines": {
18
+ "node": ">=22"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ }
30
+ }