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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dzql",
3
- "version": "0.6.9",
3
+ "version": "0.6.10",
4
4
  "description": "Database-first real-time framework with TypeScript support",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,43 +1,42 @@
1
1
  /**
2
- * DZQL Namespace for invokej integration
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.js:
8
- * ```js
9
- * import { DzqlNamespace } from 'dzql/namespace';
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
- * constructor() {
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
- * invj dzql:entities # List all entities
22
- * invj dzql:subscribables # List all subscribables
23
- * invj dzql:functions # List all manifest functions
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
- * invj dzql:search venues '{"query": "test"}' # Search with filters
27
- * invj dzql:get venues '{"id": 1}' # Get by primary key
28
- * invj dzql:save venues '{"name": "New", "org_id": 1}' # Create (no id)
29
- * invj dzql:save venues '{"id": 1, "name": "Updated"}' # Update (with id)
30
- * invj dzql:delete venues '{"id": 1}' # Delete by primary key
31
- * invj dzql:lookup venues '{"query": "test"}' # Lookup for dropdowns
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
- * invj dzql:subscribe venue_detail '{"venue_id": 1}' # Get snapshot
33
+ * invt dzql:subscribe venue_detail '{"venue_id": 1}' # Get snapshot
35
34
  *
36
35
  * Ad-hoc Function Calls:
37
- * invj dzql:call login_user '{"email": "x", "password": "y"}'
38
- * invj dzql:call register_user '{"email": "x", "password": "y"}'
39
- * invj dzql:call get_venue_detail '{"venue_id": 1}'
40
- * invj dzql:call save_venues '{"name": "Test", "org_id": 1}'
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 invokej
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?: any): Promise<void> {
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?: any): Promise<void> {
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 invj dzql:search venues '{"query": "test"}'
259
+ * @example invt dzql:search venues '{"query": "test"}'
229
260
  */
230
- async search(_context: any, entity?: string, argsJson: string = "{}"): Promise<void> {
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
- 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
-
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 invj dzql:get venues '{"id": 1}'
275
+ * @example invt dzql:get venues '{"id": 1}'
262
276
  */
263
- async get(_context: any, entity?: string, argsJson: string = "{}"): Promise<void> {
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}`, args);
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 invj dzql:save venues '{"name": "New Venue", "org_id": 1}'
291
+ * @example invt dzql:save venues '{"name": "New Venue", "org_id": 1}'
295
292
  */
296
- async save(_context: any, entity?: string, argsJson: string = "{}"): Promise<void> {
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}`, args);
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 invj dzql:delete venues '{"id": 1}'
307
+ * @example invt dzql:delete venues '{"id": 1}'
328
308
  */
329
- async delete(_context: any, entity?: string, argsJson: string = "{}"): Promise<void> {
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}`, args);
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 invj dzql:lookup organisations '{"query": "acme"}'
323
+ * @example invt dzql:lookup organisations '{"query": "acme"}'
361
324
  */
362
- async lookup(_context: any, entity?: string, argsJson: string = "{}"): Promise<void> {
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}`, args);
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 invj dzql:subscribe venue_detail '{"venue_id": 1}'
339
+ * @example invt dzql:subscribe venue_detail '{"venue_id": 1}'
394
340
  */
395
- async subscribe(_context: any, name?: string, argsJson: string = "{}"): Promise<void> {
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}`, args);
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 invj dzql:call login_user '{"email": "test@example.com", "password": "secret"}'
427
- * @example invj dzql:call get_venue_detail '{"venue_id": 1}'
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: any, funcName?: string, argsJson: string = "{}"): Promise<void> {
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, args);
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 invj dzql:functions
372
+ * @example invt dzql:functions
462
373
  */
463
- async functions(_context?: any): Promise<void> {
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 }> = {};