dzql 0.6.9 → 0.6.10
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.
- package/package.json +1 -1
- package/src/runtime/namespace.ts +79 -168
package/package.json
CHANGED
package/src/runtime/namespace.ts
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* DZQL Namespace for
|
|
2
|
+
* DZQL Namespace for invoket integration
|
|
3
3
|
*
|
|
4
4
|
* Provides CLI-style access to DZQL operations via the compiled manifest.
|
|
5
5
|
* Each method outputs JSON to console and closes the connection before returning.
|
|
6
6
|
*
|
|
7
|
-
* Setup - add to your tasks.
|
|
8
|
-
* ```
|
|
9
|
-
* import {
|
|
7
|
+
* Setup - add to your tasks.ts:
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Context } from "invoket/context";
|
|
10
|
+
* import { DzqlNamespace } from "dzql/namespace";
|
|
10
11
|
*
|
|
11
12
|
* export class Tasks {
|
|
12
|
-
*
|
|
13
|
-
* this.dzql = new DzqlNamespace();
|
|
14
|
-
* }
|
|
13
|
+
* dzql = new DzqlNamespace();
|
|
15
14
|
* }
|
|
16
15
|
* ```
|
|
17
16
|
*
|
|
18
17
|
* Available Commands:
|
|
19
18
|
*
|
|
20
19
|
* Discovery:
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
20
|
+
* invt dzql:entities # List all entities
|
|
21
|
+
* invt dzql:subscribables # List all subscribables
|
|
22
|
+
* invt dzql:functions # List all manifest functions
|
|
24
23
|
*
|
|
25
24
|
* Entity CRUD:
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
25
|
+
* invt dzql:search venues '{"query": "test"}' # Search with filters
|
|
26
|
+
* invt dzql:get venues '{"id": 1}' # Get by primary key
|
|
27
|
+
* invt dzql:save venues '{"name": "New", "org_id": 1}' # Create (no id)
|
|
28
|
+
* invt dzql:save venues '{"id": 1, "name": "Updated"}' # Update (with id)
|
|
29
|
+
* invt dzql:delete venues '{"id": 1}' # Delete by primary key
|
|
30
|
+
* invt dzql:lookup venues '{"query": "test"}' # Lookup for dropdowns
|
|
32
31
|
*
|
|
33
32
|
* Subscribables:
|
|
34
|
-
*
|
|
33
|
+
* invt dzql:subscribe venue_detail '{"venue_id": 1}' # Get snapshot
|
|
35
34
|
*
|
|
36
35
|
* Ad-hoc Function Calls:
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
36
|
+
* invt dzql:call login_user '{"email": "x", "password": "y"}'
|
|
37
|
+
* invt dzql:call register_user '{"email": "x", "password": "y"}'
|
|
38
|
+
* invt dzql:call get_venue_detail '{"venue_id": 1}'
|
|
39
|
+
* invt dzql:call save_venues '{"name": "Test", "org_id": 1}'
|
|
41
40
|
*
|
|
42
41
|
* Environment:
|
|
43
42
|
* DATABASE_URL - PostgreSQL connection string (default: postgres://localhost:5432/dzql)
|
|
@@ -54,6 +53,27 @@ import type { Manifest, FunctionDef } from "../cli/codegen/manifest.js";
|
|
|
54
53
|
// Default user for CLI operations
|
|
55
54
|
const DEFAULT_USER_ID = 1;
|
|
56
55
|
|
|
56
|
+
/** Query parameters for search operations */
|
|
57
|
+
export interface SearchParams {
|
|
58
|
+
query?: string;
|
|
59
|
+
filters?: Record<string, unknown>;
|
|
60
|
+
sort_field?: string;
|
|
61
|
+
sort_order?: "asc" | "desc";
|
|
62
|
+
limit?: number;
|
|
63
|
+
offset?: number;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Primary key for get/delete operations */
|
|
67
|
+
export interface PkParams {
|
|
68
|
+
id?: number;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Generic params for any operation */
|
|
73
|
+
export interface CallParams {
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
}
|
|
76
|
+
|
|
57
77
|
/**
|
|
58
78
|
* Load manifest from MANIFEST_PATH env var or default locations
|
|
59
79
|
*/
|
|
@@ -122,7 +142,16 @@ function discoverSubscribables(manifest: Manifest): Record<string, { params: Rec
|
|
|
122
142
|
}
|
|
123
143
|
|
|
124
144
|
/**
|
|
125
|
-
* DZQL operations namespace for
|
|
145
|
+
* DZQL operations namespace for invoket
|
|
146
|
+
*
|
|
147
|
+
* Use with invoket task runner:
|
|
148
|
+
* ```ts
|
|
149
|
+
* import { DzqlNamespace } from "dzql/namespace";
|
|
150
|
+
*
|
|
151
|
+
* export class Tasks {
|
|
152
|
+
* dzql = new DzqlNamespace();
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
126
155
|
*/
|
|
127
156
|
export class DzqlNamespace {
|
|
128
157
|
private userId: number;
|
|
@@ -193,8 +222,9 @@ export class DzqlNamespace {
|
|
|
193
222
|
|
|
194
223
|
/**
|
|
195
224
|
* List all available entities
|
|
225
|
+
* @example invt dzql:entities
|
|
196
226
|
*/
|
|
197
|
-
async entities(_context
|
|
227
|
+
async entities(_context: unknown): Promise<void> {
|
|
198
228
|
try {
|
|
199
229
|
const { manifest } = await this.init();
|
|
200
230
|
const entities = discoverEntities(manifest);
|
|
@@ -209,8 +239,9 @@ export class DzqlNamespace {
|
|
|
209
239
|
|
|
210
240
|
/**
|
|
211
241
|
* List all available subscribables
|
|
242
|
+
* @example invt dzql:subscribables
|
|
212
243
|
*/
|
|
213
|
-
async subscribables(_context
|
|
244
|
+
async subscribables(_context: unknown): Promise<void> {
|
|
214
245
|
try {
|
|
215
246
|
const { manifest } = await this.init();
|
|
216
247
|
const subscribables = discoverSubscribables(manifest);
|
|
@@ -225,28 +256,11 @@ export class DzqlNamespace {
|
|
|
225
256
|
|
|
226
257
|
/**
|
|
227
258
|
* Search an entity
|
|
228
|
-
* @example
|
|
259
|
+
* @example invt dzql:search venues '{"query": "test"}'
|
|
229
260
|
*/
|
|
230
|
-
async search(_context:
|
|
231
|
-
if (!entity) {
|
|
232
|
-
console.error("Error: entity name required");
|
|
233
|
-
console.error("Usage: invj dzql:search <entity> '<json_args>'");
|
|
234
|
-
console.error('Example: invj dzql:search venues \'{"query": "test"}\'');
|
|
235
|
-
await this.cleanup();
|
|
236
|
-
process.exit(1);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
let args: any;
|
|
261
|
+
async search(_context: unknown, entity: string, params: SearchParams = {}): Promise<void> {
|
|
240
262
|
try {
|
|
241
|
-
|
|
242
|
-
} catch {
|
|
243
|
-
console.error("Error: arguments must be valid JSON");
|
|
244
|
-
await this.cleanup();
|
|
245
|
-
process.exit(1);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
try {
|
|
249
|
-
const result = await this.executeFunction(`search_${entity}`, args);
|
|
263
|
+
const result = await this.executeFunction(`search_${entity}`, params);
|
|
250
264
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
251
265
|
await this.cleanup();
|
|
252
266
|
} catch (error: any) {
|
|
@@ -258,28 +272,11 @@ export class DzqlNamespace {
|
|
|
258
272
|
|
|
259
273
|
/**
|
|
260
274
|
* Get entity by ID
|
|
261
|
-
* @example
|
|
275
|
+
* @example invt dzql:get venues '{"id": 1}'
|
|
262
276
|
*/
|
|
263
|
-
async get(_context:
|
|
264
|
-
if (!entity) {
|
|
265
|
-
console.error("Error: entity name required");
|
|
266
|
-
console.error("Usage: invj dzql:get <entity> '<json_args>'");
|
|
267
|
-
console.error('Example: invj dzql:get venues \'{"id": 1}\'');
|
|
268
|
-
await this.cleanup();
|
|
269
|
-
process.exit(1);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
let args: any;
|
|
273
|
-
try {
|
|
274
|
-
args = JSON.parse(argsJson);
|
|
275
|
-
} catch {
|
|
276
|
-
console.error("Error: arguments must be valid JSON");
|
|
277
|
-
await this.cleanup();
|
|
278
|
-
process.exit(1);
|
|
279
|
-
}
|
|
280
|
-
|
|
277
|
+
async get(_context: unknown, entity: string, pk: PkParams): Promise<void> {
|
|
281
278
|
try {
|
|
282
|
-
const result = await this.executeFunction(`get_${entity}`,
|
|
279
|
+
const result = await this.executeFunction(`get_${entity}`, pk);
|
|
283
280
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
284
281
|
await this.cleanup();
|
|
285
282
|
} catch (error: any) {
|
|
@@ -291,28 +288,11 @@ export class DzqlNamespace {
|
|
|
291
288
|
|
|
292
289
|
/**
|
|
293
290
|
* Save (create or update) entity
|
|
294
|
-
* @example
|
|
291
|
+
* @example invt dzql:save venues '{"name": "New Venue", "org_id": 1}'
|
|
295
292
|
*/
|
|
296
|
-
async save(_context:
|
|
297
|
-
if (!entity) {
|
|
298
|
-
console.error("Error: entity name required");
|
|
299
|
-
console.error("Usage: invj dzql:save <entity> '<json_args>'");
|
|
300
|
-
console.error('Example: invj dzql:save venues \'{"name": "Test Venue", "org_id": 1}\'');
|
|
301
|
-
await this.cleanup();
|
|
302
|
-
process.exit(1);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
let args: any;
|
|
306
|
-
try {
|
|
307
|
-
args = JSON.parse(argsJson);
|
|
308
|
-
} catch {
|
|
309
|
-
console.error("Error: arguments must be valid JSON");
|
|
310
|
-
await this.cleanup();
|
|
311
|
-
process.exit(1);
|
|
312
|
-
}
|
|
313
|
-
|
|
293
|
+
async save(_context: unknown, entity: string, data: CallParams): Promise<void> {
|
|
314
294
|
try {
|
|
315
|
-
const result = await this.executeFunction(`save_${entity}`,
|
|
295
|
+
const result = await this.executeFunction(`save_${entity}`, data);
|
|
316
296
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
317
297
|
await this.cleanup();
|
|
318
298
|
} catch (error: any) {
|
|
@@ -324,28 +304,11 @@ export class DzqlNamespace {
|
|
|
324
304
|
|
|
325
305
|
/**
|
|
326
306
|
* Delete entity by ID
|
|
327
|
-
* @example
|
|
307
|
+
* @example invt dzql:delete venues '{"id": 1}'
|
|
328
308
|
*/
|
|
329
|
-
async delete(_context:
|
|
330
|
-
if (!entity) {
|
|
331
|
-
console.error("Error: entity name required");
|
|
332
|
-
console.error("Usage: invj dzql:delete <entity> '<json_args>'");
|
|
333
|
-
console.error('Example: invj dzql:delete venues \'{"id": 1}\'');
|
|
334
|
-
await this.cleanup();
|
|
335
|
-
process.exit(1);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
let args: any;
|
|
339
|
-
try {
|
|
340
|
-
args = JSON.parse(argsJson);
|
|
341
|
-
} catch {
|
|
342
|
-
console.error("Error: arguments must be valid JSON");
|
|
343
|
-
await this.cleanup();
|
|
344
|
-
process.exit(1);
|
|
345
|
-
}
|
|
346
|
-
|
|
309
|
+
async delete(_context: unknown, entity: string, pk: PkParams): Promise<void> {
|
|
347
310
|
try {
|
|
348
|
-
const result = await this.executeFunction(`delete_${entity}`,
|
|
311
|
+
const result = await this.executeFunction(`delete_${entity}`, pk);
|
|
349
312
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
350
313
|
await this.cleanup();
|
|
351
314
|
} catch (error: any) {
|
|
@@ -357,28 +320,11 @@ export class DzqlNamespace {
|
|
|
357
320
|
|
|
358
321
|
/**
|
|
359
322
|
* Lookup entity (for dropdowns/autocomplete)
|
|
360
|
-
* @example
|
|
323
|
+
* @example invt dzql:lookup organisations '{"query": "acme"}'
|
|
361
324
|
*/
|
|
362
|
-
async lookup(_context:
|
|
363
|
-
if (!entity) {
|
|
364
|
-
console.error("Error: entity name required");
|
|
365
|
-
console.error("Usage: invj dzql:lookup <entity> '<json_args>'");
|
|
366
|
-
console.error('Example: invj dzql:lookup organisations \'{"query": "acme"}\'');
|
|
367
|
-
await this.cleanup();
|
|
368
|
-
process.exit(1);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
let args: any;
|
|
372
|
-
try {
|
|
373
|
-
args = JSON.parse(argsJson);
|
|
374
|
-
} catch {
|
|
375
|
-
console.error("Error: arguments must be valid JSON");
|
|
376
|
-
await this.cleanup();
|
|
377
|
-
process.exit(1);
|
|
378
|
-
}
|
|
379
|
-
|
|
325
|
+
async lookup(_context: unknown, entity: string, params: SearchParams = {}): Promise<void> {
|
|
380
326
|
try {
|
|
381
|
-
const result = await this.executeFunction(`lookup_${entity}`,
|
|
327
|
+
const result = await this.executeFunction(`lookup_${entity}`, params);
|
|
382
328
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
383
329
|
await this.cleanup();
|
|
384
330
|
} catch (error: any) {
|
|
@@ -390,28 +336,11 @@ export class DzqlNamespace {
|
|
|
390
336
|
|
|
391
337
|
/**
|
|
392
338
|
* Get subscribable snapshot
|
|
393
|
-
* @example
|
|
339
|
+
* @example invt dzql:subscribe venue_detail '{"venue_id": 1}'
|
|
394
340
|
*/
|
|
395
|
-
async subscribe(_context:
|
|
396
|
-
if (!name) {
|
|
397
|
-
console.error("Error: subscribable name required");
|
|
398
|
-
console.error("Usage: invj dzql:subscribe <name> '<json_args>'");
|
|
399
|
-
console.error('Example: invj dzql:subscribe venue_detail \'{"venue_id": 1}\'');
|
|
400
|
-
await this.cleanup();
|
|
401
|
-
process.exit(1);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
let args: any;
|
|
405
|
-
try {
|
|
406
|
-
args = JSON.parse(argsJson);
|
|
407
|
-
} catch {
|
|
408
|
-
console.error("Error: arguments must be valid JSON");
|
|
409
|
-
await this.cleanup();
|
|
410
|
-
process.exit(1);
|
|
411
|
-
}
|
|
412
|
-
|
|
341
|
+
async subscribe(_context: unknown, name: string, params: CallParams = {}): Promise<void> {
|
|
413
342
|
try {
|
|
414
|
-
const result = await this.executeFunction(`get_${name}`,
|
|
343
|
+
const result = await this.executeFunction(`get_${name}`, params);
|
|
415
344
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
416
345
|
await this.cleanup();
|
|
417
346
|
} catch (error: any) {
|
|
@@ -423,30 +352,12 @@ export class DzqlNamespace {
|
|
|
423
352
|
|
|
424
353
|
/**
|
|
425
354
|
* Call any function in the manifest by name
|
|
426
|
-
* @example
|
|
427
|
-
* @example
|
|
355
|
+
* @example invt dzql:call login_user '{"email": "test@example.com", "password": "secret"}'
|
|
356
|
+
* @example invt dzql:call get_venue_detail '{"venue_id": 1}'
|
|
428
357
|
*/
|
|
429
|
-
async call(_context:
|
|
430
|
-
if (!funcName) {
|
|
431
|
-
console.error("Error: function name required");
|
|
432
|
-
console.error("Usage: invj dzql:call <function_name> '<json_args>'");
|
|
433
|
-
console.error('Example: invj dzql:call login_user \'{"email": "test@example.com", "password": "secret"}\'');
|
|
434
|
-
console.error('Example: invj dzql:call get_venue_detail \'{"venue_id": 1}\'');
|
|
435
|
-
await this.cleanup();
|
|
436
|
-
process.exit(1);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
let args: any;
|
|
440
|
-
try {
|
|
441
|
-
args = JSON.parse(argsJson);
|
|
442
|
-
} catch {
|
|
443
|
-
console.error("Error: arguments must be valid JSON");
|
|
444
|
-
await this.cleanup();
|
|
445
|
-
process.exit(1);
|
|
446
|
-
}
|
|
447
|
-
|
|
358
|
+
async call(_context: unknown, funcName: string, params: CallParams = {}): Promise<void> {
|
|
448
359
|
try {
|
|
449
|
-
const result = await this.executeFunction(funcName,
|
|
360
|
+
const result = await this.executeFunction(funcName, params);
|
|
450
361
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
451
362
|
await this.cleanup();
|
|
452
363
|
} catch (error: any) {
|
|
@@ -458,9 +369,9 @@ export class DzqlNamespace {
|
|
|
458
369
|
|
|
459
370
|
/**
|
|
460
371
|
* List all available functions in the manifest
|
|
461
|
-
* @example
|
|
372
|
+
* @example invt dzql:functions
|
|
462
373
|
*/
|
|
463
|
-
async functions(_context
|
|
374
|
+
async functions(_context: unknown): Promise<void> {
|
|
464
375
|
try {
|
|
465
376
|
const { manifest } = await this.init();
|
|
466
377
|
const functions: Record<string, { args: string[]; returnType: string }> = {};
|