@objectstack/client 1.0.4 → 1.0.6

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,22 @@
1
+
2
+ > @objectstack/client@1.0.6 build /home/runner/work/spec/spec/packages/client
3
+ > tsup --config ../../tsup.config.ts
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.5.1
8
+ CLI Using tsup config: /home/runner/work/spec/spec/tsup.config.ts
9
+ CLI Target: es2020
10
+ CLI Cleaning output folder
11
+ ESM Build start
12
+ CJS Build start
13
+ ESM dist/index.mjs 19.46 KB
14
+ ESM dist/index.mjs.map 40.47 KB
15
+ ESM ⚡️ Build success in 35ms
16
+ CJS dist/index.js 20.62 KB
17
+ CJS dist/index.js.map 40.53 KB
18
+ CJS ⚡️ Build success in 42ms
19
+ DTS Build start
20
+ DTS ⚡️ Build success in 10222ms
21
+ DTS dist/index.d.mts 10.28 KB
22
+ DTS dist/index.d.ts 10.28 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @objectstack/client
2
2
 
3
+ ## 1.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [a7f7b9d]
8
+ - @objectstack/spec@1.0.6
9
+ - @objectstack/core@1.0.6
10
+
11
+ ## 1.0.5
12
+
13
+ ### Patch Changes
14
+
15
+ - b1d24bd: refactor: migrate build system from tsc to tsup for faster builds
16
+ - Replaced `tsc` with `tsup` (using esbuild) across all packages
17
+ - Added shared `tsup.config.ts` in workspace root
18
+ - Added `tsup` as workspace dev dependency
19
+ - significantly improved build performance
20
+ - Updated dependencies [b1d24bd]
21
+ - @objectstack/core@1.0.5
22
+ - @objectstack/spec@1.0.5
23
+
3
24
  ## 1.0.4
4
25
 
5
26
  ### Patch Changes
@@ -0,0 +1,333 @@
1
+ import { FilterCondition, QueryAST, SortNode, AggregationNode } from '@objectstack/spec/data';
2
+ import { GetDiscoveryResponse, StandardErrorCode, ErrorCategory, GetMetaTypesResponse, GetMetaItemsResponse, MetadataCacheRequest, MetadataCacheResponse, LoginRequest, SessionResponse, FileUploadResponse, BatchUpdateRequest, BatchUpdateResponse, BatchOptions } from '@objectstack/spec/api';
3
+ export { BatchOperationResult, BatchOptions, BatchRecord, BatchUpdateRequest, BatchUpdateResponse, DeleteManyRequest, ErrorCategory, GetDiscoveryResponse, GetMetaItemsResponse, GetMetaTypesResponse, MetadataCacheRequest, MetadataCacheResponse, StandardErrorCode, UpdateManyRequest } from '@objectstack/spec/api';
4
+ import { Logger } from '@objectstack/core';
5
+
6
+ /**
7
+ * Type-Safe Query Builder
8
+ *
9
+ * Provides a fluent API for building ObjectStack queries with:
10
+ * - Compile-time type checking
11
+ * - Intelligent code completion
12
+ * - Runtime validation
13
+ * - Type-safe filters and selections
14
+ */
15
+
16
+ /**
17
+ * Type-safe filter builder
18
+ */
19
+ declare class FilterBuilder<T = any> {
20
+ private conditions;
21
+ /**
22
+ * Equality filter: field = value
23
+ */
24
+ equals<K extends keyof T>(field: K, value: T[K]): this;
25
+ /**
26
+ * Not equals filter: field != value
27
+ */
28
+ notEquals<K extends keyof T>(field: K, value: T[K]): this;
29
+ /**
30
+ * Greater than filter: field > value
31
+ */
32
+ greaterThan<K extends keyof T>(field: K, value: T[K]): this;
33
+ /**
34
+ * Greater than or equal filter: field >= value
35
+ */
36
+ greaterThanOrEqual<K extends keyof T>(field: K, value: T[K]): this;
37
+ /**
38
+ * Less than filter: field < value
39
+ */
40
+ lessThan<K extends keyof T>(field: K, value: T[K]): this;
41
+ /**
42
+ * Less than or equal filter: field <= value
43
+ */
44
+ lessThanOrEqual<K extends keyof T>(field: K, value: T[K]): this;
45
+ /**
46
+ * IN filter: field IN (value1, value2, ...)
47
+ */
48
+ in<K extends keyof T>(field: K, values: T[K][]): this;
49
+ /**
50
+ * NOT IN filter: field NOT IN (value1, value2, ...)
51
+ */
52
+ notIn<K extends keyof T>(field: K, values: T[K][]): this;
53
+ /**
54
+ * LIKE filter: field LIKE pattern
55
+ */
56
+ like<K extends keyof T>(field: K, pattern: string): this;
57
+ /**
58
+ * IS NULL filter: field IS NULL
59
+ */
60
+ isNull<K extends keyof T>(field: K): this;
61
+ /**
62
+ * IS NOT NULL filter: field IS NOT NULL
63
+ */
64
+ isNotNull<K extends keyof T>(field: K): this;
65
+ /**
66
+ * Build the filter condition
67
+ */
68
+ build(): FilterCondition;
69
+ /**
70
+ * Get raw conditions array
71
+ */
72
+ getConditions(): FilterCondition[];
73
+ }
74
+ /**
75
+ * Type-safe query builder
76
+ */
77
+ declare class QueryBuilder<T = any> {
78
+ private query;
79
+ private _object;
80
+ constructor(object: string);
81
+ /**
82
+ * Select specific fields
83
+ */
84
+ select<K extends keyof T>(...fields: K[]): this;
85
+ /**
86
+ * Add filters using a builder function
87
+ */
88
+ where(builderFn: (builder: FilterBuilder<T>) => void): this;
89
+ /**
90
+ * Add raw filter condition
91
+ */
92
+ filter(condition: FilterCondition): this;
93
+ /**
94
+ * Sort by fields
95
+ */
96
+ orderBy<K extends keyof T>(field: K, order?: 'asc' | 'desc'): this;
97
+ /**
98
+ * Limit the number of results
99
+ */
100
+ limit(count: number): this;
101
+ /**
102
+ * Skip records (for pagination)
103
+ */
104
+ skip(count: number): this;
105
+ /**
106
+ * Paginate results
107
+ */
108
+ paginate(page: number, pageSize: number): this;
109
+ /**
110
+ * Group by fields
111
+ */
112
+ groupBy<K extends keyof T>(...fields: K[]): this;
113
+ /**
114
+ * Build the final query AST
115
+ */
116
+ build(): QueryAST;
117
+ /**
118
+ * Get the current query state
119
+ */
120
+ getQuery(): Partial<QueryAST>;
121
+ }
122
+ /**
123
+ * Create a type-safe query builder for an object
124
+ */
125
+ declare function createQuery<T = any>(object: string): QueryBuilder<T>;
126
+ /**
127
+ * Create a type-safe filter builder
128
+ */
129
+ declare function createFilter<T = any>(): FilterBuilder<T>;
130
+
131
+ interface ClientConfig {
132
+ baseUrl: string;
133
+ token?: string;
134
+ /**
135
+ * Custom fetch implementation (e.g. node-fetch or for Next.js caching)
136
+ */
137
+ fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
138
+ /**
139
+ * Logger instance for debugging
140
+ */
141
+ logger?: Logger;
142
+ /**
143
+ * Enable debug logging
144
+ */
145
+ debug?: boolean;
146
+ }
147
+ /**
148
+ * Discovery Result
149
+ * Re-export from @objectstack/spec/api for convenience
150
+ */
151
+ type DiscoveryResult = GetDiscoveryResponse;
152
+ interface QueryOptions {
153
+ select?: string[];
154
+ filters?: Record<string, any>;
155
+ sort?: string | string[] | SortNode[];
156
+ top?: number;
157
+ skip?: number;
158
+ aggregations?: AggregationNode[];
159
+ groupBy?: string[];
160
+ }
161
+ interface PaginatedResult<T = any> {
162
+ value: T[];
163
+ count: number;
164
+ }
165
+ interface StandardError {
166
+ code: StandardErrorCode;
167
+ message: string;
168
+ category: ErrorCategory;
169
+ httpStatus: number;
170
+ retryable: boolean;
171
+ details?: Record<string, any>;
172
+ }
173
+ declare class ObjectStackClient {
174
+ private baseUrl;
175
+ private token?;
176
+ private fetchImpl;
177
+ private discoveryInfo?;
178
+ private logger;
179
+ constructor(config: ClientConfig);
180
+ /**
181
+ * Initialize the client by discovering server capabilities.
182
+ */
183
+ connect(): Promise<{
184
+ version: string;
185
+ apiName: string;
186
+ capabilities?: {
187
+ search: boolean;
188
+ files: boolean;
189
+ graphql: boolean;
190
+ analytics: boolean;
191
+ hub: boolean;
192
+ websockets: boolean;
193
+ } | undefined;
194
+ endpoints?: {
195
+ data: string;
196
+ metadata: string;
197
+ auth: string;
198
+ graphql?: string | undefined;
199
+ storage?: string | undefined;
200
+ automation?: string | undefined;
201
+ analytics?: string | undefined;
202
+ hub?: string | undefined;
203
+ } | undefined;
204
+ }>;
205
+ /**
206
+ * Metadata Operations
207
+ */
208
+ meta: {
209
+ /**
210
+ * Get all available metadata types
211
+ * Returns types like 'object', 'plugin', 'view', etc.
212
+ */
213
+ getTypes: () => Promise<GetMetaTypesResponse>;
214
+ /**
215
+ * Get all items of a specific metadata type
216
+ * @param type - Metadata type name (e.g., 'object', 'plugin')
217
+ */
218
+ getItems: (type: string) => Promise<GetMetaItemsResponse>;
219
+ /**
220
+ * Get a specific object definition by name
221
+ * @deprecated Use `getItem('object', name)` instead for consistency with spec protocol
222
+ * @param name - Object name (snake_case identifier)
223
+ */
224
+ getObject: (name: string) => Promise<any>;
225
+ /**
226
+ * Get a specific metadata item by type and name
227
+ * @param type - Metadata type (e.g., 'object', 'plugin')
228
+ * @param name - Item name (snake_case identifier)
229
+ */
230
+ getItem: (type: string, name: string) => Promise<any>;
231
+ /**
232
+ * Save a metadata item
233
+ * @param type - Metadata type (e.g., 'object', 'plugin')
234
+ * @param name - Item name
235
+ * @param item - The metadata content to save
236
+ */
237
+ saveItem: (type: string, name: string, item: any) => Promise<any>;
238
+ /**
239
+ * Get object metadata with cache support
240
+ * Supports ETag-based conditional requests for efficient caching
241
+ */
242
+ getCached: (name: string, cacheOptions?: MetadataCacheRequest) => Promise<MetadataCacheResponse>;
243
+ getView: (object: string, type?: "list" | "form") => Promise<any>;
244
+ };
245
+ /**
246
+ * Analytics Services
247
+ */
248
+ analytics: {
249
+ query: (payload: any) => Promise<any>;
250
+ meta: (cube: string) => Promise<any>;
251
+ explain: (payload: any) => Promise<any>;
252
+ };
253
+ /**
254
+ * Hub Management Services
255
+ */
256
+ hub: {
257
+ spaces: {
258
+ list: () => Promise<any>;
259
+ create: (payload: any) => Promise<any>;
260
+ };
261
+ plugins: {
262
+ install: (pkg: string, version?: string) => Promise<any>;
263
+ };
264
+ };
265
+ /**
266
+ * Authentication Services
267
+ */
268
+ auth: {
269
+ login: (request: LoginRequest) => Promise<SessionResponse>;
270
+ logout: () => Promise<void>;
271
+ me: () => Promise<SessionResponse>;
272
+ };
273
+ /**
274
+ * Storage Services
275
+ */
276
+ storage: {
277
+ upload: (file: any, scope?: string) => Promise<FileUploadResponse>;
278
+ getDownloadUrl: (fileId: string) => Promise<string>;
279
+ };
280
+ /**
281
+ * Automation Services
282
+ */
283
+ automation: {
284
+ trigger: (triggerName: string, payload: any) => Promise<any>;
285
+ };
286
+ /**
287
+ * Data Operations
288
+ */
289
+ data: {
290
+ /**
291
+ * Advanced Query using ObjectStack Query Protocol
292
+ * Supports both simplified options and full AST
293
+ */
294
+ query: <T = any>(object: string, query: Partial<QueryAST>) => Promise<PaginatedResult<T>>;
295
+ find: <T = any>(object: string, options?: QueryOptions) => Promise<PaginatedResult<T>>;
296
+ get: <T = any>(object: string, id: string) => Promise<T>;
297
+ create: <T = any>(object: string, data: Partial<T>) => Promise<T>;
298
+ createMany: <T = any>(object: string, data: Partial<T>[]) => Promise<T[]>;
299
+ update: <T = any>(object: string, id: string, data: Partial<T>) => Promise<T>;
300
+ /**
301
+ * Batch update multiple records
302
+ * Uses the new BatchUpdateRequest schema with full control over options
303
+ */
304
+ batch: (object: string, request: BatchUpdateRequest) => Promise<BatchUpdateResponse>;
305
+ /**
306
+ * Update multiple records (simplified batch update)
307
+ * Convenience method for batch updates without full BatchUpdateRequest
308
+ */
309
+ updateMany: <T = any>(object: string, records: Array<{
310
+ id: string;
311
+ data: Partial<T>;
312
+ }>, options?: BatchOptions) => Promise<BatchUpdateResponse>;
313
+ delete: (object: string, id: string) => Promise<{
314
+ success: boolean;
315
+ }>;
316
+ /**
317
+ * Delete multiple records by IDs
318
+ */
319
+ deleteMany: (object: string, ids: string[], options?: BatchOptions) => Promise<BatchUpdateResponse>;
320
+ };
321
+ /**
322
+ * Private Helpers
323
+ */
324
+ private isFilterAST;
325
+ private fetch;
326
+ /**
327
+ * Get the conventional route path for a given API endpoint type
328
+ * ObjectStack uses standard conventions: /api/v1/data, /api/v1/metadata, /api/v1/ui
329
+ */
330
+ private getRoute;
331
+ }
332
+
333
+ export { type ClientConfig, type DiscoveryResult, FilterBuilder, ObjectStackClient, type PaginatedResult, QueryBuilder, type QueryOptions, type StandardError, createFilter, createQuery };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,134 @@
1
- import { QueryAST, SortNode, AggregationNode } from '@objectstack/spec/data';
2
- import { BatchUpdateRequest, BatchUpdateResponse, BatchOptions, MetadataCacheRequest, MetadataCacheResponse, StandardErrorCode, ErrorCategory, GetDiscoveryResponse, GetMetaTypesResponse, GetMetaItemsResponse, LoginRequest, SessionResponse, FileUploadResponse } from '@objectstack/spec/api';
1
+ import { FilterCondition, QueryAST, SortNode, AggregationNode } from '@objectstack/spec/data';
2
+ import { GetDiscoveryResponse, StandardErrorCode, ErrorCategory, GetMetaTypesResponse, GetMetaItemsResponse, MetadataCacheRequest, MetadataCacheResponse, LoginRequest, SessionResponse, FileUploadResponse, BatchUpdateRequest, BatchUpdateResponse, BatchOptions } from '@objectstack/spec/api';
3
+ export { BatchOperationResult, BatchOptions, BatchRecord, BatchUpdateRequest, BatchUpdateResponse, DeleteManyRequest, ErrorCategory, GetDiscoveryResponse, GetMetaItemsResponse, GetMetaTypesResponse, MetadataCacheRequest, MetadataCacheResponse, StandardErrorCode, UpdateManyRequest } from '@objectstack/spec/api';
3
4
  import { Logger } from '@objectstack/core';
4
- export interface ClientConfig {
5
+
6
+ /**
7
+ * Type-Safe Query Builder
8
+ *
9
+ * Provides a fluent API for building ObjectStack queries with:
10
+ * - Compile-time type checking
11
+ * - Intelligent code completion
12
+ * - Runtime validation
13
+ * - Type-safe filters and selections
14
+ */
15
+
16
+ /**
17
+ * Type-safe filter builder
18
+ */
19
+ declare class FilterBuilder<T = any> {
20
+ private conditions;
21
+ /**
22
+ * Equality filter: field = value
23
+ */
24
+ equals<K extends keyof T>(field: K, value: T[K]): this;
25
+ /**
26
+ * Not equals filter: field != value
27
+ */
28
+ notEquals<K extends keyof T>(field: K, value: T[K]): this;
29
+ /**
30
+ * Greater than filter: field > value
31
+ */
32
+ greaterThan<K extends keyof T>(field: K, value: T[K]): this;
33
+ /**
34
+ * Greater than or equal filter: field >= value
35
+ */
36
+ greaterThanOrEqual<K extends keyof T>(field: K, value: T[K]): this;
37
+ /**
38
+ * Less than filter: field < value
39
+ */
40
+ lessThan<K extends keyof T>(field: K, value: T[K]): this;
41
+ /**
42
+ * Less than or equal filter: field <= value
43
+ */
44
+ lessThanOrEqual<K extends keyof T>(field: K, value: T[K]): this;
45
+ /**
46
+ * IN filter: field IN (value1, value2, ...)
47
+ */
48
+ in<K extends keyof T>(field: K, values: T[K][]): this;
49
+ /**
50
+ * NOT IN filter: field NOT IN (value1, value2, ...)
51
+ */
52
+ notIn<K extends keyof T>(field: K, values: T[K][]): this;
53
+ /**
54
+ * LIKE filter: field LIKE pattern
55
+ */
56
+ like<K extends keyof T>(field: K, pattern: string): this;
57
+ /**
58
+ * IS NULL filter: field IS NULL
59
+ */
60
+ isNull<K extends keyof T>(field: K): this;
61
+ /**
62
+ * IS NOT NULL filter: field IS NOT NULL
63
+ */
64
+ isNotNull<K extends keyof T>(field: K): this;
65
+ /**
66
+ * Build the filter condition
67
+ */
68
+ build(): FilterCondition;
69
+ /**
70
+ * Get raw conditions array
71
+ */
72
+ getConditions(): FilterCondition[];
73
+ }
74
+ /**
75
+ * Type-safe query builder
76
+ */
77
+ declare class QueryBuilder<T = any> {
78
+ private query;
79
+ private _object;
80
+ constructor(object: string);
81
+ /**
82
+ * Select specific fields
83
+ */
84
+ select<K extends keyof T>(...fields: K[]): this;
85
+ /**
86
+ * Add filters using a builder function
87
+ */
88
+ where(builderFn: (builder: FilterBuilder<T>) => void): this;
89
+ /**
90
+ * Add raw filter condition
91
+ */
92
+ filter(condition: FilterCondition): this;
93
+ /**
94
+ * Sort by fields
95
+ */
96
+ orderBy<K extends keyof T>(field: K, order?: 'asc' | 'desc'): this;
97
+ /**
98
+ * Limit the number of results
99
+ */
100
+ limit(count: number): this;
101
+ /**
102
+ * Skip records (for pagination)
103
+ */
104
+ skip(count: number): this;
105
+ /**
106
+ * Paginate results
107
+ */
108
+ paginate(page: number, pageSize: number): this;
109
+ /**
110
+ * Group by fields
111
+ */
112
+ groupBy<K extends keyof T>(...fields: K[]): this;
113
+ /**
114
+ * Build the final query AST
115
+ */
116
+ build(): QueryAST;
117
+ /**
118
+ * Get the current query state
119
+ */
120
+ getQuery(): Partial<QueryAST>;
121
+ }
122
+ /**
123
+ * Create a type-safe query builder for an object
124
+ */
125
+ declare function createQuery<T = any>(object: string): QueryBuilder<T>;
126
+ /**
127
+ * Create a type-safe filter builder
128
+ */
129
+ declare function createFilter<T = any>(): FilterBuilder<T>;
130
+
131
+ interface ClientConfig {
5
132
  baseUrl: string;
6
133
  token?: string;
7
134
  /**
@@ -21,8 +148,8 @@ export interface ClientConfig {
21
148
  * Discovery Result
22
149
  * Re-export from @objectstack/spec/api for convenience
23
150
  */
24
- export type DiscoveryResult = GetDiscoveryResponse;
25
- export interface QueryOptions {
151
+ type DiscoveryResult = GetDiscoveryResponse;
152
+ interface QueryOptions {
26
153
  select?: string[];
27
154
  filters?: Record<string, any>;
28
155
  sort?: string | string[] | SortNode[];
@@ -31,11 +158,11 @@ export interface QueryOptions {
31
158
  aggregations?: AggregationNode[];
32
159
  groupBy?: string[];
33
160
  }
34
- export interface PaginatedResult<T = any> {
161
+ interface PaginatedResult<T = any> {
35
162
  value: T[];
36
163
  count: number;
37
164
  }
38
- export interface StandardError {
165
+ interface StandardError {
39
166
  code: StandardErrorCode;
40
167
  message: string;
41
168
  category: ErrorCategory;
@@ -43,7 +170,7 @@ export interface StandardError {
43
170
  retryable: boolean;
44
171
  details?: Record<string, any>;
45
172
  }
46
- export declare class ObjectStackClient {
173
+ declare class ObjectStackClient {
47
174
  private baseUrl;
48
175
  private token?;
49
176
  private fetchImpl;
@@ -202,5 +329,5 @@ export declare class ObjectStackClient {
202
329
  */
203
330
  private getRoute;
204
331
  }
205
- export { QueryBuilder, FilterBuilder, createQuery, createFilter } from './query-builder';
206
- export type { BatchUpdateRequest, BatchUpdateResponse, UpdateManyRequest, DeleteManyRequest, BatchOptions, BatchRecord, BatchOperationResult, MetadataCacheRequest, MetadataCacheResponse, StandardErrorCode, ErrorCategory, GetDiscoveryResponse, GetMetaTypesResponse, GetMetaItemsResponse } from '@objectstack/spec/api';
332
+
333
+ export { type ClientConfig, type DiscoveryResult, FilterBuilder, ObjectStackClient, type PaginatedResult, QueryBuilder, type QueryOptions, type StandardError, createFilter, createQuery };