@objectql/types 4.0.1 → 4.0.3

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/README.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # @objectql/types
2
2
 
3
+ > **Implementation Status**: ✅ **Complete** - All type definitions available. See [Implementation Status](https://github.com/objectstack-ai/objectql/blob/main/IMPLEMENTATION_STATUS.md) for runtime implementation details.
4
+
3
5
  Type definitions for the ObjectQL system, including object schemas, field configurations, validation rules, queries, hooks, and actions.
4
6
 
7
+ > **Note**: This package defines the type system. Some types (like permissions and workflows) are defined but require application-layer implementation. See the implementation status document for details.
8
+
5
9
  ## Features
6
10
 
7
11
  - **Object & Field Types**: Define data models with `ObjectConfig` and `FieldConfig`
package/dist/api.d.ts CHANGED
@@ -96,16 +96,22 @@ export interface DataApiListResponse<T = unknown> extends DataApiResponse<T> {
96
96
  }
97
97
  /**
98
98
  * Response for single item operations (findOne, create, update)
99
+ * Single item operations wrap the data in a 'data' field
99
100
  */
100
101
  export interface DataApiItemResponse<T = unknown> extends DataApiResponse<T> {
101
- /** The item ID */
102
- _id?: string | number;
103
- /** Object type identifier */
104
- '@type'?: string;
105
- /** Timestamp when created */
106
- created_at?: string | Date;
107
- /** Timestamp when last updated */
108
- updated_at?: string | Date;
102
+ /** The returned item data */
103
+ data?: T & {
104
+ /** The item ID */
105
+ _id?: string | number;
106
+ /** Object type identifier */
107
+ '@type'?: string;
108
+ /** Timestamp when created */
109
+ created_at?: string | Date;
110
+ /** Timestamp when last updated */
111
+ updated_at?: string | Date;
112
+ /** Additional item fields */
113
+ [key: string]: unknown;
114
+ };
109
115
  }
110
116
  /**
111
117
  * Query parameters for GET /api/data/:object (list records)
package/dist/api.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAujBH,4CASC;AAljBD,+EAA+E;AAC/E,uBAAuB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gBAAgB,CAAC,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;CACJ;AAhBD,sCAgBC;AAqeD;;GAEG;AACU,QAAA,kBAAkB,GAA2B;IACtD,GAAG,EAAE,eAAe;IACpB,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,YAAY;CACtB,CAAC;AAEF;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,MAAuB;;IACpD,MAAM,aAAa,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;IAEzF,OAAO;QACH,GAAG,EAAE,aAAa,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,mCAAI,0BAAkB,CAAC,GAAG,CAAC;QACzD,IAAI,EAAE,aAAa,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,mCAAI,0BAAkB,CAAC,IAAI,CAAC;QAC5D,QAAQ,EAAE,aAAa,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,QAAQ,mCAAI,0BAAkB,CAAC,QAAQ,CAAC;QACxE,KAAK,EAAE,aAAa,CAAC,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,mCAAI,0BAAkB,CAAC,KAAK,CAAC;KAClE,CAAC;AACN,CAAC"}
package/dist/app.d.ts CHANGED
@@ -24,8 +24,8 @@ export interface IObjectQL {
24
24
  registerAction(objectName: string, actionName: string, handler: ActionHandler): void;
25
25
  executeAction(objectName: string, actionName: string, ctx: ActionContext): Promise<any>;
26
26
  /**
27
- * Get the underlying ObjectStackKernel instance
28
- * @returns The ObjectStackKernel instance
27
+ * Get the underlying ObjectKernel instance
28
+ * @returns The ObjectKernel instance
29
29
  */
30
30
  getKernel(): any;
31
31
  }
package/dist/config.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  import { MetadataRegistry } from "./registry";
9
9
  import { Driver } from "./driver";
10
10
  import { ObjectConfig } from "./object";
11
- import type { RuntimePlugin } from "../../../objectstack/runtime/dist";
11
+ import type { RuntimePlugin } from "./plugin";
12
12
  export interface ObjectQLConfig {
13
13
  registry?: MetadataRegistry;
14
14
  datasources?: Record<string, Driver>;
@@ -37,7 +37,7 @@ export interface ObjectQLConfig {
37
37
  modules?: string[];
38
38
  /**
39
39
  * List of plugins to load.
40
- * Must implement the RuntimePlugin interface from @objectql/runtime.
40
+ * Must implement the RuntimePlugin interface.
41
41
  * String plugins (package names) are not supported in core.
42
42
  */
43
43
  plugins?: (RuntimePlugin | string)[];
package/dist/field.d.ts CHANGED
@@ -104,9 +104,9 @@ export interface FieldOption {
104
104
  * - `deleteBehavior`: Made optional with protocol-compatible enum values
105
105
  *
106
106
  * All other protocol properties (description, defaultValue, maxLength, minLength, precision, scale, min, max,
107
- * reference, referenceFilters, writeRequiresMasterRead, expression, formula, summaryOperations) are inherited as-is.
107
+ * reference, referenceFilters, writeRequiresMasterRead, expression, summaryOperations) are inherited as-is.
108
108
  */
109
- export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'options' | 'required' | 'multiple' | 'unique' | 'deleteBehavior' | 'hidden' | 'readonly' | 'encryption' | 'index' | 'externalId' | 'searchable'> {
109
+ export interface FieldConfig extends Omit<Field, 'name' | 'label' | 'type' | 'options' | 'required' | 'multiple' | 'unique' | 'deleteBehavior' | 'hidden' | 'readonly' | 'encryption' | 'index' | 'externalId' | 'searchable' | 'auditTrail'> {
110
110
  /** Field name (inferred from Record key when used in ObjectConfig.fields) */
111
111
  name?: string;
112
112
  /** Display label (derived from name if not provided) */
package/dist/index.d.ts CHANGED
@@ -25,14 +25,10 @@ export * from './config';
25
25
  export * from './context';
26
26
  export * from './validation';
27
27
  export * from './permission';
28
- export * from './page';
29
28
  export * from './loader';
30
29
  export * from './application';
31
- export * from './menu';
32
30
  export * from './migration';
33
31
  export * from './api';
34
- export * from './view';
35
32
  export * from './workflow';
36
- export * from './report';
37
- export * from './form';
38
33
  export * from './formula';
34
+ export * from './plugin';
package/dist/index.js CHANGED
@@ -41,15 +41,11 @@ __exportStar(require("./config"), exports);
41
41
  __exportStar(require("./context"), exports);
42
42
  __exportStar(require("./validation"), exports);
43
43
  __exportStar(require("./permission"), exports);
44
- __exportStar(require("./page"), exports);
45
44
  __exportStar(require("./loader"), exports);
46
45
  __exportStar(require("./application"), exports);
47
- __exportStar(require("./menu"), exports);
48
46
  __exportStar(require("./migration"), exports);
49
47
  __exportStar(require("./api"), exports);
50
- __exportStar(require("./view"), exports);
51
48
  __exportStar(require("./workflow"), exports);
52
- __exportStar(require("./report"), exports);
53
- __exportStar(require("./form"), exports);
54
49
  __exportStar(require("./formula"), exports);
50
+ __exportStar(require("./plugin"), exports);
55
51
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;AAEH;;;;;;GAMG;AACH,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB;AACvB,2CAAyB;AACzB,+CAA6B;AAC7B,wCAAsB;AACtB,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,+CAA6B;AAC7B,yCAAuB;AACvB,2CAAyB;AACzB,gDAA8B;AAC9B,yCAAuB;AACvB,8CAA4B;AAC5B,wCAAsB;AACtB,yCAAuB;AACvB,6CAA2B;AAC3B,2CAAyB;AACzB,yCAAuB;AACvB,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;;;;;AAEH;;;;;;GAMG;AACH,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,yCAAuB;AACvB,2CAAyB;AACzB,+CAA6B;AAC7B,wCAAsB;AACtB,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,+CAA6B;AAC7B,2CAAyB;AACzB,gDAA8B;AAC9B,8CAA4B;AAC5B,wCAAsB;AACtB,6CAA2B;AAC3B,4CAA0B;AAC1B,2CAAyB"}
package/dist/object.d.ts CHANGED
@@ -5,18 +5,9 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- import { Data } from '@objectstack/spec';
9
- type ServiceObject = Data.ServiceObject;
10
- type IndexSchema = NonNullable<ServiceObject['indexes']>[number];
11
8
  import { FieldConfig } from './field';
12
9
  import { ActionConfig } from './action';
13
10
  import { AnyValidationRule } from './validation';
14
- /**
15
- * Re-export Protocol Types from the Constitution
16
- *
17
- * @deprecated Import directly from @objectstack/spec instead
18
- */
19
- export type { ServiceObject as SpecObject, IndexSchema };
20
11
  /**
21
12
  * RUNTIME-SPECIFIC TYPES
22
13
  * The following types extend or complement the Protocol Constitution
@@ -63,7 +54,7 @@ export interface ObjectAiConfig {
63
54
  * Runtime Object Configuration
64
55
  *
65
56
  * Extends the Protocol ServiceObject with runtime-specific properties.
66
- * The Protocol Constitution (SpecObject) defines the core object schema.
57
+ * The Protocol Constitution defines the core object schema.
67
58
  * This adds runtime conveniences like actions, AI config, and validation rules.
68
59
  */
69
60
  export interface ObjectConfig {
@@ -0,0 +1,125 @@
1
+ /**
2
+ * ObjectQL Plugin System
3
+ * Copyright (c) 2026-present ObjectStack Inc.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ /**
9
+ * Runtime context passed to plugin lifecycle hooks
10
+ *
11
+ * This context provides access to the kernel/engine instance
12
+ * and allows plugins to interact with the ObjectStack runtime.
13
+ */
14
+ export interface RuntimeContext {
15
+ /**
16
+ * The ObjectStack kernel/engine instance
17
+ *
18
+ * This provides access to:
19
+ * - metadata registry
20
+ * - hook manager
21
+ * - action manager
22
+ * - CRUD operations
23
+ */
24
+ engine: any;
25
+ /**
26
+ * Get the kernel instance (alternative accessor)
27
+ * Some implementations may use getKernel() instead of engine
28
+ */
29
+ getKernel?: () => any;
30
+ }
31
+ /**
32
+ * RuntimePlugin Interface
33
+ *
34
+ * Defines the standard plugin contract for ObjectStack/ObjectQL ecosystem.
35
+ * All plugins (protocol adapters, data drivers, feature extensions) should
36
+ * implement this interface to ensure consistent lifecycle management.
37
+ *
38
+ * Lifecycle Order:
39
+ * 1. install() - Called during kernel initialization
40
+ * 2. onStart() - Called when kernel starts
41
+ * 3. onStop() - Called when kernel stops/shuts down
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * export class MyPlugin implements RuntimePlugin {
46
+ * name = '@myorg/my-plugin';
47
+ * version = '1.0.0';
48
+ *
49
+ * async install(ctx: RuntimeContext): Promise<void> {
50
+ * // Register hooks, load configuration
51
+ * console.log('Plugin installed');
52
+ * }
53
+ *
54
+ * async onStart(ctx: RuntimeContext): Promise<void> {
55
+ * // Start servers, connect to services
56
+ * console.log('Plugin started');
57
+ * }
58
+ *
59
+ * async onStop(ctx: RuntimeContext): Promise<void> {
60
+ * // Cleanup resources, disconnect
61
+ * console.log('Plugin stopped');
62
+ * }
63
+ * }
64
+ * ```
65
+ */
66
+ export interface RuntimePlugin {
67
+ /**
68
+ * Unique plugin identifier
69
+ *
70
+ * Should follow npm package naming convention
71
+ * Examples: '@objectql/plugin-security', '@myorg/my-plugin'
72
+ */
73
+ name: string;
74
+ /**
75
+ * Plugin version (semantic versioning)
76
+ *
77
+ * Optional but recommended for debugging and compatibility tracking
78
+ * Example: '1.0.0', '2.1.3-beta'
79
+ */
80
+ version?: string;
81
+ /**
82
+ * Install hook - called during kernel initialization
83
+ *
84
+ * Use this phase to:
85
+ * - Register hooks and event handlers
86
+ * - Initialize plugin state
87
+ * - Load configuration
88
+ * - Register metadata (objects, fields, actions)
89
+ * - Validate dependencies
90
+ *
91
+ * This is called BEFORE the kernel starts, so services may not be available yet.
92
+ *
93
+ * @param ctx - Runtime context with access to kernel/engine
94
+ */
95
+ install?(ctx: RuntimeContext): void | Promise<void>;
96
+ /**
97
+ * Start hook - called when kernel starts
98
+ *
99
+ * Use this phase to:
100
+ * - Start background processes (servers, workers, schedulers)
101
+ * - Connect to external services (databases, APIs, message queues)
102
+ * - Initialize runtime resources
103
+ * - Perform health checks
104
+ *
105
+ * This is called AFTER install() and AFTER all plugins are installed.
106
+ *
107
+ * @param ctx - Runtime context with access to kernel/engine
108
+ */
109
+ onStart?(ctx: RuntimeContext): void | Promise<void>;
110
+ /**
111
+ * Stop hook - called when kernel stops/shuts down
112
+ *
113
+ * Use this phase to:
114
+ * - Stop background processes
115
+ * - Disconnect from external services
116
+ * - Cleanup resources (file handles, connections, timers)
117
+ * - Flush pending operations
118
+ * - Save state if needed
119
+ *
120
+ * This is called during graceful shutdown. Ensure cleanup completes quickly.
121
+ *
122
+ * @param ctx - Runtime context with access to kernel/engine
123
+ */
124
+ onStop?(ctx: RuntimeContext): void | Promise<void>;
125
+ }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  /**
3
- * ObjectQL
3
+ * ObjectQL Plugin System
4
4
  * Copyright (c) 2026-present ObjectStack Inc.
5
5
  *
6
6
  * This source code is licensed under the MIT license found in the
7
7
  * LICENSE file in the root directory of this source tree.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- //# sourceMappingURL=menu.js.map
10
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
package/dist/query.d.ts CHANGED
@@ -22,33 +22,70 @@ type FilterCondition = Data.FilterCondition;
22
22
  * Note: $not operator is not supported. Use $ne for field-level negation.
23
23
  */
24
24
  export type Filter = FilterCondition;
25
- export type AggregateFunction = 'count' | 'sum' | 'avg' | 'min' | 'max';
25
+ /** @deprecated Use AggregationFunctionType instead */
26
+ export type AggregateFunction = AggregationFunctionType;
27
+ /** @deprecated Use AggregationNode instead */
26
28
  export interface AggregateOption {
27
29
  func: AggregateFunction;
28
30
  field: string;
29
31
  alias?: string;
30
32
  }
31
33
  /**
32
- * Unified Query Interface
34
+ * Sort Node - Standard Protocol Format
35
+ * Represents an "Order By" clause.
36
+ */
37
+ export interface SortNode {
38
+ /** Field name to sort by */
39
+ field: string;
40
+ /** Sort direction - defaults to 'asc' */
41
+ order: 'asc' | 'desc';
42
+ }
43
+ /**
44
+ * Aggregation Function - Standard Protocol Format
45
+ */
46
+ export type AggregationFunctionType = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'count_distinct' | 'array_agg' | 'string_agg';
47
+ /**
48
+ * Aggregation Node - Standard Protocol Format
49
+ * Represents an aggregated field with function.
50
+ */
51
+ export interface AggregationNode {
52
+ /** Aggregation function to apply */
53
+ function: AggregationFunctionType;
54
+ /** Field to aggregate (optional for count) */
55
+ field?: string;
56
+ /** Alias for the result field */
57
+ alias: string;
58
+ /** Apply DISTINCT to the field before aggregation */
59
+ distinct?: boolean;
60
+ /** Optional filter condition for this aggregation */
61
+ filter?: Filter;
62
+ }
63
+ /**
64
+ * Unified Query Interface - Standard Protocol Format
33
65
  *
34
- * Provides a consistent query API across all ObjectQL drivers.
66
+ * Uses @objectstack/spec QueryAST format directly.
67
+ * This is the single source of truth for query structure.
35
68
  */
36
69
  export interface UnifiedQuery {
37
70
  /** Field selection - specify which fields to return */
38
71
  fields?: string[];
39
- /** Filter conditions using modern FilterCondition syntax */
40
- filters?: Filter;
41
- /** Sort order - array of [field, direction] tuples */
42
- sort?: [string, 'asc' | 'desc'][];
43
- /** Pagination - number of records to skip */
44
- skip?: number;
72
+ /** Filter conditions using standard FilterCondition syntax (was: filters) */
73
+ where?: Filter;
74
+ /** Sort order - array of SortNode objects (was: sort as tuples) */
75
+ orderBy?: SortNode[];
76
+ /** Pagination - number of records to skip (was: skip) */
77
+ offset?: number;
45
78
  /** Pagination - maximum number of records to return */
46
79
  limit?: number;
47
80
  /** Relation expansion - load related records */
48
81
  expand?: Record<string, UnifiedQuery>;
49
82
  /** Aggregation - group by fields */
50
83
  groupBy?: string[];
51
- /** Aggregation - aggregate functions to apply */
52
- aggregate?: AggregateOption[];
84
+ /** Aggregation - aggregate functions to apply (was: aggregate with func) */
85
+ aggregations?: AggregationNode[];
86
+ /** Filter for aggregated results (HAVING clause) */
87
+ having?: Filter;
88
+ /** Enable distinct results */
89
+ distinct?: boolean;
53
90
  }
54
91
  export {};
@@ -6,15 +6,35 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  /**
9
- * Re-export MetadataRegistry and MetadataItem from @objectql/runtime
9
+ * Optimized Metadata Registry with O(k) package uninstall complexity
10
10
  *
11
- * As of Week 3 refactoring, metadata management has been moved to the
12
- * @objectql/runtime package to enable sharing across the ecosystem.
11
+ * Uses secondary indexes to achieve O(k) complexity for unregisterPackage
12
+ * operation (where k is the number of items in the package) instead of
13
+ * O(n*m) (where n is types and m is items per type).
13
14
  */
14
- export { MetadataRegistry, MetadataItem } from '../../../objectstack/runtime/dist';
15
+ export declare class MetadataRegistry {
16
+ private items;
17
+ private packageIndex;
18
+ constructor();
19
+ register(type: string, nameOrConfig: any, config?: any): void;
20
+ get<T = any>(type: string, name: string): T;
21
+ list<T = any>(type: string): T[];
22
+ getTypes(): string[];
23
+ getEntry<T = any>(type: string, name: string): T;
24
+ unregister(type: string, name: string): void;
25
+ /**
26
+ * Optimized package unregistration with O(k) complexity
27
+ * where k is the number of items in the package.
28
+ *
29
+ * Previous complexity: O(n*m) - iterate all types and all items
30
+ * New complexity: O(k) - direct lookup via secondary index
31
+ */
32
+ unregisterPackage(packageName: string): void;
33
+ }
34
+ export type MetadataItem = any;
15
35
  /**
16
36
  * Legacy Metadata interface - kept for backward compatibility
17
- * @deprecated Use MetadataItem from @objectql/runtime instead
37
+ * @deprecated Use MetadataItem from @objectstack/runtime instead
18
38
  */
19
39
  export interface Metadata {
20
40
  type: string;
package/dist/registry.js CHANGED
@@ -9,11 +9,116 @@
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.MetadataRegistry = void 0;
11
11
  /**
12
- * Re-export MetadataRegistry and MetadataItem from @objectql/runtime
12
+ * Optimized Metadata Registry with O(k) package uninstall complexity
13
13
  *
14
- * As of Week 3 refactoring, metadata management has been moved to the
15
- * @objectql/runtime package to enable sharing across the ecosystem.
14
+ * Uses secondary indexes to achieve O(k) complexity for unregisterPackage
15
+ * operation (where k is the number of items in the package) instead of
16
+ * O(n*m) (where n is types and m is items per type).
16
17
  */
17
- var dist_1 = require("../../../objectstack/runtime/dist");
18
- Object.defineProperty(exports, "MetadataRegistry", { enumerable: true, get: function () { return dist_1.MetadataRegistry; } });
18
+ class MetadataRegistry {
19
+ constructor() {
20
+ this.items = {};
21
+ // Secondary index: package name -> list of metadata references
22
+ this.packageIndex = new Map();
23
+ }
24
+ register(type, nameOrConfig, config) {
25
+ if (!this.items[type]) {
26
+ this.items[type] = {};
27
+ }
28
+ let name;
29
+ let item;
30
+ if (config) {
31
+ name = nameOrConfig;
32
+ item = config;
33
+ }
34
+ else {
35
+ item = nameOrConfig;
36
+ name = item.name || item.id;
37
+ }
38
+ if (name) {
39
+ this.items[type][name] = item;
40
+ // Update package index
41
+ const packageName = item.package || item._package || item.packageName;
42
+ if (packageName) {
43
+ if (!this.packageIndex.has(packageName)) {
44
+ this.packageIndex.set(packageName, new Set());
45
+ }
46
+ this.packageIndex.get(packageName).add({ type, name });
47
+ }
48
+ }
49
+ }
50
+ get(type, name) {
51
+ var _a;
52
+ const item = (_a = this.items[type]) === null || _a === void 0 ? void 0 : _a[name];
53
+ if (item && item.content) {
54
+ return item.content;
55
+ }
56
+ return item;
57
+ }
58
+ list(type) {
59
+ if (!this.items[type])
60
+ return [];
61
+ return Object.values(this.items[type]).map((item) => {
62
+ if (item && item.content) {
63
+ return item.content;
64
+ }
65
+ return item;
66
+ });
67
+ }
68
+ getTypes() {
69
+ return Object.keys(this.items);
70
+ }
71
+ getEntry(type, name) {
72
+ var _a;
73
+ return (_a = this.items[type]) === null || _a === void 0 ? void 0 : _a[name];
74
+ }
75
+ unregister(type, name) {
76
+ var _a;
77
+ const item = (_a = this.items[type]) === null || _a === void 0 ? void 0 : _a[name];
78
+ if (item) {
79
+ // Update package index
80
+ const packageName = item.package || item._package || item.packageName;
81
+ if (packageName) {
82
+ const refs = this.packageIndex.get(packageName);
83
+ if (refs) {
84
+ // Remove this specific reference
85
+ for (const ref of refs) {
86
+ if (ref.type === type && ref.name === name) {
87
+ refs.delete(ref);
88
+ break;
89
+ }
90
+ }
91
+ // Clean up empty package entries
92
+ if (refs.size === 0) {
93
+ this.packageIndex.delete(packageName);
94
+ }
95
+ }
96
+ }
97
+ delete this.items[type][name];
98
+ }
99
+ }
100
+ /**
101
+ * Optimized package unregistration with O(k) complexity
102
+ * where k is the number of items in the package.
103
+ *
104
+ * Previous complexity: O(n*m) - iterate all types and all items
105
+ * New complexity: O(k) - direct lookup via secondary index
106
+ */
107
+ unregisterPackage(packageName) {
108
+ var _a;
109
+ // Direct lookup via secondary index ✅
110
+ const refs = this.packageIndex.get(packageName);
111
+ if (refs) {
112
+ // Delete each item referenced by this package
113
+ for (const ref of refs) {
114
+ if ((_a = this.items[ref.type]) === null || _a === void 0 ? void 0 : _a[ref.name]) {
115
+ delete this.items[ref.type][ref.name];
116
+ }
117
+ }
118
+ // Remove package from index
119
+ this.packageIndex.delete(packageName);
120
+ }
121
+ }
122
+ }
123
+ exports.MetadataRegistry = MetadataRegistry;
19
124
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH;;;;;GAKG;AACH,0DAAmF;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raint {
109
109
  expression?: string;
110
110
  /** Relationships needed for the rule */
111
111
  relationships?: Record<string, ValidationRelationship>;
112
- /** Logical AND conditions */
113
- all_of?: ValidationCondition[];
114
- /** Logical OR conditions */
115
- any_of?: ValidationCondition[];
116
- /** Required field condition */
117
- then_require?: ValidationCondition[];
112
+ /**
113
+ * Logical AND conditions (all must be true).
114
+ * Can be an array of field names (checks if fields are present and non-empty)
115
+ * or ValidationCondition objects for more complex validations.
116
+ */
117
+ all_of?: (string | ValidationCondition)[];
118
+ /**
119
+ * Logical OR conditions (at least one must be true).
120
+ * Can be an array of field names (checks if at least one field is present and non-empty)
121
+ * or ValidationCondition objects for more complex validations.
122
+ */
123
+ any_of?: (string | ValidationCondition)[];
124
+ /** Conditional field check - if this field is truthy, then_require fields must be present */
125
+ if_field?: string;
126
+ /**
127
+ * Required fields when if_field condition is met.
128
+ * Can be an array of field names (checks if fields are present and non-empty)
129
+ * or ValidationCondition objects for more complex validations.
130
+ */
131
+ then_require?: (string | ValidationCondition)[];
118
132
  }
119
133
  /**
120
134
  * Field validation configuration (built into FieldConfig).
@@ -172,11 +186,22 @@ export interface ValidationRule {
172
186
  }
173
187
  /**
174
188
  * Cross-field validation rule.
189
+ * Supports two formats:
190
+ * 1. Using the 'rule' property with a ValidationCondition object
191
+ * 2. Shorthand format with field, operator, and value/compare_to properties directly on the rule
175
192
  */
176
193
  export interface CrossFieldValidationRule extends ValidationRule {
177
194
  type: 'cross_field';
178
195
  /** The validation rule to apply */
179
196
  rule?: ValidationCondition;
197
+ /** Shorthand: Field to check (alternative to using rule property) */
198
+ field?: string;
199
+ /** Shorthand: Comparison operator (alternative to using rule property) */
200
+ operator?: ValidationOperator;
201
+ /** Shorthand: Value to compare against (mutually exclusive with compare_to) */
202
+ value?: any;
203
+ /** Shorthand: Field name to compare against for cross-field validation (mutually exclusive with value) */
204
+ compare_to?: string;
180
205
  }
181
206
  /**
182
207
  * Business rule validation.
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AA2XH;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACtC,YACI,OAAe,EACR,OAA+B,EAC/B,IAAa;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,YAAO,GAAP,OAAO,CAAwB;QAC/B,SAAI,GAAJ,IAAI,CAAS;QAGpB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAClC,CAAC;CACJ;AATD,0CASC"}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAoZH;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACtC,YACI,OAAe,EACR,OAA+B,EAC/B,IAAa;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,YAAO,GAAP,OAAO,CAAwB;QAC/B,SAAI,GAAJ,IAAI,CAAS;QAGpB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAClC,CAAC;CACJ;AATD,0CASC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectql/types",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "Pure TypeScript type definitions and interfaces for the ObjectQL protocol - The Contract",
5
5
  "keywords": [
6
6
  "objectql",
@@ -26,13 +26,13 @@
26
26
  "generate:schemas": "node scripts/generate-schemas.js",
27
27
  "test": "jest --passWithNoTests"
28
28
  },
29
- "peerDependencies": {
30
- "@objectstack/spec": "^0.3.1",
31
- "@objectql/runtime": "^0.2.0"
29
+ "peerDependencies": {},
30
+ "dependencies": {
31
+ "@objectstack/spec": "^0.8.0",
32
+ "@objectstack/objectql": "^0.8.0"
32
33
  },
33
34
  "devDependencies": {
34
- "@objectstack/spec": "^0.3.1",
35
- "@objectql/runtime": "workspace:*",
36
- "ts-json-schema-generator": "^2.4.0"
35
+ "ts-json-schema-generator": "^2.4.0",
36
+ "zod": "^3.23.8"
37
37
  }
38
38
  }