@objectstack/objectql 5.1.0 → 6.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
@@ -274,12 +274,12 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
274
274
  /**
275
275
  * Project scope applied to sys_metadata reads/writes. When undefined
276
276
  * (single-kernel deployments), rows land in / come from the
277
- * platform-global bucket (`project_id IS NULL`). When set, every
277
+ * platform-global bucket (`environment_id IS NULL`). When set, every
278
278
  * saveMetaItem insert/update and loadMetaFromDb query is filtered by
279
- * `project_id = projectId`, so per-project kernels see only their own
279
+ * `environment_id = environmentId`, so per-project kernels see only their own
280
280
  * metadata even if several projects share the same physical database.
281
281
  */
282
- private projectId?;
282
+ private environmentId?;
283
283
  /**
284
284
  * Lazily-instantiated SysMetadataRepository per organization. Keyed by
285
285
  * `${organizationId ?? '__env__'}`. Repositories are stateful — they
@@ -287,7 +287,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
287
287
  * them rather than constructing one per call.
288
288
  */
289
289
  private overlayRepos;
290
- constructor(engine: IDataEngine, getServicesRegistry?: () => Map<string, any>, getFeedService?: () => IFeedService | undefined, projectId?: string);
290
+ constructor(engine: IDataEngine, getServicesRegistry?: () => Map<string, any>, getFeedService?: () => IFeedService | undefined, environmentId?: string);
291
291
  /**
292
292
  * Lazily obtain a SysMetadataRepository for the given organization.
293
293
  * Env-wide overlays (organizationId == null) share a singleton under
@@ -297,7 +297,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
297
297
  /**
298
298
  * One-time guard for ensuring the overlay-uniqueness UNIQUE INDEX exists
299
299
  * on `sys_metadata`. ADR-0005: scopes overlays by
300
- * `(type, name, organization_id, project_id, scope)` for active rows only.
300
+ * `(type, name, organization_id, environment_id, scope)` for active rows only.
301
301
  * Idempotent SQL — safe to attempt on every protocol instance.
302
302
  *
303
303
  * Inlined here (rather than importing from @objectstack/metadata/migrations)
@@ -309,7 +309,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
309
309
  * Exposes the project scope the protocol is bound to. Consumers like
310
310
  * the HTTP dispatcher use this to decide whether to trust the process-
311
311
  * wide SchemaRegistry or whether they must route a read through the
312
- * protocol's project_id-filtered lookup.
312
+ * protocol's environment_id-filtered lookup.
313
313
  */
314
314
  getProjectId(): string | undefined;
315
315
  private requireFeedService;
@@ -664,7 +664,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
664
664
  *
665
665
  * Per ADR-0005, project-kernel mode ALSO hydrates from sys_metadata —
666
666
  * customization overlay rows must survive restart. Scope filter
667
- * (`project_id = this.projectId ?? null`) keeps tenants isolated.
667
+ * (`environment_id = this.environmentId ?? null`) keeps tenants isolated.
668
668
  */
669
669
  loadMetaFromDb(): Promise<{
670
670
  loaded: number;
@@ -899,7 +899,7 @@ declare class ObjectQL implements IDataEngine {
899
899
  * Expose the SchemaRegistry for plugins to register metadata.
900
900
  *
901
901
  * Returns the per-engine instance, NOT the class. Each ObjectQL engine
902
- * owns its registry so multi-project kernels remain isolated.
902
+ * owns its registry so multi-environment kernels remain isolated.
903
903
  */
904
904
  get registry(): SchemaRegistry;
905
905
  /**
@@ -1667,11 +1667,11 @@ declare class MetadataFacade {
1667
1667
  /**
1668
1668
  * Options for ObjectQLPlugin.
1669
1669
  *
1670
- * `projectId` scopes all metadata writes + reads to a specific project.
1671
- * When set, `protocol.saveMetaItem` stamps `project_id = <projectId>` on
1670
+ * `environmentId` scopes all metadata writes + reads to a specific project.
1671
+ * When set, `protocol.saveMetaItem` stamps `environment_id = <environmentId>` on
1672
1672
  * new sys_metadata rows, and `protocol.loadMetaFromDb` filters by the same
1673
1673
  * column. Leave undefined in single-kernel / self-hosted mode — rows land
1674
- * in the platform-global scope (project_id IS NULL).
1674
+ * in the platform-global scope (environment_id IS NULL).
1675
1675
  */
1676
1676
  interface ObjectQLPluginOptions {
1677
1677
  /** Optional pre-built engine. When absent, one is lazily created in init. */
@@ -1679,7 +1679,7 @@ interface ObjectQLPluginOptions {
1679
1679
  /** Passed to `new ObjectQL(...)` when `ql` is not supplied. */
1680
1680
  hostContext?: Record<string, any>;
1681
1681
  /** Scope sys_metadata reads/writes to this project. */
1682
- projectId?: string;
1682
+ environmentId?: string;
1683
1683
  /**
1684
1684
  * Override the kernel's default plugin-start timeout for this plugin.
1685
1685
  * Defaults to 120000 (120s). Schema sync to a remote SQL backend
@@ -1720,7 +1720,7 @@ declare class ObjectQLPlugin implements Plugin {
1720
1720
  startupTimeout: number;
1721
1721
  private ql;
1722
1722
  private hostContext?;
1723
- private projectId?;
1723
+ private environmentId?;
1724
1724
  private skipSchemaSync;
1725
1725
  /** Unsubscribe handles for metadata-event subscriptions (ADR-0008 PR-7). */
1726
1726
  private metadataUnsubscribes;
package/dist/index.d.ts CHANGED
@@ -274,12 +274,12 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
274
274
  /**
275
275
  * Project scope applied to sys_metadata reads/writes. When undefined
276
276
  * (single-kernel deployments), rows land in / come from the
277
- * platform-global bucket (`project_id IS NULL`). When set, every
277
+ * platform-global bucket (`environment_id IS NULL`). When set, every
278
278
  * saveMetaItem insert/update and loadMetaFromDb query is filtered by
279
- * `project_id = projectId`, so per-project kernels see only their own
279
+ * `environment_id = environmentId`, so per-project kernels see only their own
280
280
  * metadata even if several projects share the same physical database.
281
281
  */
282
- private projectId?;
282
+ private environmentId?;
283
283
  /**
284
284
  * Lazily-instantiated SysMetadataRepository per organization. Keyed by
285
285
  * `${organizationId ?? '__env__'}`. Repositories are stateful — they
@@ -287,7 +287,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
287
287
  * them rather than constructing one per call.
288
288
  */
289
289
  private overlayRepos;
290
- constructor(engine: IDataEngine, getServicesRegistry?: () => Map<string, any>, getFeedService?: () => IFeedService | undefined, projectId?: string);
290
+ constructor(engine: IDataEngine, getServicesRegistry?: () => Map<string, any>, getFeedService?: () => IFeedService | undefined, environmentId?: string);
291
291
  /**
292
292
  * Lazily obtain a SysMetadataRepository for the given organization.
293
293
  * Env-wide overlays (organizationId == null) share a singleton under
@@ -297,7 +297,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
297
297
  /**
298
298
  * One-time guard for ensuring the overlay-uniqueness UNIQUE INDEX exists
299
299
  * on `sys_metadata`. ADR-0005: scopes overlays by
300
- * `(type, name, organization_id, project_id, scope)` for active rows only.
300
+ * `(type, name, organization_id, environment_id, scope)` for active rows only.
301
301
  * Idempotent SQL — safe to attempt on every protocol instance.
302
302
  *
303
303
  * Inlined here (rather than importing from @objectstack/metadata/migrations)
@@ -309,7 +309,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
309
309
  * Exposes the project scope the protocol is bound to. Consumers like
310
310
  * the HTTP dispatcher use this to decide whether to trust the process-
311
311
  * wide SchemaRegistry or whether they must route a read through the
312
- * protocol's project_id-filtered lookup.
312
+ * protocol's environment_id-filtered lookup.
313
313
  */
314
314
  getProjectId(): string | undefined;
315
315
  private requireFeedService;
@@ -664,7 +664,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
664
664
  *
665
665
  * Per ADR-0005, project-kernel mode ALSO hydrates from sys_metadata —
666
666
  * customization overlay rows must survive restart. Scope filter
667
- * (`project_id = this.projectId ?? null`) keeps tenants isolated.
667
+ * (`environment_id = this.environmentId ?? null`) keeps tenants isolated.
668
668
  */
669
669
  loadMetaFromDb(): Promise<{
670
670
  loaded: number;
@@ -899,7 +899,7 @@ declare class ObjectQL implements IDataEngine {
899
899
  * Expose the SchemaRegistry for plugins to register metadata.
900
900
  *
901
901
  * Returns the per-engine instance, NOT the class. Each ObjectQL engine
902
- * owns its registry so multi-project kernels remain isolated.
902
+ * owns its registry so multi-environment kernels remain isolated.
903
903
  */
904
904
  get registry(): SchemaRegistry;
905
905
  /**
@@ -1667,11 +1667,11 @@ declare class MetadataFacade {
1667
1667
  /**
1668
1668
  * Options for ObjectQLPlugin.
1669
1669
  *
1670
- * `projectId` scopes all metadata writes + reads to a specific project.
1671
- * When set, `protocol.saveMetaItem` stamps `project_id = <projectId>` on
1670
+ * `environmentId` scopes all metadata writes + reads to a specific project.
1671
+ * When set, `protocol.saveMetaItem` stamps `environment_id = <environmentId>` on
1672
1672
  * new sys_metadata rows, and `protocol.loadMetaFromDb` filters by the same
1673
1673
  * column. Leave undefined in single-kernel / self-hosted mode — rows land
1674
- * in the platform-global scope (project_id IS NULL).
1674
+ * in the platform-global scope (environment_id IS NULL).
1675
1675
  */
1676
1676
  interface ObjectQLPluginOptions {
1677
1677
  /** Optional pre-built engine. When absent, one is lazily created in init. */
@@ -1679,7 +1679,7 @@ interface ObjectQLPluginOptions {
1679
1679
  /** Passed to `new ObjectQL(...)` when `ql` is not supplied. */
1680
1680
  hostContext?: Record<string, any>;
1681
1681
  /** Scope sys_metadata reads/writes to this project. */
1682
- projectId?: string;
1682
+ environmentId?: string;
1683
1683
  /**
1684
1684
  * Override the kernel's default plugin-start timeout for this plugin.
1685
1685
  * Defaults to 120000 (120s). Schema sync to a remote SQL backend
@@ -1720,7 +1720,7 @@ declare class ObjectQLPlugin implements Plugin {
1720
1720
  startupTimeout: number;
1721
1721
  private ql;
1722
1722
  private hostContext?;
1723
- private projectId?;
1723
+ private environmentId?;
1724
1724
  private skipSchemaSync;
1725
1725
  /** Unsubscribe handles for metadata-event subscriptions (ADR-0008 PR-7). */
1726
1726
  private metadataUnsubscribes;
package/dist/index.js CHANGED
@@ -1241,7 +1241,7 @@ var SERVICE_CONFIG = {
1241
1241
  search: { route: "/api/v1/search", plugin: "plugin-search" }
1242
1242
  };
1243
1243
  var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementation {
1244
- constructor(engine, getServicesRegistry, getFeedService, projectId) {
1244
+ constructor(engine, getServicesRegistry, getFeedService, environmentId) {
1245
1245
  /**
1246
1246
  * Lazily-instantiated SysMetadataRepository per organization. Keyed by
1247
1247
  * `${organizationId ?? '__env__'}`. Repositories are stateful — they
@@ -1252,7 +1252,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
1252
1252
  /**
1253
1253
  * One-time guard for ensuring the overlay-uniqueness UNIQUE INDEX exists
1254
1254
  * on `sys_metadata`. ADR-0005: scopes overlays by
1255
- * `(type, name, organization_id, project_id, scope)` for active rows only.
1255
+ * `(type, name, organization_id, environment_id, scope)` for active rows only.
1256
1256
  * Idempotent SQL — safe to attempt on every protocol instance.
1257
1257
  *
1258
1258
  * Inlined here (rather than importing from @objectstack/metadata/migrations)
@@ -1262,7 +1262,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
1262
1262
  this.engine = engine;
1263
1263
  this.getServicesRegistry = getServicesRegistry;
1264
1264
  this.getFeedService = getFeedService;
1265
- this.projectId = projectId;
1265
+ this.environmentId = environmentId;
1266
1266
  }
1267
1267
  /**
1268
1268
  * Lazily obtain a SysMetadataRepository for the given organization.
@@ -1330,10 +1330,10 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
1330
1330
  * Exposes the project scope the protocol is bound to. Consumers like
1331
1331
  * the HTTP dispatcher use this to decide whether to trust the process-
1332
1332
  * wide SchemaRegistry or whether they must route a read through the
1333
- * protocol's project_id-filtered lookup.
1333
+ * protocol's environment_id-filtered lookup.
1334
1334
  */
1335
1335
  getProjectId() {
1336
- return this.projectId;
1336
+ return this.environmentId;
1337
1337
  }
1338
1338
  requireFeedService() {
1339
1339
  const svc = this.getFeedService?.();
@@ -1446,7 +1446,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
1446
1446
  async getMetaItems(request) {
1447
1447
  const { packageId } = request;
1448
1448
  let items = [];
1449
- if (this.projectId === void 0) {
1449
+ if (this.environmentId === void 0) {
1450
1450
  items = [...this.engine.registry.listItems(request.type, packageId)];
1451
1451
  if (items.length === 0) {
1452
1452
  const alt = import_shared.PLURAL_TO_SINGULAR[request.type] ?? import_shared.SINGULAR_TO_PLURAL[request.type];
@@ -1498,7 +1498,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
1498
1498
  if (data && typeof data === "object" && "name" in data) {
1499
1499
  byName.set(data.name, data);
1500
1500
  }
1501
- if (this.projectId === void 0) {
1501
+ if (this.environmentId === void 0) {
1502
1502
  this.engine.registry.registerItem(request.type, data, "name");
1503
1503
  }
1504
1504
  }
@@ -2506,7 +2506,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
2506
2506
  if (!request.item) {
2507
2507
  throw new Error("Item data is required");
2508
2508
  }
2509
- if (this.projectId !== void 0 && !_ObjectStackProtocolImplementation.isOverlayAllowed(request.type)) {
2509
+ if (this.environmentId !== void 0 && !_ObjectStackProtocolImplementation.isOverlayAllowed(request.type)) {
2510
2510
  const allowed = Array.from(_ObjectStackProtocolImplementation.OVERLAY_ALLOWED_TYPES).join(", ");
2511
2511
  const err = new Error(
2512
2512
  `[not_overridable] Metadata type '${request.type}' has not opted into per-org overlay writes. Set allowOrgOverride: true on its DEFAULT_METADATA_TYPE_REGISTRY entry to enable. Currently allowed: ${allowed}. See docs/adr/0005-metadata-customization-overlay.md.`
@@ -2673,7 +2673,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
2673
2673
  * with {@link saveMetaItem}.
2674
2674
  */
2675
2675
  async deleteMetaItem(request) {
2676
- if (this.projectId !== void 0 && !_ObjectStackProtocolImplementation.isOverlayAllowed(request.type)) {
2676
+ if (this.environmentId !== void 0 && !_ObjectStackProtocolImplementation.isOverlayAllowed(request.type)) {
2677
2677
  const err = new Error(
2678
2678
  `[not_overridable] Metadata type '${request.type}' has not opted into per-org overlay writes. See docs/adr/0005-metadata-customization-overlay.md.`
2679
2679
  );
@@ -2706,7 +2706,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
2706
2706
  actor: request.actor ?? "system",
2707
2707
  source: "protocol.deleteMetaItem"
2708
2708
  });
2709
- if (this.projectId === void 0) {
2709
+ if (this.environmentId === void 0) {
2710
2710
  try {
2711
2711
  const services = this.getServicesRegistry?.();
2712
2712
  const metadataService = services?.get("metadata");
@@ -2756,7 +2756,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
2756
2756
  };
2757
2757
  }
2758
2758
  await this.engine.delete("sys_metadata", { where: { id: existing.id } });
2759
- if (this.projectId === void 0) {
2759
+ if (this.environmentId === void 0) {
2760
2760
  try {
2761
2761
  const services = this.getServicesRegistry?.();
2762
2762
  const metadataService = services?.get("metadata");
@@ -2787,7 +2787,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
2787
2787
  *
2788
2788
  * Per ADR-0005, project-kernel mode ALSO hydrates from sys_metadata —
2789
2789
  * customization overlay rows must survive restart. Scope filter
2790
- * (`project_id = this.projectId ?? null`) keeps tenants isolated.
2790
+ * (`environment_id = this.environmentId ?? null`) keeps tenants isolated.
2791
2791
  */
2792
2792
  async loadMetaFromDb() {
2793
2793
  let loaded = 0;
@@ -3759,7 +3759,7 @@ var _ObjectQL = class _ObjectQL {
3759
3759
  // Per-engine SchemaRegistry instance.
3760
3760
  //
3761
3761
  // Historically SchemaRegistry was a process-wide singleton of static state,
3762
- // which broke multi-project servers: a project kernel would inherit every
3762
+ // which broke multi-environment servers: a project kernel would inherit every
3763
3763
  // object registered by the control plane (e.g. sys_metadata), and
3764
3764
  // getDriver()'s owner lookup would route CRUD to the wrong database. Each
3765
3765
  // engine now owns its registry so kernels are fully isolated.
@@ -3790,7 +3790,7 @@ var _ObjectQL = class _ObjectQL {
3790
3790
  * Expose the SchemaRegistry for plugins to register metadata.
3791
3791
  *
3792
3792
  * Returns the per-engine instance, NOT the class. Each ObjectQL engine
3793
- * owns its registry so multi-project kernels remain isolated.
3793
+ * owns its registry so multi-environment kernels remain isolated.
3794
3794
  */
3795
3795
  get registry() {
3796
3796
  return this._registry;
@@ -5576,7 +5576,7 @@ var ObjectQLPlugin = class {
5576
5576
  this.ql,
5577
5577
  () => ctx.getServices ? ctx.getServices() : /* @__PURE__ */ new Map(),
5578
5578
  void 0,
5579
- this.projectId
5579
+ this.environmentId
5580
5580
  );
5581
5581
  ctx.registerService("protocol", protocolShim);
5582
5582
  ctx.logger.info("Protocol service registered");
@@ -5638,7 +5638,7 @@ var ObjectQLPlugin = class {
5638
5638
  } else {
5639
5639
  await this.syncRegisteredSchemas(ctx);
5640
5640
  }
5641
- if (this.projectId === void 0) {
5641
+ if (this.environmentId === void 0) {
5642
5642
  await this.restoreMetadataFromDb(ctx);
5643
5643
  } else {
5644
5644
  ctx.logger.info("Project kernel \u2014 skipping sys_metadata hydration (metadata sourced from artifact)");
@@ -5646,7 +5646,7 @@ var ObjectQLPlugin = class {
5646
5646
  if (!this.skipSchemaSync) {
5647
5647
  await this.syncRegisteredSchemas(ctx);
5648
5648
  }
5649
- if (this.projectId === void 0) {
5649
+ if (this.environmentId === void 0) {
5650
5650
  await this.bridgeObjectsToMetadataService(ctx);
5651
5651
  }
5652
5652
  this.registerAuditHooks(ctx);
@@ -5675,7 +5675,7 @@ var ObjectQLPlugin = class {
5675
5675
  this.ql = opts.ql;
5676
5676
  }
5677
5677
  this.hostContext = opts.hostContext ?? hostContext;
5678
- this.projectId = opts.projectId;
5678
+ this.environmentId = opts.environmentId;
5679
5679
  if (typeof opts.startupTimeout === "number" && opts.startupTimeout > 0) {
5680
5680
  this.startupTimeout = opts.startupTimeout;
5681
5681
  }