@objectstack/objectql 8.0.1 → 9.0.0

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/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- import { ServiceObject, ObjectOwnership, HookContext, QueryAST, EngineQueryOptions, DataEngineInsertOptions, EngineUpdateOptions, EngineDeleteOptions, EngineCountOptions, EngineAggregateOptions, DateGranularityValue, Hook } from '@objectstack/spec/data';
1
+ import { ServiceObject, ObjectOwnership, HookContext, QueryAST, EngineQueryOptions, DataEngineInsertOptions, EngineUpdateOptions, EngineDeleteOptions, EngineCountOptions, EngineAggregateOptions, DateGranularityValue, Hook, SeedLoaderRequest, SeedLoaderResult, ObjectDependencyGraph, Seed, SeedLoaderConfigInput } from '@objectstack/spec/data';
2
2
  import { ObjectStackManifest, InstalledPackage, MetadataValidationResult, MetadataLock, MetadataProvenance, ExecutionContext } from '@objectstack/spec/kernel';
3
3
  import * as _objectstack_metadata_core from '@objectstack/metadata-core';
4
4
  import { MetadataRepository, MetaRef, MetadataItem, PutOptions, PutResult, DeleteOptions, DeleteResult, MetadataWriteIntent, ListFilter, MetadataItemHeader, HistoryOptions, MetadataEvent, WatchFilter } from '@objectstack/metadata-core';
5
5
  import { ObjectStackProtocol, MetadataCacheRequest, MetadataCacheResponse, BatchUpdateRequest, BatchUpdateResponse, UpdateManyDataRequest, DeleteManyDataRequest, InstallPackageRequest, InstallPackageResponse } from '@objectstack/spec/api';
6
- import { IDataEngine, DriverInterface, Logger, Plugin, PluginContext, ObjectKernel } from '@objectstack/core';
7
- import { IFeedService, IRealtimeService, ICryptoProvider } from '@objectstack/spec/contracts';
6
+ import { IDataEngine, DriverInterface, Logger as Logger$1, Plugin, PluginContext, ObjectKernel } from '@objectstack/core';
7
+ import { IFeedService, IRealtimeService, ICryptoProvider, ISeedLoaderService, IDataEngine as IDataEngine$1, IMetadataService } from '@objectstack/spec/contracts';
8
8
  import { Expression } from '@objectstack/spec';
9
9
 
10
10
  /**
@@ -1250,12 +1250,40 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
1250
1250
  organizationId?: string;
1251
1251
  actor?: string;
1252
1252
  message?: string;
1253
+ /**
1254
+ * INTERNAL — `publishPackageDrafts` publishes many drafts and batch-applies
1255
+ * every seed body in ONE loader pass afterwards (cross-seed references need
1256
+ * multi-pass over the whole set), so it suppresses the per-item apply here.
1257
+ */
1258
+ _skipSeedApply?: boolean;
1253
1259
  }): Promise<{
1254
1260
  success: boolean;
1255
1261
  version: string;
1256
1262
  seq: number;
1257
1263
  message?: string;
1264
+ /**
1265
+ * Present when a `seed` draft was published: the result of materializing
1266
+ * its rows. Publishing the metadata ALWAYS succeeds independently — a
1267
+ * seed-load problem is surfaced here, never thrown, so callers (and UIs)
1268
+ * must check `seedApplied.success` instead of assuming data went live.
1269
+ */
1270
+ seedApplied?: {
1271
+ success: boolean;
1272
+ inserted: number;
1273
+ updated: number;
1274
+ error?: string;
1275
+ errors?: unknown[];
1276
+ };
1258
1277
  }>;
1278
+ /**
1279
+ * Materialize published `seed` bodies into data rows via the SeedLoaderService
1280
+ * (externalId-keyed upsert, multi-pass for cross-seed references). Passing ALL
1281
+ * of a publish's seed bodies in ONE call lets a child seed reference a parent
1282
+ * seed's rows regardless of publish order. Best-effort: any failure is
1283
+ * returned, never thrown — publishing metadata must not be blocked by a data
1284
+ * problem, but the caller surfaces `seedApplied` so the failure is LOUD.
1285
+ */
1286
+ private applySeedBodies;
1259
1287
  /**
1260
1288
  * List pending DRAFT metadata (ADR-0033) for the org, optionally narrowed
1261
1289
  * by `packageId` and/or `type`. The list reads of `getMetaItems` only see
@@ -1304,6 +1332,14 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
1304
1332
  error: string;
1305
1333
  code?: string;
1306
1334
  }>;
1335
+ /** Aggregate result of materializing every published `seed` (absent when no seeds). */
1336
+ seedApplied?: {
1337
+ success: boolean;
1338
+ inserted: number;
1339
+ updated: number;
1340
+ error?: string;
1341
+ errors?: unknown[];
1342
+ };
1307
1343
  }>;
1308
1344
  /**
1309
1345
  * Discard every pending DRAFT bound to a package — the NON-destructive
@@ -1799,7 +1835,7 @@ type EngineMiddleware = (ctx: OperationContext, next: () => Promise<void>) => Pr
1799
1835
  */
1800
1836
  interface ObjectQLHostContext {
1801
1837
  ql: ObjectQL;
1802
- logger: Logger;
1838
+ logger: Logger$1;
1803
1839
  [key: string]: any;
1804
1840
  }
1805
1841
  declare class ObjectQL implements IDataEngine {
@@ -3107,4 +3143,56 @@ declare function convertIntrospectedSchemaToObjects(introspectedSchema: Introspe
3107
3143
  skipSystemColumns?: boolean;
3108
3144
  }): ServiceObject[];
3109
3145
 
3110
- export { type BindHooksOptions, type BindHooksResult, DEFAULT_EXTENDER_PRIORITY, DEFAULT_OWNER_PRIORITY, type EngineMiddleware, type EvaluateRulesOptions, type FieldValidationError, type HookEntry, type HookHandler, type HookMetricLabel, type HookMetricOutcome, type HookMetricsRecorder, type HookSkipReason, InMemoryHookMetricsRecorder, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedSchema, type IntrospectedTable, MetadataFacade, type ObjectContributor, ObjectQL, type ObjectQLHostContext, type ObjectQLKernelOptions, ObjectQLPlugin, ObjectRepository, ObjectStackProtocolImplementation, type OperationContext, RESERVED_NAMESPACES, SECRET_MASK, SECRET_REF_PREFIX, SchemaRegistry, type SchemaRegistryOptions, ScopedContext, type SysMetadataEngine, SysMetadataRepository, type SysMetadataRepositoryOptions, ValidationError, type WrapDeclarativeOptions, applyInMemoryAggregation, applySystemFields, bindHooksToEngine, bucketDateValue, collectSecretFields, computeFQN, convertIntrospectedSchemaToObjects, createObjectQLKernel, evaluateValidationRules, isSecretRef, legalNextStates, makeSecretRef, needsPriorRecord, noopHookMetricsRecorder, parseFQN, parseSecretRef, toTitleCase, validateRecord, wrapDeclarativeHook };
3146
+ interface Logger {
3147
+ info(message: string, meta?: Record<string, any>): void;
3148
+ warn(message: string, meta?: Record<string, any>): void;
3149
+ error(message: string, error?: Error, meta?: Record<string, any>): void;
3150
+ debug(message: string, meta?: Record<string, any>): void;
3151
+ }
3152
+ /**
3153
+ * SeedLoaderService — Runtime implementation of ISeedLoaderService
3154
+ *
3155
+ * Provides metadata-driven seed data loading with:
3156
+ * - Automatic lookup/master_detail reference resolution via externalId
3157
+ * - Topological dependency ordering (parents before children)
3158
+ * - Multi-pass loading for circular references
3159
+ * - Dry-run validation mode
3160
+ * - Upsert support honoring SeedSchema mode
3161
+ * - Actionable error reporting
3162
+ */
3163
+ declare class SeedLoaderService implements ISeedLoaderService {
3164
+ private engine;
3165
+ private metadata;
3166
+ private logger;
3167
+ constructor(engine: IDataEngine$1, metadata: IMetadataService, logger: Logger);
3168
+ load(request: SeedLoaderRequest): Promise<SeedLoaderResult>;
3169
+ buildDependencyGraph(objectNames: string[]): Promise<ObjectDependencyGraph>;
3170
+ validate(datasets: Seed[], config?: SeedLoaderConfigInput): Promise<SeedLoaderResult>;
3171
+ private loadDataset;
3172
+ private resolveFromDatabase;
3173
+ private resolveDeferredUpdates;
3174
+ /**
3175
+ * Seed writes always run as a privileged system context. This bypasses
3176
+ * RBAC checks (so seeds can target system tables like `sys_*`) and
3177
+ * disables the SecurityPlugin's auto-injection of `organization_id` /
3178
+ * `owner_id` — seeds either declare those fields explicitly per
3179
+ * record, or are intentionally cross-tenant / global.
3180
+ */
3181
+ private static readonly SEED_OPTIONS;
3182
+ private writeRecord;
3183
+ /**
3184
+ * Kahn's algorithm for topological sort with cycle detection.
3185
+ */
3186
+ private topologicalSort;
3187
+ private findCycles;
3188
+ private filterByEnv;
3189
+ private orderDatasets;
3190
+ private buildReferenceMap;
3191
+ private loadExistingRecords;
3192
+ private looksLikeInternalId;
3193
+ private extractId;
3194
+ private buildEmptyResult;
3195
+ private buildResult;
3196
+ }
3197
+
3198
+ export { type BindHooksOptions, type BindHooksResult, DEFAULT_EXTENDER_PRIORITY, DEFAULT_OWNER_PRIORITY, type EngineMiddleware, type EvaluateRulesOptions, type FieldValidationError, type HookEntry, type HookHandler, type HookMetricLabel, type HookMetricOutcome, type HookMetricsRecorder, type HookSkipReason, InMemoryHookMetricsRecorder, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedSchema, type IntrospectedTable, MetadataFacade, type ObjectContributor, ObjectQL, type ObjectQLHostContext, type ObjectQLKernelOptions, ObjectQLPlugin, ObjectRepository, ObjectStackProtocolImplementation, type OperationContext, RESERVED_NAMESPACES, SECRET_MASK, SECRET_REF_PREFIX, SchemaRegistry, type SchemaRegistryOptions, ScopedContext, SeedLoaderService, type SysMetadataEngine, SysMetadataRepository, type SysMetadataRepositoryOptions, ValidationError, type WrapDeclarativeOptions, applyInMemoryAggregation, applySystemFields, bindHooksToEngine, bucketDateValue, collectSecretFields, computeFQN, convertIntrospectedSchemaToObjects, createObjectQLKernel, evaluateValidationRules, isSecretRef, legalNextStates, makeSecretRef, needsPriorRecord, noopHookMetricsRecorder, parseFQN, parseSecretRef, toTitleCase, validateRecord, wrapDeclarativeHook };
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { ServiceObject, ObjectOwnership, HookContext, QueryAST, EngineQueryOptions, DataEngineInsertOptions, EngineUpdateOptions, EngineDeleteOptions, EngineCountOptions, EngineAggregateOptions, DateGranularityValue, Hook } from '@objectstack/spec/data';
1
+ import { ServiceObject, ObjectOwnership, HookContext, QueryAST, EngineQueryOptions, DataEngineInsertOptions, EngineUpdateOptions, EngineDeleteOptions, EngineCountOptions, EngineAggregateOptions, DateGranularityValue, Hook, SeedLoaderRequest, SeedLoaderResult, ObjectDependencyGraph, Seed, SeedLoaderConfigInput } from '@objectstack/spec/data';
2
2
  import { ObjectStackManifest, InstalledPackage, MetadataValidationResult, MetadataLock, MetadataProvenance, ExecutionContext } from '@objectstack/spec/kernel';
3
3
  import * as _objectstack_metadata_core from '@objectstack/metadata-core';
4
4
  import { MetadataRepository, MetaRef, MetadataItem, PutOptions, PutResult, DeleteOptions, DeleteResult, MetadataWriteIntent, ListFilter, MetadataItemHeader, HistoryOptions, MetadataEvent, WatchFilter } from '@objectstack/metadata-core';
5
5
  import { ObjectStackProtocol, MetadataCacheRequest, MetadataCacheResponse, BatchUpdateRequest, BatchUpdateResponse, UpdateManyDataRequest, DeleteManyDataRequest, InstallPackageRequest, InstallPackageResponse } from '@objectstack/spec/api';
6
- import { IDataEngine, DriverInterface, Logger, Plugin, PluginContext, ObjectKernel } from '@objectstack/core';
7
- import { IFeedService, IRealtimeService, ICryptoProvider } from '@objectstack/spec/contracts';
6
+ import { IDataEngine, DriverInterface, Logger as Logger$1, Plugin, PluginContext, ObjectKernel } from '@objectstack/core';
7
+ import { IFeedService, IRealtimeService, ICryptoProvider, ISeedLoaderService, IDataEngine as IDataEngine$1, IMetadataService } from '@objectstack/spec/contracts';
8
8
  import { Expression } from '@objectstack/spec';
9
9
 
10
10
  /**
@@ -1250,12 +1250,40 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
1250
1250
  organizationId?: string;
1251
1251
  actor?: string;
1252
1252
  message?: string;
1253
+ /**
1254
+ * INTERNAL — `publishPackageDrafts` publishes many drafts and batch-applies
1255
+ * every seed body in ONE loader pass afterwards (cross-seed references need
1256
+ * multi-pass over the whole set), so it suppresses the per-item apply here.
1257
+ */
1258
+ _skipSeedApply?: boolean;
1253
1259
  }): Promise<{
1254
1260
  success: boolean;
1255
1261
  version: string;
1256
1262
  seq: number;
1257
1263
  message?: string;
1264
+ /**
1265
+ * Present when a `seed` draft was published: the result of materializing
1266
+ * its rows. Publishing the metadata ALWAYS succeeds independently — a
1267
+ * seed-load problem is surfaced here, never thrown, so callers (and UIs)
1268
+ * must check `seedApplied.success` instead of assuming data went live.
1269
+ */
1270
+ seedApplied?: {
1271
+ success: boolean;
1272
+ inserted: number;
1273
+ updated: number;
1274
+ error?: string;
1275
+ errors?: unknown[];
1276
+ };
1258
1277
  }>;
1278
+ /**
1279
+ * Materialize published `seed` bodies into data rows via the SeedLoaderService
1280
+ * (externalId-keyed upsert, multi-pass for cross-seed references). Passing ALL
1281
+ * of a publish's seed bodies in ONE call lets a child seed reference a parent
1282
+ * seed's rows regardless of publish order. Best-effort: any failure is
1283
+ * returned, never thrown — publishing metadata must not be blocked by a data
1284
+ * problem, but the caller surfaces `seedApplied` so the failure is LOUD.
1285
+ */
1286
+ private applySeedBodies;
1259
1287
  /**
1260
1288
  * List pending DRAFT metadata (ADR-0033) for the org, optionally narrowed
1261
1289
  * by `packageId` and/or `type`. The list reads of `getMetaItems` only see
@@ -1304,6 +1332,14 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
1304
1332
  error: string;
1305
1333
  code?: string;
1306
1334
  }>;
1335
+ /** Aggregate result of materializing every published `seed` (absent when no seeds). */
1336
+ seedApplied?: {
1337
+ success: boolean;
1338
+ inserted: number;
1339
+ updated: number;
1340
+ error?: string;
1341
+ errors?: unknown[];
1342
+ };
1307
1343
  }>;
1308
1344
  /**
1309
1345
  * Discard every pending DRAFT bound to a package — the NON-destructive
@@ -1799,7 +1835,7 @@ type EngineMiddleware = (ctx: OperationContext, next: () => Promise<void>) => Pr
1799
1835
  */
1800
1836
  interface ObjectQLHostContext {
1801
1837
  ql: ObjectQL;
1802
- logger: Logger;
1838
+ logger: Logger$1;
1803
1839
  [key: string]: any;
1804
1840
  }
1805
1841
  declare class ObjectQL implements IDataEngine {
@@ -3107,4 +3143,56 @@ declare function convertIntrospectedSchemaToObjects(introspectedSchema: Introspe
3107
3143
  skipSystemColumns?: boolean;
3108
3144
  }): ServiceObject[];
3109
3145
 
3110
- export { type BindHooksOptions, type BindHooksResult, DEFAULT_EXTENDER_PRIORITY, DEFAULT_OWNER_PRIORITY, type EngineMiddleware, type EvaluateRulesOptions, type FieldValidationError, type HookEntry, type HookHandler, type HookMetricLabel, type HookMetricOutcome, type HookMetricsRecorder, type HookSkipReason, InMemoryHookMetricsRecorder, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedSchema, type IntrospectedTable, MetadataFacade, type ObjectContributor, ObjectQL, type ObjectQLHostContext, type ObjectQLKernelOptions, ObjectQLPlugin, ObjectRepository, ObjectStackProtocolImplementation, type OperationContext, RESERVED_NAMESPACES, SECRET_MASK, SECRET_REF_PREFIX, SchemaRegistry, type SchemaRegistryOptions, ScopedContext, type SysMetadataEngine, SysMetadataRepository, type SysMetadataRepositoryOptions, ValidationError, type WrapDeclarativeOptions, applyInMemoryAggregation, applySystemFields, bindHooksToEngine, bucketDateValue, collectSecretFields, computeFQN, convertIntrospectedSchemaToObjects, createObjectQLKernel, evaluateValidationRules, isSecretRef, legalNextStates, makeSecretRef, needsPriorRecord, noopHookMetricsRecorder, parseFQN, parseSecretRef, toTitleCase, validateRecord, wrapDeclarativeHook };
3146
+ interface Logger {
3147
+ info(message: string, meta?: Record<string, any>): void;
3148
+ warn(message: string, meta?: Record<string, any>): void;
3149
+ error(message: string, error?: Error, meta?: Record<string, any>): void;
3150
+ debug(message: string, meta?: Record<string, any>): void;
3151
+ }
3152
+ /**
3153
+ * SeedLoaderService — Runtime implementation of ISeedLoaderService
3154
+ *
3155
+ * Provides metadata-driven seed data loading with:
3156
+ * - Automatic lookup/master_detail reference resolution via externalId
3157
+ * - Topological dependency ordering (parents before children)
3158
+ * - Multi-pass loading for circular references
3159
+ * - Dry-run validation mode
3160
+ * - Upsert support honoring SeedSchema mode
3161
+ * - Actionable error reporting
3162
+ */
3163
+ declare class SeedLoaderService implements ISeedLoaderService {
3164
+ private engine;
3165
+ private metadata;
3166
+ private logger;
3167
+ constructor(engine: IDataEngine$1, metadata: IMetadataService, logger: Logger);
3168
+ load(request: SeedLoaderRequest): Promise<SeedLoaderResult>;
3169
+ buildDependencyGraph(objectNames: string[]): Promise<ObjectDependencyGraph>;
3170
+ validate(datasets: Seed[], config?: SeedLoaderConfigInput): Promise<SeedLoaderResult>;
3171
+ private loadDataset;
3172
+ private resolveFromDatabase;
3173
+ private resolveDeferredUpdates;
3174
+ /**
3175
+ * Seed writes always run as a privileged system context. This bypasses
3176
+ * RBAC checks (so seeds can target system tables like `sys_*`) and
3177
+ * disables the SecurityPlugin's auto-injection of `organization_id` /
3178
+ * `owner_id` — seeds either declare those fields explicitly per
3179
+ * record, or are intentionally cross-tenant / global.
3180
+ */
3181
+ private static readonly SEED_OPTIONS;
3182
+ private writeRecord;
3183
+ /**
3184
+ * Kahn's algorithm for topological sort with cycle detection.
3185
+ */
3186
+ private topologicalSort;
3187
+ private findCycles;
3188
+ private filterByEnv;
3189
+ private orderDatasets;
3190
+ private buildReferenceMap;
3191
+ private loadExistingRecords;
3192
+ private looksLikeInternalId;
3193
+ private extractId;
3194
+ private buildEmptyResult;
3195
+ private buildResult;
3196
+ }
3197
+
3198
+ export { type BindHooksOptions, type BindHooksResult, DEFAULT_EXTENDER_PRIORITY, DEFAULT_OWNER_PRIORITY, type EngineMiddleware, type EvaluateRulesOptions, type FieldValidationError, type HookEntry, type HookHandler, type HookMetricLabel, type HookMetricOutcome, type HookMetricsRecorder, type HookSkipReason, InMemoryHookMetricsRecorder, type IntrospectedColumn, type IntrospectedForeignKey, type IntrospectedSchema, type IntrospectedTable, MetadataFacade, type ObjectContributor, ObjectQL, type ObjectQLHostContext, type ObjectQLKernelOptions, ObjectQLPlugin, ObjectRepository, ObjectStackProtocolImplementation, type OperationContext, RESERVED_NAMESPACES, SECRET_MASK, SECRET_REF_PREFIX, SchemaRegistry, type SchemaRegistryOptions, ScopedContext, SeedLoaderService, type SysMetadataEngine, SysMetadataRepository, type SysMetadataRepositoryOptions, ValidationError, type WrapDeclarativeOptions, applyInMemoryAggregation, applySystemFields, bindHooksToEngine, bucketDateValue, collectSecretFields, computeFQN, convertIntrospectedSchemaToObjects, createObjectQLKernel, evaluateValidationRules, isSecretRef, legalNextStates, makeSecretRef, needsPriorRecord, noopHookMetricsRecorder, parseFQN, parseSecretRef, toTitleCase, validateRecord, wrapDeclarativeHook };