@objectstack/objectql 2.0.4 → 2.0.5

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @objectstack/objectql@2.0.4 build /home/runner/work/spec/spec/packages/objectql
2
+ > @objectstack/objectql@2.0.5 build /home/runner/work/spec/spec/packages/objectql
3
3
  > tsup --config ../../tsup.config.ts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -10,13 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  CJS Build start
13
- CJS dist/index.js 62.77 KB
14
- CJS dist/index.js.map 126.84 KB
15
- CJS ⚡️ Build success in 81ms
16
- ESM dist/index.mjs 61.35 KB
17
- ESM dist/index.mjs.map 126.13 KB
18
- ESM ⚡️ Build success in 94ms
13
+ ESM dist/index.mjs 71.78 KB
14
+ ESM dist/index.mjs.map 145.78 KB
15
+ ESM ⚡️ Build success in 150ms
16
+ CJS dist/index.js 73.33 KB
17
+ CJS dist/index.js.map 146.65 KB
18
+ CJS ⚡️ Build success in 161ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 12002ms
21
- DTS dist/index.d.mts 66.66 KB
22
- DTS dist/index.d.ts 66.66 KB
20
+ DTS ⚡️ Build success in 13396ms
21
+ DTS dist/index.d.mts 70.72 KB
22
+ DTS dist/index.d.ts 70.72 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @objectstack/objectql
2
2
 
3
+ ## 2.0.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @objectstack/spec@2.0.5
9
+ - @objectstack/core@2.0.5
10
+ - @objectstack/types@2.0.5
11
+
3
12
  ## 2.0.4
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import * as _objectstack_spec_data from '@objectstack/spec/data';
3
- import { ServiceObject, ObjectOwnership, HookContext, DataEngineQueryOptions, DataEngineInsertOptions, DataEngineUpdateOptions, DataEngineDeleteOptions, DataEngineCountOptions, DataEngineAggregateOptions } from '@objectstack/spec/data';
4
- import { ObjectStackManifest, InstalledPackage } from '@objectstack/spec/kernel';
3
+ import { ServiceObject, ObjectOwnership, HookContext, QueryAST, DataEngineQueryOptions, DataEngineInsertOptions, DataEngineUpdateOptions, DataEngineDeleteOptions, DataEngineCountOptions, DataEngineAggregateOptions } from '@objectstack/spec/data';
4
+ import { ObjectStackManifest, InstalledPackage, ExecutionContext } from '@objectstack/spec/kernel';
5
5
  import { ObjectStackProtocol, MetadataCacheRequest, MetadataCacheResponse, BatchUpdateRequest, BatchUpdateResponse, UpdateManyDataRequest, DeleteManyDataRequest } from '@objectstack/spec/api';
6
6
  import { IDataEngine, DriverInterface, Logger, Plugin, PluginContext } from '@objectstack/core';
7
7
 
@@ -1290,6 +1290,30 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
1290
1290
  }
1291
1291
 
1292
1292
  type HookHandler = (context: HookContext) => Promise<void> | void;
1293
+ /**
1294
+ * Per-object hook entry with priority support
1295
+ */
1296
+ interface HookEntry {
1297
+ handler: HookHandler;
1298
+ object?: string | string[];
1299
+ priority: number;
1300
+ }
1301
+ /**
1302
+ * Operation Context for Middleware Chain
1303
+ */
1304
+ interface OperationContext {
1305
+ object: string;
1306
+ operation: 'find' | 'findOne' | 'insert' | 'update' | 'delete' | 'count' | 'aggregate';
1307
+ ast?: QueryAST;
1308
+ data?: any;
1309
+ options?: any;
1310
+ context?: ExecutionContext;
1311
+ result?: any;
1312
+ }
1313
+ /**
1314
+ * Engine Middleware (Onion model)
1315
+ */
1316
+ type EngineMiddleware = (ctx: OperationContext, next: () => Promise<void>) => Promise<void>;
1293
1317
  /**
1294
1318
  * Host Context provided to plugins (Internal ObjectQL Plugin System)
1295
1319
  */
@@ -1311,6 +1335,7 @@ declare class ObjectQL implements IDataEngine {
1311
1335
  private defaultDriver;
1312
1336
  private logger;
1313
1337
  private hooks;
1338
+ private middlewares;
1314
1339
  private hostContext;
1315
1340
  constructor(hostContext?: Record<string, any>);
1316
1341
  /**
@@ -1335,9 +1360,30 @@ declare class ObjectQL implements IDataEngine {
1335
1360
  * Register a hook
1336
1361
  * @param event The event name (e.g. 'beforeFind', 'afterInsert')
1337
1362
  * @param handler The handler function
1363
+ * @param options Optional: target object(s) and priority
1338
1364
  */
1339
- registerHook(event: string, handler: HookHandler): void;
1365
+ registerHook(event: string, handler: HookHandler, options?: {
1366
+ object?: string | string[];
1367
+ priority?: number;
1368
+ }): void;
1340
1369
  triggerHooks(event: string, context: HookContext): Promise<void>;
1370
+ /**
1371
+ * Register a middleware function
1372
+ * Middlewares execute in onion model around every data operation.
1373
+ * @param fn The middleware function
1374
+ * @param options Optional: target object filter
1375
+ */
1376
+ registerMiddleware(fn: EngineMiddleware, options?: {
1377
+ object?: string;
1378
+ }): void;
1379
+ /**
1380
+ * Execute an operation through the middleware chain
1381
+ */
1382
+ private executeWithMiddleware;
1383
+ /**
1384
+ * Build a HookContext.session from ExecutionContext
1385
+ */
1386
+ private buildSession;
1341
1387
  /**
1342
1388
  * Register contribution (Manifest)
1343
1389
  *
@@ -1653,6 +1699,87 @@ declare class ObjectQL implements IDataEngine {
1653
1699
  count(object: string, query?: DataEngineCountOptions): Promise<number>;
1654
1700
  aggregate(object: string, query: DataEngineAggregateOptions): Promise<any[]>;
1655
1701
  execute(command: any, options?: Record<string, any>): Promise<any>;
1702
+ /**
1703
+ * Create a scoped execution context bound to this engine.
1704
+ *
1705
+ * Usage:
1706
+ * const ctx = engine.createContext({ userId: '...', tenantId: '...' });
1707
+ * const users = ctx.object('user');
1708
+ * await users.find({ filter: { status: 'active' } });
1709
+ */
1710
+ createContext(ctx: Partial<ExecutionContext>): ScopedContext;
1711
+ }
1712
+ /**
1713
+ * Repository scoped to a single object, bound to an execution context.
1714
+ */
1715
+ declare class ObjectRepository {
1716
+ private objectName;
1717
+ private context;
1718
+ private engine;
1719
+ constructor(objectName: string, context: ExecutionContext, engine: IDataEngine);
1720
+ find(query?: any): Promise<any[]>;
1721
+ findOne(query?: any): Promise<any>;
1722
+ insert(data: any): Promise<any>;
1723
+ update(data: any, options?: any): Promise<any>;
1724
+ delete(options?: any): Promise<any>;
1725
+ count(query?: any): Promise<number>;
1726
+ }
1727
+ /**
1728
+ * Scoped execution context with object() accessor.
1729
+ */
1730
+ declare class ScopedContext {
1731
+ private executionContext;
1732
+ private engine;
1733
+ constructor(executionContext: ExecutionContext, engine: IDataEngine);
1734
+ /** Get a repository scoped to this context */
1735
+ object(name: string): ObjectRepository;
1736
+ /** Create an elevated (system) context */
1737
+ sudo(): ScopedContext;
1738
+ get userId(): string | undefined;
1739
+ get tenantId(): string | undefined;
1740
+ get roles(): string[];
1741
+ }
1742
+
1743
+ /**
1744
+ * MetadataFacade
1745
+ *
1746
+ * Provides a clean, injectable interface over SchemaRegistry.
1747
+ * Registered as the 'metadata' kernel service to eliminate
1748
+ * downstream packages needing to manually wrap SchemaRegistry.
1749
+ */
1750
+ declare class MetadataFacade {
1751
+ /**
1752
+ * Register a metadata item
1753
+ */
1754
+ register(type: string, definition: any): void;
1755
+ /**
1756
+ * Get a metadata item by type and name
1757
+ */
1758
+ get(type: string, name: string): any;
1759
+ /**
1760
+ * Get the raw entry (with metadata wrapper)
1761
+ */
1762
+ getEntry(type: string, name: string): any;
1763
+ /**
1764
+ * List all items of a type
1765
+ */
1766
+ list(type: string): any[];
1767
+ /**
1768
+ * Unregister a metadata item
1769
+ */
1770
+ unregister(type: string, name: string): void;
1771
+ /**
1772
+ * Unregister all metadata from a package
1773
+ */
1774
+ unregisterPackage(packageName: string): void;
1775
+ /**
1776
+ * Convenience: get object definition
1777
+ */
1778
+ getObject(name: string): any;
1779
+ /**
1780
+ * Convenience: list all objects
1781
+ */
1782
+ listObjects(): any[];
1656
1783
  }
1657
1784
 
1658
1785
  declare class ObjectQLPlugin implements Plugin {
@@ -1664,6 +1791,16 @@ declare class ObjectQLPlugin implements Plugin {
1664
1791
  constructor(ql?: ObjectQL, hostContext?: Record<string, any>);
1665
1792
  init: (ctx: PluginContext) => Promise<void>;
1666
1793
  start: (ctx: PluginContext) => Promise<void>;
1794
+ /**
1795
+ * Register built-in audit hooks for auto-stamping createdBy/modifiedBy
1796
+ * and fetching previousData for update/delete operations.
1797
+ */
1798
+ private registerAuditHooks;
1799
+ /**
1800
+ * Register tenant isolation middleware that auto-injects space_id filter
1801
+ * for multi-tenant operations.
1802
+ */
1803
+ private registerTenantMiddleware;
1667
1804
  /**
1668
1805
  * Load metadata from external metadata service into ObjectQL registry
1669
1806
  * This enables ObjectQL to use file-based or remote metadata
@@ -1671,4 +1808,4 @@ declare class ObjectQLPlugin implements Plugin {
1671
1808
  private loadMetadataFromService;
1672
1809
  }
1673
1810
 
1674
- export { DEFAULT_EXTENDER_PRIORITY, DEFAULT_OWNER_PRIORITY, type HookHandler, type ObjectContributor, ObjectQL, type ObjectQLHostContext, ObjectQLPlugin, ObjectStackProtocolImplementation, RESERVED_NAMESPACES, SchemaRegistry, computeFQN, parseFQN };
1811
+ export { DEFAULT_EXTENDER_PRIORITY, DEFAULT_OWNER_PRIORITY, type EngineMiddleware, type HookEntry, type HookHandler, MetadataFacade, type ObjectContributor, ObjectQL, type ObjectQLHostContext, ObjectQLPlugin, ObjectRepository, ObjectStackProtocolImplementation, type OperationContext, RESERVED_NAMESPACES, SchemaRegistry, ScopedContext, computeFQN, parseFQN };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import * as _objectstack_spec_data from '@objectstack/spec/data';
3
- import { ServiceObject, ObjectOwnership, HookContext, DataEngineQueryOptions, DataEngineInsertOptions, DataEngineUpdateOptions, DataEngineDeleteOptions, DataEngineCountOptions, DataEngineAggregateOptions } from '@objectstack/spec/data';
4
- import { ObjectStackManifest, InstalledPackage } from '@objectstack/spec/kernel';
3
+ import { ServiceObject, ObjectOwnership, HookContext, QueryAST, DataEngineQueryOptions, DataEngineInsertOptions, DataEngineUpdateOptions, DataEngineDeleteOptions, DataEngineCountOptions, DataEngineAggregateOptions } from '@objectstack/spec/data';
4
+ import { ObjectStackManifest, InstalledPackage, ExecutionContext } from '@objectstack/spec/kernel';
5
5
  import { ObjectStackProtocol, MetadataCacheRequest, MetadataCacheResponse, BatchUpdateRequest, BatchUpdateResponse, UpdateManyDataRequest, DeleteManyDataRequest } from '@objectstack/spec/api';
6
6
  import { IDataEngine, DriverInterface, Logger, Plugin, PluginContext } from '@objectstack/core';
7
7
 
@@ -1290,6 +1290,30 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
1290
1290
  }
1291
1291
 
1292
1292
  type HookHandler = (context: HookContext) => Promise<void> | void;
1293
+ /**
1294
+ * Per-object hook entry with priority support
1295
+ */
1296
+ interface HookEntry {
1297
+ handler: HookHandler;
1298
+ object?: string | string[];
1299
+ priority: number;
1300
+ }
1301
+ /**
1302
+ * Operation Context for Middleware Chain
1303
+ */
1304
+ interface OperationContext {
1305
+ object: string;
1306
+ operation: 'find' | 'findOne' | 'insert' | 'update' | 'delete' | 'count' | 'aggregate';
1307
+ ast?: QueryAST;
1308
+ data?: any;
1309
+ options?: any;
1310
+ context?: ExecutionContext;
1311
+ result?: any;
1312
+ }
1313
+ /**
1314
+ * Engine Middleware (Onion model)
1315
+ */
1316
+ type EngineMiddleware = (ctx: OperationContext, next: () => Promise<void>) => Promise<void>;
1293
1317
  /**
1294
1318
  * Host Context provided to plugins (Internal ObjectQL Plugin System)
1295
1319
  */
@@ -1311,6 +1335,7 @@ declare class ObjectQL implements IDataEngine {
1311
1335
  private defaultDriver;
1312
1336
  private logger;
1313
1337
  private hooks;
1338
+ private middlewares;
1314
1339
  private hostContext;
1315
1340
  constructor(hostContext?: Record<string, any>);
1316
1341
  /**
@@ -1335,9 +1360,30 @@ declare class ObjectQL implements IDataEngine {
1335
1360
  * Register a hook
1336
1361
  * @param event The event name (e.g. 'beforeFind', 'afterInsert')
1337
1362
  * @param handler The handler function
1363
+ * @param options Optional: target object(s) and priority
1338
1364
  */
1339
- registerHook(event: string, handler: HookHandler): void;
1365
+ registerHook(event: string, handler: HookHandler, options?: {
1366
+ object?: string | string[];
1367
+ priority?: number;
1368
+ }): void;
1340
1369
  triggerHooks(event: string, context: HookContext): Promise<void>;
1370
+ /**
1371
+ * Register a middleware function
1372
+ * Middlewares execute in onion model around every data operation.
1373
+ * @param fn The middleware function
1374
+ * @param options Optional: target object filter
1375
+ */
1376
+ registerMiddleware(fn: EngineMiddleware, options?: {
1377
+ object?: string;
1378
+ }): void;
1379
+ /**
1380
+ * Execute an operation through the middleware chain
1381
+ */
1382
+ private executeWithMiddleware;
1383
+ /**
1384
+ * Build a HookContext.session from ExecutionContext
1385
+ */
1386
+ private buildSession;
1341
1387
  /**
1342
1388
  * Register contribution (Manifest)
1343
1389
  *
@@ -1653,6 +1699,87 @@ declare class ObjectQL implements IDataEngine {
1653
1699
  count(object: string, query?: DataEngineCountOptions): Promise<number>;
1654
1700
  aggregate(object: string, query: DataEngineAggregateOptions): Promise<any[]>;
1655
1701
  execute(command: any, options?: Record<string, any>): Promise<any>;
1702
+ /**
1703
+ * Create a scoped execution context bound to this engine.
1704
+ *
1705
+ * Usage:
1706
+ * const ctx = engine.createContext({ userId: '...', tenantId: '...' });
1707
+ * const users = ctx.object('user');
1708
+ * await users.find({ filter: { status: 'active' } });
1709
+ */
1710
+ createContext(ctx: Partial<ExecutionContext>): ScopedContext;
1711
+ }
1712
+ /**
1713
+ * Repository scoped to a single object, bound to an execution context.
1714
+ */
1715
+ declare class ObjectRepository {
1716
+ private objectName;
1717
+ private context;
1718
+ private engine;
1719
+ constructor(objectName: string, context: ExecutionContext, engine: IDataEngine);
1720
+ find(query?: any): Promise<any[]>;
1721
+ findOne(query?: any): Promise<any>;
1722
+ insert(data: any): Promise<any>;
1723
+ update(data: any, options?: any): Promise<any>;
1724
+ delete(options?: any): Promise<any>;
1725
+ count(query?: any): Promise<number>;
1726
+ }
1727
+ /**
1728
+ * Scoped execution context with object() accessor.
1729
+ */
1730
+ declare class ScopedContext {
1731
+ private executionContext;
1732
+ private engine;
1733
+ constructor(executionContext: ExecutionContext, engine: IDataEngine);
1734
+ /** Get a repository scoped to this context */
1735
+ object(name: string): ObjectRepository;
1736
+ /** Create an elevated (system) context */
1737
+ sudo(): ScopedContext;
1738
+ get userId(): string | undefined;
1739
+ get tenantId(): string | undefined;
1740
+ get roles(): string[];
1741
+ }
1742
+
1743
+ /**
1744
+ * MetadataFacade
1745
+ *
1746
+ * Provides a clean, injectable interface over SchemaRegistry.
1747
+ * Registered as the 'metadata' kernel service to eliminate
1748
+ * downstream packages needing to manually wrap SchemaRegistry.
1749
+ */
1750
+ declare class MetadataFacade {
1751
+ /**
1752
+ * Register a metadata item
1753
+ */
1754
+ register(type: string, definition: any): void;
1755
+ /**
1756
+ * Get a metadata item by type and name
1757
+ */
1758
+ get(type: string, name: string): any;
1759
+ /**
1760
+ * Get the raw entry (with metadata wrapper)
1761
+ */
1762
+ getEntry(type: string, name: string): any;
1763
+ /**
1764
+ * List all items of a type
1765
+ */
1766
+ list(type: string): any[];
1767
+ /**
1768
+ * Unregister a metadata item
1769
+ */
1770
+ unregister(type: string, name: string): void;
1771
+ /**
1772
+ * Unregister all metadata from a package
1773
+ */
1774
+ unregisterPackage(packageName: string): void;
1775
+ /**
1776
+ * Convenience: get object definition
1777
+ */
1778
+ getObject(name: string): any;
1779
+ /**
1780
+ * Convenience: list all objects
1781
+ */
1782
+ listObjects(): any[];
1656
1783
  }
1657
1784
 
1658
1785
  declare class ObjectQLPlugin implements Plugin {
@@ -1664,6 +1791,16 @@ declare class ObjectQLPlugin implements Plugin {
1664
1791
  constructor(ql?: ObjectQL, hostContext?: Record<string, any>);
1665
1792
  init: (ctx: PluginContext) => Promise<void>;
1666
1793
  start: (ctx: PluginContext) => Promise<void>;
1794
+ /**
1795
+ * Register built-in audit hooks for auto-stamping createdBy/modifiedBy
1796
+ * and fetching previousData for update/delete operations.
1797
+ */
1798
+ private registerAuditHooks;
1799
+ /**
1800
+ * Register tenant isolation middleware that auto-injects space_id filter
1801
+ * for multi-tenant operations.
1802
+ */
1803
+ private registerTenantMiddleware;
1667
1804
  /**
1668
1805
  * Load metadata from external metadata service into ObjectQL registry
1669
1806
  * This enables ObjectQL to use file-based or remote metadata
@@ -1671,4 +1808,4 @@ declare class ObjectQLPlugin implements Plugin {
1671
1808
  private loadMetadataFromService;
1672
1809
  }
1673
1810
 
1674
- export { DEFAULT_EXTENDER_PRIORITY, DEFAULT_OWNER_PRIORITY, type HookHandler, type ObjectContributor, ObjectQL, type ObjectQLHostContext, ObjectQLPlugin, ObjectStackProtocolImplementation, RESERVED_NAMESPACES, SchemaRegistry, computeFQN, parseFQN };
1811
+ export { DEFAULT_EXTENDER_PRIORITY, DEFAULT_OWNER_PRIORITY, type EngineMiddleware, type HookEntry, type HookHandler, MetadataFacade, type ObjectContributor, ObjectQL, type ObjectQLHostContext, ObjectQLPlugin, ObjectRepository, ObjectStackProtocolImplementation, type OperationContext, RESERVED_NAMESPACES, SchemaRegistry, ScopedContext, computeFQN, parseFQN };