dzql 0.6.9 → 0.6.11
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 +85 -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,33 @@ 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
|
+
/** Context interface compatible with invoket - kept minimal to avoid dependency */
|
|
57
|
+
export interface Context {
|
|
58
|
+
cwd: string;
|
|
59
|
+
run(command: string, options?: { echo?: boolean }): Promise<unknown>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Query parameters for search operations */
|
|
63
|
+
export interface SearchParams {
|
|
64
|
+
query?: string;
|
|
65
|
+
filters?: Record<string, unknown>;
|
|
66
|
+
sort_field?: string;
|
|
67
|
+
sort_order?: "asc" | "desc";
|
|
68
|
+
limit?: number;
|
|
69
|
+
offset?: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Primary key for get/delete operations */
|
|
73
|
+
export interface PkParams {
|
|
74
|
+
id?: number;
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Generic params for any operation */
|
|
79
|
+
export interface CallParams {
|
|
80
|
+
[key: string]: unknown;
|
|
81
|
+
}
|
|
82
|
+
|
|
57
83
|
/**
|
|
58
84
|
* Load manifest from MANIFEST_PATH env var or default locations
|
|
59
85
|
*/
|
|
@@ -122,7 +148,16 @@ function discoverSubscribables(manifest: Manifest): Record<string, { params: Rec
|
|
|
122
148
|
}
|
|
123
149
|
|
|
124
150
|
/**
|
|
125
|
-
* DZQL operations namespace for
|
|
151
|
+
* DZQL operations namespace for invoket
|
|
152
|
+
*
|
|
153
|
+
* Use with invoket task runner:
|
|
154
|
+
* ```ts
|
|
155
|
+
* import { DzqlNamespace } from "dzql/namespace";
|
|
156
|
+
*
|
|
157
|
+
* export class Tasks {
|
|
158
|
+
* dzql = new DzqlNamespace();
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
126
161
|
*/
|
|
127
162
|
export class DzqlNamespace {
|
|
128
163
|
private userId: number;
|
|
@@ -193,8 +228,9 @@ export class DzqlNamespace {
|
|
|
193
228
|
|
|
194
229
|
/**
|
|
195
230
|
* List all available entities
|
|
231
|
+
* @example invt dzql:entities
|
|
196
232
|
*/
|
|
197
|
-
async entities(
|
|
233
|
+
async entities(c: Context): Promise<void> {
|
|
198
234
|
try {
|
|
199
235
|
const { manifest } = await this.init();
|
|
200
236
|
const entities = discoverEntities(manifest);
|
|
@@ -209,8 +245,9 @@ export class DzqlNamespace {
|
|
|
209
245
|
|
|
210
246
|
/**
|
|
211
247
|
* List all available subscribables
|
|
248
|
+
* @example invt dzql:subscribables
|
|
212
249
|
*/
|
|
213
|
-
async subscribables(
|
|
250
|
+
async subscribables(c: Context): Promise<void> {
|
|
214
251
|
try {
|
|
215
252
|
const { manifest } = await this.init();
|
|
216
253
|
const subscribables = discoverSubscribables(manifest);
|
|
@@ -225,28 +262,11 @@ export class DzqlNamespace {
|
|
|
225
262
|
|
|
226
263
|
/**
|
|
227
264
|
* Search an entity
|
|
228
|
-
* @example
|
|
265
|
+
* @example invt dzql:search venues '{"query": "test"}'
|
|
229
266
|
*/
|
|
230
|
-
async search(
|
|
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;
|
|
240
|
-
try {
|
|
241
|
-
args = JSON.parse(argsJson);
|
|
242
|
-
} catch {
|
|
243
|
-
console.error("Error: arguments must be valid JSON");
|
|
244
|
-
await this.cleanup();
|
|
245
|
-
process.exit(1);
|
|
246
|
-
}
|
|
247
|
-
|
|
267
|
+
async search(c: Context, entity: string, params: SearchParams = {}): Promise<void> {
|
|
248
268
|
try {
|
|
249
|
-
const result = await this.executeFunction(`search_${entity}`,
|
|
269
|
+
const result = await this.executeFunction(`search_${entity}`, params);
|
|
250
270
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
251
271
|
await this.cleanup();
|
|
252
272
|
} catch (error: any) {
|
|
@@ -258,28 +278,11 @@ export class DzqlNamespace {
|
|
|
258
278
|
|
|
259
279
|
/**
|
|
260
280
|
* Get entity by ID
|
|
261
|
-
* @example
|
|
281
|
+
* @example invt dzql:get venues '{"id": 1}'
|
|
262
282
|
*/
|
|
263
|
-
async get(
|
|
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;
|
|
283
|
+
async get(c: Context, entity: string, pk: PkParams): Promise<void> {
|
|
273
284
|
try {
|
|
274
|
-
|
|
275
|
-
} catch {
|
|
276
|
-
console.error("Error: arguments must be valid JSON");
|
|
277
|
-
await this.cleanup();
|
|
278
|
-
process.exit(1);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
try {
|
|
282
|
-
const result = await this.executeFunction(`get_${entity}`, args);
|
|
285
|
+
const result = await this.executeFunction(`get_${entity}`, pk);
|
|
283
286
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
284
287
|
await this.cleanup();
|
|
285
288
|
} catch (error: any) {
|
|
@@ -291,28 +294,11 @@ export class DzqlNamespace {
|
|
|
291
294
|
|
|
292
295
|
/**
|
|
293
296
|
* Save (create or update) entity
|
|
294
|
-
* @example
|
|
297
|
+
* @example invt dzql:save venues '{"name": "New Venue", "org_id": 1}'
|
|
295
298
|
*/
|
|
296
|
-
async save(
|
|
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
|
-
|
|
299
|
+
async save(c: Context, entity: string, data: CallParams): Promise<void> {
|
|
314
300
|
try {
|
|
315
|
-
const result = await this.executeFunction(`save_${entity}`,
|
|
301
|
+
const result = await this.executeFunction(`save_${entity}`, data);
|
|
316
302
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
317
303
|
await this.cleanup();
|
|
318
304
|
} catch (error: any) {
|
|
@@ -324,28 +310,11 @@ export class DzqlNamespace {
|
|
|
324
310
|
|
|
325
311
|
/**
|
|
326
312
|
* Delete entity by ID
|
|
327
|
-
* @example
|
|
313
|
+
* @example invt dzql:delete venues '{"id": 1}'
|
|
328
314
|
*/
|
|
329
|
-
async delete(
|
|
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;
|
|
315
|
+
async delete(c: Context, entity: string, pk: PkParams): Promise<void> {
|
|
339
316
|
try {
|
|
340
|
-
|
|
341
|
-
} catch {
|
|
342
|
-
console.error("Error: arguments must be valid JSON");
|
|
343
|
-
await this.cleanup();
|
|
344
|
-
process.exit(1);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
try {
|
|
348
|
-
const result = await this.executeFunction(`delete_${entity}`, args);
|
|
317
|
+
const result = await this.executeFunction(`delete_${entity}`, pk);
|
|
349
318
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
350
319
|
await this.cleanup();
|
|
351
320
|
} catch (error: any) {
|
|
@@ -357,28 +326,11 @@ export class DzqlNamespace {
|
|
|
357
326
|
|
|
358
327
|
/**
|
|
359
328
|
* Lookup entity (for dropdowns/autocomplete)
|
|
360
|
-
* @example
|
|
329
|
+
* @example invt dzql:lookup organisations '{"query": "acme"}'
|
|
361
330
|
*/
|
|
362
|
-
async lookup(
|
|
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
|
-
|
|
331
|
+
async lookup(c: Context, entity: string, params: SearchParams = {}): Promise<void> {
|
|
380
332
|
try {
|
|
381
|
-
const result = await this.executeFunction(`lookup_${entity}`,
|
|
333
|
+
const result = await this.executeFunction(`lookup_${entity}`, params);
|
|
382
334
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
383
335
|
await this.cleanup();
|
|
384
336
|
} catch (error: any) {
|
|
@@ -390,28 +342,11 @@ export class DzqlNamespace {
|
|
|
390
342
|
|
|
391
343
|
/**
|
|
392
344
|
* Get subscribable snapshot
|
|
393
|
-
* @example
|
|
345
|
+
* @example invt dzql:subscribe venue_detail '{"venue_id": 1}'
|
|
394
346
|
*/
|
|
395
|
-
async subscribe(
|
|
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
|
-
|
|
347
|
+
async subscribe(c: Context, name: string, params: CallParams = {}): Promise<void> {
|
|
413
348
|
try {
|
|
414
|
-
const result = await this.executeFunction(`get_${name}`,
|
|
349
|
+
const result = await this.executeFunction(`get_${name}`, params);
|
|
415
350
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
416
351
|
await this.cleanup();
|
|
417
352
|
} catch (error: any) {
|
|
@@ -423,30 +358,12 @@ export class DzqlNamespace {
|
|
|
423
358
|
|
|
424
359
|
/**
|
|
425
360
|
* Call any function in the manifest by name
|
|
426
|
-
* @example
|
|
427
|
-
* @example
|
|
361
|
+
* @example invt dzql:call login_user '{"email": "test@example.com", "password": "secret"}'
|
|
362
|
+
* @example invt dzql:call get_venue_detail '{"venue_id": 1}'
|
|
428
363
|
*/
|
|
429
|
-
async call(
|
|
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
|
-
|
|
364
|
+
async call(c: Context, funcName: string, params: CallParams = {}): Promise<void> {
|
|
448
365
|
try {
|
|
449
|
-
const result = await this.executeFunction(funcName,
|
|
366
|
+
const result = await this.executeFunction(funcName, params);
|
|
450
367
|
console.log(JSON.stringify({ success: true, result }, null, 2));
|
|
451
368
|
await this.cleanup();
|
|
452
369
|
} catch (error: any) {
|
|
@@ -458,9 +375,9 @@ export class DzqlNamespace {
|
|
|
458
375
|
|
|
459
376
|
/**
|
|
460
377
|
* List all available functions in the manifest
|
|
461
|
-
* @example
|
|
378
|
+
* @example invt dzql:functions
|
|
462
379
|
*/
|
|
463
|
-
async functions(
|
|
380
|
+
async functions(c: Context): Promise<void> {
|
|
464
381
|
try {
|
|
465
382
|
const { manifest } = await this.init();
|
|
466
383
|
const functions: Record<string, { args: string[]; returnType: string }> = {};
|