@objectstack/objectql 4.0.3 → 4.0.4

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@4.0.3 build /home/runner/work/framework/framework/packages/objectql
2
+ > @objectstack/objectql@4.0.4 build /home/runner/work/framework/framework/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
- ESM dist/index.mjs 112.91 KB
14
- ESM dist/index.mjs.map 230.31 KB
15
- ESM ⚡️ Build success in 125ms
16
- CJS dist/index.js 114.81 KB
17
- CJS dist/index.js.map 231.61 KB
18
- CJS ⚡️ Build success in 160ms
13
+ CJS dist/index.js 117.80 KB
14
+ CJS dist/index.js.map 237.44 KB
15
+ CJS ⚡️ Build success in 238ms
16
+ ESM dist/index.mjs 115.90 KB
17
+ ESM dist/index.mjs.map 236.13 KB
18
+ ESM ⚡️ Build success in 244ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 21312ms
21
- DTS dist/index.d.mts 78.76 KB
22
- DTS dist/index.d.ts 78.76 KB
20
+ DTS ⚡️ Build success in 27180ms
21
+ DTS dist/index.d.mts 79.80 KB
22
+ DTS dist/index.d.ts 79.80 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @objectstack/objectql
2
2
 
3
+ ## 4.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [326b66b]
8
+ - @objectstack/spec@4.0.4
9
+ - @objectstack/core@4.0.4
10
+ - @objectstack/types@4.0.4
11
+
3
12
  ## 4.0.3
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -563,6 +563,7 @@ declare class SchemaRegistry {
563
563
  } | {
564
564
  manifest: {
565
565
  id: string;
566
+ defaultDatasource: string;
566
567
  version: string;
567
568
  type: "theme" | "app" | "agent" | "driver" | "server" | "ui" | "module" | "objectql" | "plugin" | "gateway" | "adapter";
568
569
  name: string;
@@ -888,6 +889,7 @@ declare class SchemaRegistry {
888
889
  registeredNamespaces?: string[] | undefined;
889
890
  } | {
890
891
  id: string;
892
+ defaultDatasource: string;
891
893
  version: string;
892
894
  type: "theme" | "app" | "agent" | "driver" | "server" | "ui" | "module" | "objectql" | "plugin" | "gateway" | "adapter";
893
895
  name: string;
@@ -1487,6 +1489,8 @@ declare class ObjectQL implements IDataEngine {
1487
1489
  private drivers;
1488
1490
  private defaultDriver;
1489
1491
  private logger;
1492
+ private datasourceMapping;
1493
+ private manifests;
1490
1494
  private hooks;
1491
1495
  private middlewares;
1492
1496
  private actions;
@@ -1609,8 +1613,38 @@ declare class ObjectQL implements IDataEngine {
1609
1613
  private resolveObjectName;
1610
1614
  /**
1611
1615
  * Helper to get the target driver
1616
+ *
1617
+ * Resolution priority (first match wins):
1618
+ * 1. Object's explicit `datasource` field (if not 'default')
1619
+ * 2. DatasourceMapping rules (namespace/package/pattern matching)
1620
+ * 3. Package's `defaultDatasource` from manifest
1621
+ * 4. Global default driver
1612
1622
  */
1613
1623
  private getDriver;
1624
+ /**
1625
+ * Resolve datasource from mapping rules
1626
+ *
1627
+ * Rules are evaluated in order (or by priority if specified).
1628
+ * First matching rule wins.
1629
+ */
1630
+ private resolveDatasourceFromMapping;
1631
+ /**
1632
+ * Simple glob pattern matching
1633
+ * Supports * (any chars) and ? (single char)
1634
+ */
1635
+ private matchPattern;
1636
+ /**
1637
+ * Set datasource mapping rules
1638
+ * Called by ObjectQLPlugin during bootstrap
1639
+ */
1640
+ setDatasourceMapping(rules: Array<{
1641
+ namespace?: string;
1642
+ package?: string;
1643
+ objectPattern?: string;
1644
+ default?: boolean;
1645
+ datasource: string;
1646
+ priority?: number;
1647
+ }>): void;
1614
1648
  /**
1615
1649
  * Initialize the engine and all registered drivers
1616
1650
  */
package/dist/index.d.ts CHANGED
@@ -563,6 +563,7 @@ declare class SchemaRegistry {
563
563
  } | {
564
564
  manifest: {
565
565
  id: string;
566
+ defaultDatasource: string;
566
567
  version: string;
567
568
  type: "theme" | "app" | "agent" | "driver" | "server" | "ui" | "module" | "objectql" | "plugin" | "gateway" | "adapter";
568
569
  name: string;
@@ -888,6 +889,7 @@ declare class SchemaRegistry {
888
889
  registeredNamespaces?: string[] | undefined;
889
890
  } | {
890
891
  id: string;
892
+ defaultDatasource: string;
891
893
  version: string;
892
894
  type: "theme" | "app" | "agent" | "driver" | "server" | "ui" | "module" | "objectql" | "plugin" | "gateway" | "adapter";
893
895
  name: string;
@@ -1487,6 +1489,8 @@ declare class ObjectQL implements IDataEngine {
1487
1489
  private drivers;
1488
1490
  private defaultDriver;
1489
1491
  private logger;
1492
+ private datasourceMapping;
1493
+ private manifests;
1490
1494
  private hooks;
1491
1495
  private middlewares;
1492
1496
  private actions;
@@ -1609,8 +1613,38 @@ declare class ObjectQL implements IDataEngine {
1609
1613
  private resolveObjectName;
1610
1614
  /**
1611
1615
  * Helper to get the target driver
1616
+ *
1617
+ * Resolution priority (first match wins):
1618
+ * 1. Object's explicit `datasource` field (if not 'default')
1619
+ * 2. DatasourceMapping rules (namespace/package/pattern matching)
1620
+ * 3. Package's `defaultDatasource` from manifest
1621
+ * 4. Global default driver
1612
1622
  */
1613
1623
  private getDriver;
1624
+ /**
1625
+ * Resolve datasource from mapping rules
1626
+ *
1627
+ * Rules are evaluated in order (or by priority if specified).
1628
+ * First matching rule wins.
1629
+ */
1630
+ private resolveDatasourceFromMapping;
1631
+ /**
1632
+ * Simple glob pattern matching
1633
+ * Supports * (any chars) and ? (single char)
1634
+ */
1635
+ private matchPattern;
1636
+ /**
1637
+ * Set datasource mapping rules
1638
+ * Called by ObjectQLPlugin during bootstrap
1639
+ */
1640
+ setDatasourceMapping(rules: Array<{
1641
+ namespace?: string;
1642
+ package?: string;
1643
+ objectPattern?: string;
1644
+ default?: boolean;
1645
+ datasource: string;
1646
+ priority?: number;
1647
+ }>): void;
1614
1648
  /**
1615
1649
  * Initialize the engine and all registered drivers
1616
1650
  */
package/dist/index.js CHANGED
@@ -736,7 +736,10 @@ var ObjectStackProtocolImplementation = class {
736
736
  const services = this.getServicesRegistry?.();
737
737
  const metadataService = services?.get("metadata");
738
738
  if (metadataService && typeof metadataService.list === "function") {
739
- const runtimeItems = await metadataService.list(request.type);
739
+ let runtimeItems = await metadataService.list(request.type);
740
+ if (packageId && runtimeItems && runtimeItems.length > 0) {
741
+ runtimeItems = runtimeItems.filter((item) => item?._packageId === packageId);
742
+ }
740
743
  if (runtimeItems && runtimeItems.length > 0) {
741
744
  const itemMap = /* @__PURE__ */ new Map();
742
745
  for (const item of items) {
@@ -1555,6 +1558,10 @@ var _ObjectQL = class _ObjectQL {
1555
1558
  constructor(hostContext = {}) {
1556
1559
  this.drivers = /* @__PURE__ */ new Map();
1557
1560
  this.defaultDriver = null;
1561
+ // Datasource mapping rules (imported from defineStack)
1562
+ this.datasourceMapping = [];
1563
+ // Package manifests registry (for defaultDatasource lookup)
1564
+ this.manifests = /* @__PURE__ */ new Map();
1558
1565
  // Per-object hooks with priority support
1559
1566
  this.hooks = /* @__PURE__ */ new Map([
1560
1567
  ["beforeFind", []],
@@ -1752,6 +1759,9 @@ var _ObjectQL = class _ObjectQL {
1752
1759
  const id = manifest.id || manifest.name;
1753
1760
  const namespace = manifest.namespace;
1754
1761
  this.logger.debug("Registering package manifest", { id, namespace });
1762
+ if (id) {
1763
+ this.manifests.set(id, manifest);
1764
+ }
1755
1765
  SchemaRegistry.installPackage(manifest);
1756
1766
  this.logger.debug("Installed Package", { id: manifest.id, name: manifest.name, namespace });
1757
1767
  if (manifest.objects) {
@@ -2006,27 +2016,99 @@ var _ObjectQL = class _ObjectQL {
2006
2016
  }
2007
2017
  /**
2008
2018
  * Helper to get the target driver
2019
+ *
2020
+ * Resolution priority (first match wins):
2021
+ * 1. Object's explicit `datasource` field (if not 'default')
2022
+ * 2. DatasourceMapping rules (namespace/package/pattern matching)
2023
+ * 3. Package's `defaultDatasource` from manifest
2024
+ * 4. Global default driver
2009
2025
  */
2010
2026
  getDriver(objectName) {
2011
2027
  const object = SchemaRegistry.getObject(objectName);
2012
- if (object) {
2013
- const datasourceName = object.datasource || "default";
2014
- if (datasourceName === "default") {
2015
- if (this.defaultDriver && this.drivers.has(this.defaultDriver)) {
2016
- return this.drivers.get(this.defaultDriver);
2017
- }
2018
- } else {
2019
- if (this.drivers.has(datasourceName)) {
2020
- return this.drivers.get(datasourceName);
2028
+ if (object?.datasource && object.datasource !== "default") {
2029
+ if (this.drivers.has(object.datasource)) {
2030
+ return this.drivers.get(object.datasource);
2031
+ }
2032
+ throw new Error(`[ObjectQL] Datasource '${object.datasource}' configured for object '${objectName}' is not registered.`);
2033
+ }
2034
+ const mappedDatasource = this.resolveDatasourceFromMapping(objectName, object);
2035
+ if (mappedDatasource && this.drivers.has(mappedDatasource)) {
2036
+ this.logger.debug("Resolved datasource from mapping", {
2037
+ object: objectName,
2038
+ datasource: mappedDatasource
2039
+ });
2040
+ return this.drivers.get(mappedDatasource);
2041
+ }
2042
+ const fqn = object?.name || objectName;
2043
+ const owner = SchemaRegistry.getObjectOwner(fqn);
2044
+ if (owner?.packageId) {
2045
+ const manifest = this.manifests.get(owner.packageId);
2046
+ if (manifest?.defaultDatasource && manifest.defaultDatasource !== "default") {
2047
+ if (this.drivers.has(manifest.defaultDatasource)) {
2048
+ this.logger.debug("Resolved datasource from package manifest", {
2049
+ object: objectName,
2050
+ package: owner.packageId,
2051
+ datasource: manifest.defaultDatasource
2052
+ });
2053
+ return this.drivers.get(manifest.defaultDatasource);
2021
2054
  }
2022
- throw new Error(`[ObjectQL] Datasource '${datasourceName}' configured for object '${objectName}' is not registered.`);
2023
2055
  }
2024
2056
  }
2025
- if (this.defaultDriver) {
2057
+ if (this.defaultDriver && this.drivers.has(this.defaultDriver)) {
2026
2058
  return this.drivers.get(this.defaultDriver);
2027
2059
  }
2028
2060
  throw new Error(`[ObjectQL] No driver available for object '${objectName}'`);
2029
2061
  }
2062
+ /**
2063
+ * Resolve datasource from mapping rules
2064
+ *
2065
+ * Rules are evaluated in order (or by priority if specified).
2066
+ * First matching rule wins.
2067
+ */
2068
+ resolveDatasourceFromMapping(objectName, object) {
2069
+ if (!this.datasourceMapping || this.datasourceMapping.length === 0) {
2070
+ return null;
2071
+ }
2072
+ const sortedRules = [...this.datasourceMapping].sort((a, b) => {
2073
+ const aPriority = a.priority ?? 1e3;
2074
+ const bPriority = b.priority ?? 1e3;
2075
+ return aPriority - bPriority;
2076
+ });
2077
+ for (const rule of sortedRules) {
2078
+ if (rule.namespace && object?.namespace === rule.namespace) {
2079
+ return rule.datasource;
2080
+ }
2081
+ if (rule.package && object?.packageId === rule.package) {
2082
+ return rule.datasource;
2083
+ }
2084
+ if (rule.objectPattern && this.matchPattern(objectName, rule.objectPattern)) {
2085
+ return rule.datasource;
2086
+ }
2087
+ if (rule.default) {
2088
+ return rule.datasource;
2089
+ }
2090
+ }
2091
+ return null;
2092
+ }
2093
+ /**
2094
+ * Simple glob pattern matching
2095
+ * Supports * (any chars) and ? (single char)
2096
+ */
2097
+ matchPattern(objectName, pattern) {
2098
+ const regexPattern = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*").replace(/\?/g, ".");
2099
+ const regex = new RegExp(`^${regexPattern}$`);
2100
+ return regex.test(objectName);
2101
+ }
2102
+ /**
2103
+ * Set datasource mapping rules
2104
+ * Called by ObjectQLPlugin during bootstrap
2105
+ */
2106
+ setDatasourceMapping(rules) {
2107
+ this.datasourceMapping = rules;
2108
+ this.logger.info("Datasource mapping rules configured", {
2109
+ ruleCount: rules.length
2110
+ });
2111
+ }
2030
2112
  /**
2031
2113
  * Initialize the engine and all registered drivers
2032
2114
  */