@objectstack/objectql 7.2.0 → 7.2.1
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 +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +78 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// src/registry.ts
|
|
2
2
|
import { ObjectSchema } from "@objectstack/spec/data";
|
|
3
|
+
import { readEnvWithDeprecation } from "@objectstack/types";
|
|
3
4
|
import { ManifestSchema, InstalledPackageSchema } from "@objectstack/spec/kernel";
|
|
4
5
|
import { AppSchema } from "@objectstack/spec/ui";
|
|
6
|
+
import { applyProtection } from "@objectstack/spec/shared";
|
|
5
7
|
var RESERVED_NAMESPACES = /* @__PURE__ */ new Set(["base", "system"]);
|
|
6
8
|
var DEFAULT_OWNER_PRIORITY = 100;
|
|
7
9
|
var DEFAULT_EXTENDER_PRIORITY = 200;
|
|
@@ -129,7 +131,7 @@ var SchemaRegistry = class {
|
|
|
129
131
|
if (options.multiTenant !== void 0) {
|
|
130
132
|
this.multiTenant = options.multiTenant;
|
|
131
133
|
} else {
|
|
132
|
-
this.multiTenant = String(
|
|
134
|
+
this.multiTenant = String(readEnvWithDeprecation("OS_MULTI_ORG_ENABLED", "OS_MULTI_TENANT") ?? "false").toLowerCase() !== "false";
|
|
133
135
|
}
|
|
134
136
|
}
|
|
135
137
|
get logLevel() {
|
|
@@ -231,6 +233,7 @@ var SchemaRegistry = class {
|
|
|
231
233
|
contributors.splice(idx, 1);
|
|
232
234
|
}
|
|
233
235
|
}
|
|
236
|
+
applyProtection(schema, { packageId });
|
|
234
237
|
const contributor = {
|
|
235
238
|
packageId,
|
|
236
239
|
namespace: namespace || "",
|
|
@@ -378,9 +381,7 @@ var SchemaRegistry = class {
|
|
|
378
381
|
}
|
|
379
382
|
const collection = this.metadata.get(type);
|
|
380
383
|
const baseName = String(item[keyField]);
|
|
381
|
-
|
|
382
|
-
item._packageId = packageId;
|
|
383
|
-
}
|
|
384
|
+
applyProtection(item, { packageId });
|
|
384
385
|
try {
|
|
385
386
|
this.validate(type, item);
|
|
386
387
|
} catch (e) {
|
|
@@ -629,8 +630,12 @@ var SchemaRegistry = class {
|
|
|
629
630
|
}
|
|
630
631
|
};
|
|
631
632
|
|
|
633
|
+
// src/protocol.ts
|
|
634
|
+
import { readEnvWithDeprecation as readEnvWithDeprecation3 } from "@objectstack/types";
|
|
635
|
+
|
|
632
636
|
// src/sys-metadata-repository.ts
|
|
633
637
|
import { hashSpec, ConflictError } from "@objectstack/metadata-core";
|
|
638
|
+
import { readEnvWithDeprecation as readEnvWithDeprecation2 } from "@objectstack/types";
|
|
634
639
|
import { DEFAULT_METADATA_TYPE_REGISTRY } from "@objectstack/spec/kernel";
|
|
635
640
|
import { PLURAL_TO_SINGULAR, SINGULAR_TO_PLURAL } from "@objectstack/spec/shared";
|
|
636
641
|
var OVERLAY_ALLOWED_TYPES = new Set(
|
|
@@ -645,7 +650,7 @@ var RUNTIME_CREATE_ALLOWED_TYPES = new Set(
|
|
|
645
650
|
var _envWritableMetadataTypes = null;
|
|
646
651
|
function envWritableMetadataTypes() {
|
|
647
652
|
if (_envWritableMetadataTypes !== null) return _envWritableMetadataTypes;
|
|
648
|
-
const raw =
|
|
653
|
+
const raw = readEnvWithDeprecation2("OS_METADATA_WRITABLE", "OBJECTSTACK_METADATA_WRITABLE") || "";
|
|
649
654
|
const set = /* @__PURE__ */ new Set();
|
|
650
655
|
for (const tok of raw.split(",")) {
|
|
651
656
|
const t = tok.trim();
|
|
@@ -1172,7 +1177,7 @@ var SysMetadataRepository = class {
|
|
|
1172
1177
|
* at `(type, name)`. In that case we accept types with
|
|
1173
1178
|
* `allowRuntimeCreate: true`, even when `allowOrgOverride` is false.
|
|
1174
1179
|
*
|
|
1175
|
-
* The env-var escape hatch (`
|
|
1180
|
+
* The env-var escape hatch (`OS_METADATA_WRITABLE`) still
|
|
1176
1181
|
* applies to BOTH intents, so operators can opt into artifact
|
|
1177
1182
|
* overrides at runtime for emergency fixes.
|
|
1178
1183
|
*/
|
|
@@ -1197,7 +1202,7 @@ var SysMetadataRepository = class {
|
|
|
1197
1202
|
const code = intent === "runtime-only" ? "not_creatable" : "not_overridable";
|
|
1198
1203
|
const detail = intent === "runtime-only" ? `'${type}' has neither allowOrgOverride nor allowRuntimeCreate in the registry. ` : `'${type}' is not allowOrgOverride in the registry. `;
|
|
1199
1204
|
const err = new Error(
|
|
1200
|
-
`[${code}] ${detail}Overlay-allowed: ${Array.from(new Set(allowed)).join(", ") || "(none)"}. Set
|
|
1205
|
+
`[${code}] ${detail}Overlay-allowed: ${Array.from(new Set(allowed)).join(", ") || "(none)"}. Set OS_METADATA_WRITABLE to enable additional types at runtime.`
|
|
1201
1206
|
);
|
|
1202
1207
|
err.code = code;
|
|
1203
1208
|
err.status = 403;
|
|
@@ -1569,6 +1574,8 @@ function mergeArtifactProtection(item, artifactItem) {
|
|
|
1569
1574
|
const out = { ...item };
|
|
1570
1575
|
if (a._lock !== void 0) out._lock = a._lock;
|
|
1571
1576
|
if (a._lockReason !== void 0) out._lockReason = a._lockReason;
|
|
1577
|
+
if (a._lockDocsUrl !== void 0) out._lockDocsUrl = a._lockDocsUrl;
|
|
1578
|
+
if (a._lockSource !== void 0) out._lockSource = a._lockSource;
|
|
1572
1579
|
if (a._packageId !== void 0) out._packageId = a._packageId;
|
|
1573
1580
|
if (a._packageVersion !== void 0) out._packageVersion = a._packageVersion;
|
|
1574
1581
|
if (a._provenance !== void 0) out._provenance = a._provenance;
|
|
@@ -2080,10 +2087,13 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2080
2087
|
}
|
|
2081
2088
|
const items = Array.isArray(listed?.items) ? listed.items : Array.isArray(listed) ? listed : [];
|
|
2082
2089
|
const pkgSet = /* @__PURE__ */ new Set();
|
|
2090
|
+
let lockedCount = 0;
|
|
2083
2091
|
for (const item of items) {
|
|
2084
2092
|
scannedItems += 1;
|
|
2085
2093
|
const pkg = item?._packageId ?? null;
|
|
2086
2094
|
if (pkg) pkgSet.add(pkg);
|
|
2095
|
+
const lock = item?._lock;
|
|
2096
|
+
if (lock && lock !== "none") lockedCount += 1;
|
|
2087
2097
|
const diag = item?._diagnostics ?? computeMetadataDiagnostics(t, item);
|
|
2088
2098
|
if (!diag) continue;
|
|
2089
2099
|
if (diag.valid && !includeWarnings) continue;
|
|
@@ -2094,7 +2104,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2094
2104
|
diagnostics: diag
|
|
2095
2105
|
});
|
|
2096
2106
|
}
|
|
2097
|
-
stats[t] = { count: items.length, packages: [...pkgSet].sort() };
|
|
2107
|
+
stats[t] = { count: items.length, locked: lockedCount, packages: [...pkgSet].sort() };
|
|
2098
2108
|
}
|
|
2099
2109
|
return {
|
|
2100
2110
|
entries,
|
|
@@ -2295,6 +2305,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2295
2305
|
lock: lockState.lock,
|
|
2296
2306
|
...lockState.lockReason !== void 0 ? { lockReason: lockState.lockReason } : {},
|
|
2297
2307
|
...lockState.lockSource !== void 0 ? { lockSource: lockState.lockSource } : {},
|
|
2308
|
+
...lockState.lockDocsUrl !== void 0 ? { lockDocsUrl: lockState.lockDocsUrl } : {},
|
|
2298
2309
|
...lockState.provenance !== void 0 ? { provenance: lockState.provenance } : {},
|
|
2299
2310
|
...lockState.packageId !== void 0 ? { packageId: lockState.packageId } : {},
|
|
2300
2311
|
...lockState.packageVersion !== void 0 ? { packageVersion: lockState.packageVersion } : {},
|
|
@@ -2394,6 +2405,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2394
2405
|
lock: lockState.lock,
|
|
2395
2406
|
...lockState.lockReason !== void 0 ? { lockReason: lockState.lockReason } : {},
|
|
2396
2407
|
...lockState.lockSource !== void 0 ? { lockSource: lockState.lockSource } : {},
|
|
2408
|
+
...lockState.lockDocsUrl !== void 0 ? { lockDocsUrl: lockState.lockDocsUrl } : {},
|
|
2397
2409
|
...lockState.provenance !== void 0 ? { provenance: lockState.provenance } : {},
|
|
2398
2410
|
...lockState.packageId !== void 0 ? { packageId: lockState.packageId } : {},
|
|
2399
2411
|
...lockState.packageVersion !== void 0 ? { packageVersion: lockState.packageVersion } : {},
|
|
@@ -3326,7 +3338,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3326
3338
|
}
|
|
3327
3339
|
static envWritableTypes() {
|
|
3328
3340
|
if (this._envWritableTypes !== null) return this._envWritableTypes;
|
|
3329
|
-
const raw =
|
|
3341
|
+
const raw = readEnvWithDeprecation3("OS_METADATA_WRITABLE", "OBJECTSTACK_METADATA_WRITABLE") || "";
|
|
3330
3342
|
const set = /* @__PURE__ */ new Set();
|
|
3331
3343
|
for (const tok of raw.split(",")) {
|
|
3332
3344
|
const t = tok.trim();
|
|
@@ -3572,7 +3584,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3572
3584
|
const artifactBacked = this.isArtifactBacked(request.type, request.name);
|
|
3573
3585
|
if (artifactBacked && !overlayAllowed) {
|
|
3574
3586
|
const err = new Error(
|
|
3575
|
-
`[not_overridable] Metadata item '${request.type}/${request.name}' is provided by a code package and the type has not opted into per-org overlay writes (allowOrgOverride=false). Edit the source artifact and redeploy, or set
|
|
3587
|
+
`[not_overridable] Metadata item '${request.type}/${request.name}' is provided by a code package and the type has not opted into per-org overlay writes (allowOrgOverride=false). Edit the source artifact and redeploy, or set OS_METADATA_WRITABLE to grant a runtime escape hatch. See docs/adr/0005-metadata-customization-overlay.md.`
|
|
3576
3588
|
);
|
|
3577
3589
|
err.code = "not_overridable";
|
|
3578
3590
|
err.status = 403;
|
|
@@ -3622,6 +3634,18 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3622
3634
|
if (err?.code === "destructive_change") throw err;
|
|
3623
3635
|
}
|
|
3624
3636
|
}
|
|
3637
|
+
{
|
|
3638
|
+
const it = request.item;
|
|
3639
|
+
const looksLikeLayeredEnvelope = it && typeof it === "object" && !Array.isArray(it) && "code" in it && "overlay" in it && "overlayScope" in it && "effective" in it;
|
|
3640
|
+
if (looksLikeLayeredEnvelope) {
|
|
3641
|
+
const err = new Error(
|
|
3642
|
+
`[invalid_metadata] ${request.type}/${request.name}: the request body is a layered read envelope ({ code, overlay, overlayScope, effective }), not a metadata body. Unwrap and send the effective/overlay document instead \u2014 the layered shape is read-only (GET ?layers=true) and must never be persisted.`
|
|
3643
|
+
);
|
|
3644
|
+
err.code = "invalid_metadata";
|
|
3645
|
+
err.status = 422;
|
|
3646
|
+
throw err;
|
|
3647
|
+
}
|
|
3648
|
+
}
|
|
3625
3649
|
{
|
|
3626
3650
|
const schema = resolveOverlaySchema(request.type, request.item);
|
|
3627
3651
|
if (schema) {
|
|
@@ -4419,7 +4443,7 @@ _ObjectStackProtocolImplementation.OVERLAY_ALLOWED_TYPES = (() => {
|
|
|
4419
4443
|
return out;
|
|
4420
4444
|
})();
|
|
4421
4445
|
/**
|
|
4422
|
-
* Phase 3a-env-writable: parse `
|
|
4446
|
+
* Phase 3a-env-writable: parse `OS_METADATA_WRITABLE` once.
|
|
4423
4447
|
* Comma-separated singular type names. When the env var is set, the
|
|
4424
4448
|
* listed types get treated as `allowOrgOverride: true` regardless of
|
|
4425
4449
|
* their static registry entry. This is the runtime escape hatch admins
|