@objectstack/objectql 9.4.0 → 9.5.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.mjs CHANGED
@@ -2025,8 +2025,10 @@ var SysMetadataRepository = class {
2025
2025
  */
2026
2026
  async promoteDraft(ref, opts) {
2027
2027
  this.assertOpen();
2028
- const draft = await this.get(ref, { state: "draft" });
2029
- if (!draft) {
2028
+ const draftRow = await this.engine.findOne("sys_metadata", {
2029
+ where: this.whereFor(ref, "draft")
2030
+ });
2031
+ if (!draftRow) {
2030
2032
  const err = new Error(
2031
2033
  `[no_draft] No pending draft exists for ${ref.type}/${ref.name} \u2014 nothing to publish.`
2032
2034
  );
@@ -2034,7 +2036,9 @@ var SysMetadataRepository = class {
2034
2036
  err.status = 404;
2035
2037
  throw err;
2036
2038
  }
2037
- const currentActive = await this.get(ref, { state: "active" });
2039
+ const draftPackageId = draftRow.package_id ?? null;
2040
+ const draft = this.rowToItem(ref, draftRow);
2041
+ const currentActive = await this.get(ref, { state: "active", packageId: draftPackageId });
2038
2042
  const result = await this.put(ref, draft.body, {
2039
2043
  parentVersion: currentActive?.hash ?? null,
2040
2044
  actor: opts.actor,
@@ -2042,7 +2046,8 @@ var SysMetadataRepository = class {
2042
2046
  message: opts.message ?? `publish draft (hash ${draft.hash})`,
2043
2047
  intent: opts.intent ?? "override-artifact",
2044
2048
  state: "active",
2045
- opType: "publish"
2049
+ opType: "publish",
2050
+ packageId: draftPackageId
2046
2051
  });
2047
2052
  try {
2048
2053
  await this.delete(ref, {
@@ -2135,10 +2140,15 @@ var SysMetadataRepository = class {
2135
2140
  */
2136
2141
  async listDrafts(filter) {
2137
2142
  this.assertOpen();
2138
- const where = {
2139
- organization_id: this.organizationId,
2140
- state: "draft"
2141
- };
2143
+ const where = { state: "draft" };
2144
+ if (this.organizationId != null) {
2145
+ where.$or = [
2146
+ { organization_id: this.organizationId },
2147
+ { organization_id: null }
2148
+ ];
2149
+ } else {
2150
+ where.organization_id = null;
2151
+ }
2142
2152
  if (filter?.type) where.type = filter.type;
2143
2153
  if (filter?.packageId) where.package_id = filter.packageId;
2144
2154
  const rows = await this.engine.find("sys_metadata", { where });