@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.d.mts
CHANGED
|
@@ -536,6 +536,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
536
536
|
*/
|
|
537
537
|
stats: Record<string, {
|
|
538
538
|
count: number;
|
|
539
|
+
locked: number;
|
|
539
540
|
packages: string[];
|
|
540
541
|
}>;
|
|
541
542
|
}>;
|
|
@@ -564,6 +565,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
564
565
|
packageVersion?: string | undefined;
|
|
565
566
|
packageId?: string | undefined;
|
|
566
567
|
provenance?: "package" | "env-forced" | "org" | undefined;
|
|
568
|
+
lockDocsUrl?: string | undefined;
|
|
567
569
|
lockSource?: "artifact" | "package" | "env-forced" | undefined;
|
|
568
570
|
lockReason?: string | undefined;
|
|
569
571
|
type: string;
|
|
@@ -609,6 +611,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
609
611
|
lock: MetadataLock;
|
|
610
612
|
lockReason?: string;
|
|
611
613
|
lockSource?: 'artifact' | 'package' | 'env-forced' | 'overlay';
|
|
614
|
+
lockDocsUrl?: string;
|
|
612
615
|
provenance?: MetadataProvenance;
|
|
613
616
|
packageId?: string;
|
|
614
617
|
packageVersion?: string;
|
|
@@ -865,7 +868,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
865
868
|
*/
|
|
866
869
|
private static readonly OVERLAY_ALLOWED_TYPES;
|
|
867
870
|
/**
|
|
868
|
-
* Phase 3a-env-writable: parse `
|
|
871
|
+
* Phase 3a-env-writable: parse `OS_METADATA_WRITABLE` once.
|
|
869
872
|
* Comma-separated singular type names. When the env var is set, the
|
|
870
873
|
* listed types get treated as `allowOrgOverride: true` regardless of
|
|
871
874
|
* their static registry entry. This is the runtime escape hatch admins
|
|
@@ -1346,7 +1349,7 @@ declare class SysMetadataRepository implements MetadataRepository {
|
|
|
1346
1349
|
* at `(type, name)`. In that case we accept types with
|
|
1347
1350
|
* `allowRuntimeCreate: true`, even when `allowOrgOverride` is false.
|
|
1348
1351
|
*
|
|
1349
|
-
* The env-var escape hatch (`
|
|
1352
|
+
* The env-var escape hatch (`OS_METADATA_WRITABLE`) still
|
|
1350
1353
|
* applies to BOTH intents, so operators can opt into artifact
|
|
1351
1354
|
* overrides at runtime for emergency fixes.
|
|
1352
1355
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -536,6 +536,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
536
536
|
*/
|
|
537
537
|
stats: Record<string, {
|
|
538
538
|
count: number;
|
|
539
|
+
locked: number;
|
|
539
540
|
packages: string[];
|
|
540
541
|
}>;
|
|
541
542
|
}>;
|
|
@@ -564,6 +565,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
564
565
|
packageVersion?: string | undefined;
|
|
565
566
|
packageId?: string | undefined;
|
|
566
567
|
provenance?: "package" | "env-forced" | "org" | undefined;
|
|
568
|
+
lockDocsUrl?: string | undefined;
|
|
567
569
|
lockSource?: "artifact" | "package" | "env-forced" | undefined;
|
|
568
570
|
lockReason?: string | undefined;
|
|
569
571
|
type: string;
|
|
@@ -609,6 +611,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
609
611
|
lock: MetadataLock;
|
|
610
612
|
lockReason?: string;
|
|
611
613
|
lockSource?: 'artifact' | 'package' | 'env-forced' | 'overlay';
|
|
614
|
+
lockDocsUrl?: string;
|
|
612
615
|
provenance?: MetadataProvenance;
|
|
613
616
|
packageId?: string;
|
|
614
617
|
packageVersion?: string;
|
|
@@ -865,7 +868,7 @@ declare class ObjectStackProtocolImplementation implements ObjectStackProtocol {
|
|
|
865
868
|
*/
|
|
866
869
|
private static readonly OVERLAY_ALLOWED_TYPES;
|
|
867
870
|
/**
|
|
868
|
-
* Phase 3a-env-writable: parse `
|
|
871
|
+
* Phase 3a-env-writable: parse `OS_METADATA_WRITABLE` once.
|
|
869
872
|
* Comma-separated singular type names. When the env var is set, the
|
|
870
873
|
* listed types get treated as `allowOrgOverride: true` regardless of
|
|
871
874
|
* their static registry entry. This is the runtime escape hatch admins
|
|
@@ -1346,7 +1349,7 @@ declare class SysMetadataRepository implements MetadataRepository {
|
|
|
1346
1349
|
* at `(type, name)`. In that case we accept types with
|
|
1347
1350
|
* `allowRuntimeCreate: true`, even when `allowOrgOverride` is false.
|
|
1348
1351
|
*
|
|
1349
|
-
* The env-var escape hatch (`
|
|
1352
|
+
* The env-var escape hatch (`OS_METADATA_WRITABLE`) still
|
|
1350
1353
|
* applies to BOTH intents, so operators can opt into artifact
|
|
1351
1354
|
* overrides at runtime for emergency fixes.
|
|
1352
1355
|
*/
|
package/dist/index.js
CHANGED
|
@@ -50,8 +50,10 @@ module.exports = __toCommonJS(index_exports);
|
|
|
50
50
|
|
|
51
51
|
// src/registry.ts
|
|
52
52
|
var import_data = require("@objectstack/spec/data");
|
|
53
|
+
var import_types = require("@objectstack/types");
|
|
53
54
|
var import_kernel = require("@objectstack/spec/kernel");
|
|
54
55
|
var import_ui = require("@objectstack/spec/ui");
|
|
56
|
+
var import_shared = require("@objectstack/spec/shared");
|
|
55
57
|
var RESERVED_NAMESPACES = /* @__PURE__ */ new Set(["base", "system"]);
|
|
56
58
|
var DEFAULT_OWNER_PRIORITY = 100;
|
|
57
59
|
var DEFAULT_EXTENDER_PRIORITY = 200;
|
|
@@ -179,7 +181,7 @@ var SchemaRegistry = class {
|
|
|
179
181
|
if (options.multiTenant !== void 0) {
|
|
180
182
|
this.multiTenant = options.multiTenant;
|
|
181
183
|
} else {
|
|
182
|
-
this.multiTenant = String(
|
|
184
|
+
this.multiTenant = String((0, import_types.readEnvWithDeprecation)("OS_MULTI_ORG_ENABLED", "OS_MULTI_TENANT") ?? "false").toLowerCase() !== "false";
|
|
183
185
|
}
|
|
184
186
|
}
|
|
185
187
|
get logLevel() {
|
|
@@ -281,6 +283,7 @@ var SchemaRegistry = class {
|
|
|
281
283
|
contributors.splice(idx, 1);
|
|
282
284
|
}
|
|
283
285
|
}
|
|
286
|
+
(0, import_shared.applyProtection)(schema, { packageId });
|
|
284
287
|
const contributor = {
|
|
285
288
|
packageId,
|
|
286
289
|
namespace: namespace || "",
|
|
@@ -428,9 +431,7 @@ var SchemaRegistry = class {
|
|
|
428
431
|
}
|
|
429
432
|
const collection = this.metadata.get(type);
|
|
430
433
|
const baseName = String(item[keyField]);
|
|
431
|
-
|
|
432
|
-
item._packageId = packageId;
|
|
433
|
-
}
|
|
434
|
+
(0, import_shared.applyProtection)(item, { packageId });
|
|
434
435
|
try {
|
|
435
436
|
this.validate(type, item);
|
|
436
437
|
} catch (e) {
|
|
@@ -679,10 +680,14 @@ var SchemaRegistry = class {
|
|
|
679
680
|
}
|
|
680
681
|
};
|
|
681
682
|
|
|
683
|
+
// src/protocol.ts
|
|
684
|
+
var import_types3 = require("@objectstack/types");
|
|
685
|
+
|
|
682
686
|
// src/sys-metadata-repository.ts
|
|
683
687
|
var import_metadata_core = require("@objectstack/metadata-core");
|
|
688
|
+
var import_types2 = require("@objectstack/types");
|
|
684
689
|
var import_kernel2 = require("@objectstack/spec/kernel");
|
|
685
|
-
var
|
|
690
|
+
var import_shared2 = require("@objectstack/spec/shared");
|
|
686
691
|
var OVERLAY_ALLOWED_TYPES = new Set(
|
|
687
692
|
import_kernel2.DEFAULT_METADATA_TYPE_REGISTRY.filter((e) => e.allowOrgOverride).map((e) => e.type)
|
|
688
693
|
);
|
|
@@ -695,14 +700,14 @@ var RUNTIME_CREATE_ALLOWED_TYPES = new Set(
|
|
|
695
700
|
var _envWritableMetadataTypes = null;
|
|
696
701
|
function envWritableMetadataTypes() {
|
|
697
702
|
if (_envWritableMetadataTypes !== null) return _envWritableMetadataTypes;
|
|
698
|
-
const raw =
|
|
703
|
+
const raw = (0, import_types2.readEnvWithDeprecation)("OS_METADATA_WRITABLE", "OBJECTSTACK_METADATA_WRITABLE") || "";
|
|
699
704
|
const set = /* @__PURE__ */ new Set();
|
|
700
705
|
for (const tok of raw.split(",")) {
|
|
701
706
|
const t = tok.trim();
|
|
702
707
|
if (!t) continue;
|
|
703
|
-
const singular =
|
|
708
|
+
const singular = import_shared2.PLURAL_TO_SINGULAR[t] ?? t;
|
|
704
709
|
set.add(singular);
|
|
705
|
-
const plural =
|
|
710
|
+
const plural = import_shared2.SINGULAR_TO_PLURAL[singular];
|
|
706
711
|
if (plural) set.add(plural);
|
|
707
712
|
}
|
|
708
713
|
_envWritableMetadataTypes = set;
|
|
@@ -1222,12 +1227,12 @@ var SysMetadataRepository = class {
|
|
|
1222
1227
|
* at `(type, name)`. In that case we accept types with
|
|
1223
1228
|
* `allowRuntimeCreate: true`, even when `allowOrgOverride` is false.
|
|
1224
1229
|
*
|
|
1225
|
-
* The env-var escape hatch (`
|
|
1230
|
+
* The env-var escape hatch (`OS_METADATA_WRITABLE`) still
|
|
1226
1231
|
* applies to BOTH intents, so operators can opt into artifact
|
|
1227
1232
|
* overrides at runtime for emergency fixes.
|
|
1228
1233
|
*/
|
|
1229
1234
|
assertAllowed(type, intent = "override-artifact") {
|
|
1230
|
-
const singular =
|
|
1235
|
+
const singular = import_shared2.PLURAL_TO_SINGULAR[type] ?? type;
|
|
1231
1236
|
const allowedByRegistry = OVERLAY_ALLOWED_TYPES.has(singular) || OVERLAY_ALLOWED_TYPES.has(type);
|
|
1232
1237
|
if (allowedByRegistry) return;
|
|
1233
1238
|
if (intent === "runtime-only") {
|
|
@@ -1247,7 +1252,7 @@ var SysMetadataRepository = class {
|
|
|
1247
1252
|
const code = intent === "runtime-only" ? "not_creatable" : "not_overridable";
|
|
1248
1253
|
const detail = intent === "runtime-only" ? `'${type}' has neither allowOrgOverride nor allowRuntimeCreate in the registry. ` : `'${type}' is not allowOrgOverride in the registry. `;
|
|
1249
1254
|
const err = new Error(
|
|
1250
|
-
`[${code}] ${detail}Overlay-allowed: ${Array.from(new Set(allowed)).join(", ") || "(none)"}. Set
|
|
1255
|
+
`[${code}] ${detail}Overlay-allowed: ${Array.from(new Set(allowed)).join(", ") || "(none)"}. Set OS_METADATA_WRITABLE to enable additional types at runtime.`
|
|
1251
1256
|
);
|
|
1252
1257
|
err.code = code;
|
|
1253
1258
|
err.status = 403;
|
|
@@ -1355,7 +1360,7 @@ var SysMetadataRepository = class {
|
|
|
1355
1360
|
// src/protocol.ts
|
|
1356
1361
|
var import_metadata_core2 = require("@objectstack/metadata-core");
|
|
1357
1362
|
var import_data2 = require("@objectstack/spec/data");
|
|
1358
|
-
var
|
|
1363
|
+
var import_shared4 = require("@objectstack/spec/shared");
|
|
1359
1364
|
var import_system = require("@objectstack/spec/system");
|
|
1360
1365
|
var import_kernel4 = require("@objectstack/spec/kernel");
|
|
1361
1366
|
var import_kernel5 = require("@objectstack/spec/kernel");
|
|
@@ -1363,9 +1368,9 @@ var import_zod = require("zod");
|
|
|
1363
1368
|
|
|
1364
1369
|
// src/metadata-diagnostics.ts
|
|
1365
1370
|
var import_kernel3 = require("@objectstack/spec/kernel");
|
|
1366
|
-
var
|
|
1371
|
+
var import_shared3 = require("@objectstack/spec/shared");
|
|
1367
1372
|
function computeMetadataDiagnostics(type, item) {
|
|
1368
|
-
const singular =
|
|
1373
|
+
const singular = import_shared3.PLURAL_TO_SINGULAR[type] ?? type;
|
|
1369
1374
|
const schema = (0, import_kernel3.getMetadataTypeSchema)(singular);
|
|
1370
1375
|
if (!schema) return void 0;
|
|
1371
1376
|
if (item === null || item === void 0 || typeof item !== "object") {
|
|
@@ -1603,7 +1608,7 @@ var HAND_CRAFTED_SCHEMAS = {
|
|
|
1603
1608
|
}
|
|
1604
1609
|
};
|
|
1605
1610
|
function resolveOverlaySchema(type, _item) {
|
|
1606
|
-
const singular =
|
|
1611
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[type] ?? type;
|
|
1607
1612
|
return (0, import_kernel4.getMetadataTypeSchema)(singular) ?? null;
|
|
1608
1613
|
}
|
|
1609
1614
|
function mergeArtifactProtection(item, artifactItem) {
|
|
@@ -1614,6 +1619,8 @@ function mergeArtifactProtection(item, artifactItem) {
|
|
|
1614
1619
|
const out = { ...item };
|
|
1615
1620
|
if (a._lock !== void 0) out._lock = a._lock;
|
|
1616
1621
|
if (a._lockReason !== void 0) out._lockReason = a._lockReason;
|
|
1622
|
+
if (a._lockDocsUrl !== void 0) out._lockDocsUrl = a._lockDocsUrl;
|
|
1623
|
+
if (a._lockSource !== void 0) out._lockSource = a._lockSource;
|
|
1617
1624
|
if (a._packageId !== void 0) out._packageId = a._packageId;
|
|
1618
1625
|
if (a._packageVersion !== void 0) out._packageVersion = a._packageVersion;
|
|
1619
1626
|
if (a._provenance !== void 0) out._provenance = a._provenance;
|
|
@@ -2044,7 +2051,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2044
2051
|
import_kernel4.DEFAULT_METADATA_TYPE_REGISTRY.map((e) => [e.type, e])
|
|
2045
2052
|
);
|
|
2046
2053
|
const entries = allTypes.map((type) => {
|
|
2047
|
-
const singular =
|
|
2054
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[type] ?? type;
|
|
2048
2055
|
const zodSchema = (0, import_kernel4.getMetadataTypeSchema)(singular);
|
|
2049
2056
|
const schema = (zodSchema ? toJsonSchemaSafe(zodSchema) : void 0) ?? HAND_CRAFTED_SCHEMAS[singular];
|
|
2050
2057
|
const form = TYPE_TO_FORM[singular];
|
|
@@ -2125,10 +2132,13 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2125
2132
|
}
|
|
2126
2133
|
const items = Array.isArray(listed?.items) ? listed.items : Array.isArray(listed) ? listed : [];
|
|
2127
2134
|
const pkgSet = /* @__PURE__ */ new Set();
|
|
2135
|
+
let lockedCount = 0;
|
|
2128
2136
|
for (const item of items) {
|
|
2129
2137
|
scannedItems += 1;
|
|
2130
2138
|
const pkg = item?._packageId ?? null;
|
|
2131
2139
|
if (pkg) pkgSet.add(pkg);
|
|
2140
|
+
const lock = item?._lock;
|
|
2141
|
+
if (lock && lock !== "none") lockedCount += 1;
|
|
2132
2142
|
const diag = item?._diagnostics ?? computeMetadataDiagnostics(t, item);
|
|
2133
2143
|
if (!diag) continue;
|
|
2134
2144
|
if (diag.valid && !includeWarnings) continue;
|
|
@@ -2139,7 +2149,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2139
2149
|
diagnostics: diag
|
|
2140
2150
|
});
|
|
2141
2151
|
}
|
|
2142
|
-
stats[t] = { count: items.length, packages: [...pkgSet].sort() };
|
|
2152
|
+
stats[t] = { count: items.length, locked: lockedCount, packages: [...pkgSet].sort() };
|
|
2143
2153
|
}
|
|
2144
2154
|
return {
|
|
2145
2155
|
entries,
|
|
@@ -2155,13 +2165,13 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2155
2165
|
if (this.environmentId === void 0) {
|
|
2156
2166
|
items = [...this.engine.registry.listItems(request.type, packageId)];
|
|
2157
2167
|
if (items.length === 0) {
|
|
2158
|
-
const alt =
|
|
2168
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2159
2169
|
if (alt) items = [...this.engine.registry.listItems(alt, packageId)];
|
|
2160
2170
|
}
|
|
2161
2171
|
} else {
|
|
2162
2172
|
items = [...this.engine.registry.listItems(request.type, packageId)];
|
|
2163
2173
|
if (items.length === 0) {
|
|
2164
|
-
const alt =
|
|
2174
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2165
2175
|
if (alt) items = [...this.engine.registry.listItems(alt, packageId)];
|
|
2166
2176
|
}
|
|
2167
2177
|
}
|
|
@@ -2176,7 +2186,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2176
2186
|
if (packageId) whereClause._packageId = packageId;
|
|
2177
2187
|
let rs = await this.engine.find("sys_metadata", { where: whereClause });
|
|
2178
2188
|
if (!rs || rs.length === 0) {
|
|
2179
|
-
const alt =
|
|
2189
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2180
2190
|
if (alt) {
|
|
2181
2191
|
const altWhere = { type: alt, state: "active", organization_id: oid };
|
|
2182
2192
|
if (packageId) altWhere._packageId = packageId;
|
|
@@ -2269,7 +2279,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2269
2279
|
};
|
|
2270
2280
|
const rec = await this.engine.findOne("sys_metadata", { where });
|
|
2271
2281
|
if (rec) return rec;
|
|
2272
|
-
const alt =
|
|
2282
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2273
2283
|
if (alt) {
|
|
2274
2284
|
const altWhere = {
|
|
2275
2285
|
type: alt,
|
|
@@ -2307,7 +2317,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2307
2317
|
if (fromService !== void 0 && fromService !== null) {
|
|
2308
2318
|
item = fromService;
|
|
2309
2319
|
} else {
|
|
2310
|
-
const alt =
|
|
2320
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2311
2321
|
if (alt) {
|
|
2312
2322
|
const altFromService = await metadataService.get(alt, request.name);
|
|
2313
2323
|
if (altFromService !== void 0 && altFromService !== null) {
|
|
@@ -2322,7 +2332,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2322
2332
|
if (item === void 0) {
|
|
2323
2333
|
item = this.engine.registry.getItem(request.type, request.name);
|
|
2324
2334
|
if (item === void 0) {
|
|
2325
|
-
const alt =
|
|
2335
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2326
2336
|
if (alt) item = this.engine.registry.getItem(alt, request.name);
|
|
2327
2337
|
}
|
|
2328
2338
|
}
|
|
@@ -2340,6 +2350,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2340
2350
|
lock: lockState.lock,
|
|
2341
2351
|
...lockState.lockReason !== void 0 ? { lockReason: lockState.lockReason } : {},
|
|
2342
2352
|
...lockState.lockSource !== void 0 ? { lockSource: lockState.lockSource } : {},
|
|
2353
|
+
...lockState.lockDocsUrl !== void 0 ? { lockDocsUrl: lockState.lockDocsUrl } : {},
|
|
2343
2354
|
...lockState.provenance !== void 0 ? { provenance: lockState.provenance } : {},
|
|
2344
2355
|
...lockState.packageId !== void 0 ? { packageId: lockState.packageId } : {},
|
|
2345
2356
|
...lockState.packageVersion !== void 0 ? { packageVersion: lockState.packageVersion } : {},
|
|
@@ -2371,7 +2382,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2371
2382
|
if (metadataService && typeof metadataService.get === "function") {
|
|
2372
2383
|
let fromService = await metadataService.get(request.type, request.name);
|
|
2373
2384
|
if (fromService === void 0 || fromService === null) {
|
|
2374
|
-
const alt =
|
|
2385
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2375
2386
|
if (alt) fromService = await metadataService.get(alt, request.name);
|
|
2376
2387
|
}
|
|
2377
2388
|
if (fromService !== void 0 && fromService !== null) code = fromService;
|
|
@@ -2381,7 +2392,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2381
2392
|
if (code === null) {
|
|
2382
2393
|
let regItem = this.engine.registry.getItem(request.type, request.name);
|
|
2383
2394
|
if (regItem === void 0) {
|
|
2384
|
-
const alt =
|
|
2395
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2385
2396
|
if (alt) regItem = this.engine.registry.getItem(alt, request.name);
|
|
2386
2397
|
}
|
|
2387
2398
|
if (regItem !== void 0) code = regItem;
|
|
@@ -2398,7 +2409,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2398
2409
|
};
|
|
2399
2410
|
let rec = await this.engine.findOne("sys_metadata", { where });
|
|
2400
2411
|
if (!rec) {
|
|
2401
|
-
const alt =
|
|
2412
|
+
const alt = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? import_shared4.SINGULAR_TO_PLURAL[request.type];
|
|
2402
2413
|
if (alt) {
|
|
2403
2414
|
rec = await this.engine.findOne("sys_metadata", {
|
|
2404
2415
|
where: { ...where, type: alt }
|
|
@@ -2439,6 +2450,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2439
2450
|
lock: lockState.lock,
|
|
2440
2451
|
...lockState.lockReason !== void 0 ? { lockReason: lockState.lockReason } : {},
|
|
2441
2452
|
...lockState.lockSource !== void 0 ? { lockSource: lockState.lockSource } : {},
|
|
2453
|
+
...lockState.lockDocsUrl !== void 0 ? { lockDocsUrl: lockState.lockDocsUrl } : {},
|
|
2442
2454
|
...lockState.provenance !== void 0 ? { provenance: lockState.provenance } : {},
|
|
2443
2455
|
...lockState.packageId !== void 0 ? { packageId: lockState.packageId } : {},
|
|
2444
2456
|
...lockState.packageVersion !== void 0 ? { packageVersion: lockState.packageVersion } : {},
|
|
@@ -2462,7 +2474,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
2462
2474
|
* raising, keeping the Studio tab harmless.
|
|
2463
2475
|
*/
|
|
2464
2476
|
async auditMetaItem(request) {
|
|
2465
|
-
const singular =
|
|
2477
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
2466
2478
|
const limit = Math.min(
|
|
2467
2479
|
Math.max(1, request.limit ?? 100),
|
|
2468
2480
|
500
|
|
@@ -3371,14 +3383,14 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3371
3383
|
}
|
|
3372
3384
|
static envWritableTypes() {
|
|
3373
3385
|
if (this._envWritableTypes !== null) return this._envWritableTypes;
|
|
3374
|
-
const raw =
|
|
3386
|
+
const raw = (0, import_types3.readEnvWithDeprecation)("OS_METADATA_WRITABLE", "OBJECTSTACK_METADATA_WRITABLE") || "";
|
|
3375
3387
|
const set = /* @__PURE__ */ new Set();
|
|
3376
3388
|
for (const tok of raw.split(",")) {
|
|
3377
3389
|
const t = tok.trim();
|
|
3378
3390
|
if (!t) continue;
|
|
3379
|
-
const singular =
|
|
3391
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[t] ?? t;
|
|
3380
3392
|
set.add(singular);
|
|
3381
|
-
const plural =
|
|
3393
|
+
const plural = import_shared4.SINGULAR_TO_PLURAL[singular];
|
|
3382
3394
|
if (plural) set.add(plural);
|
|
3383
3395
|
}
|
|
3384
3396
|
this._envWritableTypes = set;
|
|
@@ -3390,7 +3402,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3390
3402
|
}
|
|
3391
3403
|
/** Normalize plural→singular before consulting the allow-list. */
|
|
3392
3404
|
static isOverlayAllowed(type) {
|
|
3393
|
-
const singular =
|
|
3405
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[type] ?? type;
|
|
3394
3406
|
if (this.OVERLAY_ALLOWED_TYPES.has(singular) || this.OVERLAY_ALLOWED_TYPES.has(type)) {
|
|
3395
3407
|
return true;
|
|
3396
3408
|
}
|
|
@@ -3399,7 +3411,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3399
3411
|
}
|
|
3400
3412
|
/** Does this type permit creating brand-new (artifact-free) items? */
|
|
3401
3413
|
static isRuntimeCreateAllowed(type) {
|
|
3402
|
-
const singular =
|
|
3414
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[type] ?? type;
|
|
3403
3415
|
if (this.RUNTIME_CREATE_ALLOWED_TYPES.has(singular) || this.RUNTIME_CREATE_ALLOWED_TYPES.has(type)) {
|
|
3404
3416
|
return true;
|
|
3405
3417
|
}
|
|
@@ -3428,7 +3440,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3428
3440
|
if (!registry || typeof registry.getItem !== "function") {
|
|
3429
3441
|
return false;
|
|
3430
3442
|
}
|
|
3431
|
-
const singular =
|
|
3443
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[type] ?? type;
|
|
3432
3444
|
const item = registry.getItem(singular, name) ?? registry.getItem(type, name);
|
|
3433
3445
|
if (!item || !item._packageId) return false;
|
|
3434
3446
|
return item._packageId !== "sys_metadata";
|
|
@@ -3444,7 +3456,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3444
3456
|
lookupArtifactItem(type, name) {
|
|
3445
3457
|
const registry = this.engine?.registry;
|
|
3446
3458
|
if (!registry || typeof registry.getItem !== "function") return void 0;
|
|
3447
|
-
const singular =
|
|
3459
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[type] ?? type;
|
|
3448
3460
|
return registry.getItem(singular, name) ?? registry.getItem(type, name);
|
|
3449
3461
|
}
|
|
3450
3462
|
/**
|
|
@@ -3460,7 +3472,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3460
3472
|
*/
|
|
3461
3473
|
async getEffectiveLock(type, name, organizationId) {
|
|
3462
3474
|
const registry = this.engine?.registry;
|
|
3463
|
-
const singular =
|
|
3475
|
+
const singular = import_shared4.PLURAL_TO_SINGULAR[type] ?? type;
|
|
3464
3476
|
let artifactItem;
|
|
3465
3477
|
if (registry && typeof registry.getItem === "function") {
|
|
3466
3478
|
artifactItem = registry.getItem(singular, name) ?? registry.getItem(type, name);
|
|
@@ -3504,7 +3516,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3504
3516
|
occurred_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3505
3517
|
actor: entry.actor ?? "system",
|
|
3506
3518
|
source: entry.source ?? "protocol",
|
|
3507
|
-
type:
|
|
3519
|
+
type: import_shared4.PLURAL_TO_SINGULAR[entry.type] ?? entry.type,
|
|
3508
3520
|
name: entry.name,
|
|
3509
3521
|
organization_id: entry.organizationId ?? null,
|
|
3510
3522
|
operation: entry.operation,
|
|
@@ -3617,7 +3629,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3617
3629
|
const artifactBacked = this.isArtifactBacked(request.type, request.name);
|
|
3618
3630
|
if (artifactBacked && !overlayAllowed) {
|
|
3619
3631
|
const err = new Error(
|
|
3620
|
-
`[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
|
|
3632
|
+
`[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.`
|
|
3621
3633
|
);
|
|
3622
3634
|
err.code = "not_overridable";
|
|
3623
3635
|
err.status = 403;
|
|
@@ -3641,7 +3653,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3641
3653
|
});
|
|
3642
3654
|
if (lockErr) throw lockErr;
|
|
3643
3655
|
}
|
|
3644
|
-
const singularType =
|
|
3656
|
+
const singularType = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
3645
3657
|
if (!request.force && (singularType === "object" || singularType === "field")) {
|
|
3646
3658
|
try {
|
|
3647
3659
|
const existing = await this.getMetaItem({
|
|
@@ -3667,6 +3679,18 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3667
3679
|
if (err?.code === "destructive_change") throw err;
|
|
3668
3680
|
}
|
|
3669
3681
|
}
|
|
3682
|
+
{
|
|
3683
|
+
const it = request.item;
|
|
3684
|
+
const looksLikeLayeredEnvelope = it && typeof it === "object" && !Array.isArray(it) && "code" in it && "overlay" in it && "overlayScope" in it && "effective" in it;
|
|
3685
|
+
if (looksLikeLayeredEnvelope) {
|
|
3686
|
+
const err = new Error(
|
|
3687
|
+
`[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.`
|
|
3688
|
+
);
|
|
3689
|
+
err.code = "invalid_metadata";
|
|
3690
|
+
err.status = 422;
|
|
3691
|
+
throw err;
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3670
3694
|
{
|
|
3671
3695
|
const schema = resolveOverlaySchema(request.type, request.item);
|
|
3672
3696
|
if (schema) {
|
|
@@ -3689,7 +3713,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3689
3713
|
}
|
|
3690
3714
|
}
|
|
3691
3715
|
await this.ensureOverlayIndex();
|
|
3692
|
-
const singularTypeForRepo =
|
|
3716
|
+
const singularTypeForRepo = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
3693
3717
|
const overlayAllowedForRepo = _ObjectStackProtocolImplementation.isOverlayAllowed(singularTypeForRepo);
|
|
3694
3718
|
const runtimeCreateAllowedForRepo = _ObjectStackProtocolImplementation.isRuntimeCreateAllowed(singularTypeForRepo);
|
|
3695
3719
|
const useRepoPath = overlayAllowedForRepo || runtimeCreateAllowedForRepo;
|
|
@@ -3821,7 +3845,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3821
3845
|
* "no history" uniformly.
|
|
3822
3846
|
*/
|
|
3823
3847
|
async historyMetaItem(request) {
|
|
3824
|
-
const singularType =
|
|
3848
|
+
const singularType = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
3825
3849
|
if (!_ObjectStackProtocolImplementation.isOverlayAllowed(singularType) && !_ObjectStackProtocolImplementation.isRuntimeCreateAllowed(singularType)) {
|
|
3826
3850
|
return { events: [] };
|
|
3827
3851
|
}
|
|
@@ -3845,7 +3869,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3845
3869
|
* when there is nothing to publish.
|
|
3846
3870
|
*/
|
|
3847
3871
|
async publishMetaItem(request) {
|
|
3848
|
-
const singularType =
|
|
3872
|
+
const singularType = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
3849
3873
|
if (!_ObjectStackProtocolImplementation.isOverlayAllowed(singularType) && !_ObjectStackProtocolImplementation.isRuntimeCreateAllowed(singularType)) {
|
|
3850
3874
|
const err = new Error(
|
|
3851
3875
|
`[not_overridable] Metadata type '${request.type}' is not draftable \u2014 no overlay/runtime-create permission.`
|
|
@@ -3921,7 +3945,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3921
3945
|
err.status = 400;
|
|
3922
3946
|
throw err;
|
|
3923
3947
|
}
|
|
3924
|
-
const singularType =
|
|
3948
|
+
const singularType = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
3925
3949
|
if (!_ObjectStackProtocolImplementation.isOverlayAllowed(singularType) && !_ObjectStackProtocolImplementation.isRuntimeCreateAllowed(singularType)) {
|
|
3926
3950
|
const err = new Error(
|
|
3927
3951
|
`[not_overridable] Metadata type '${request.type}' is not revertable \u2014 no overlay/runtime-create permission.`
|
|
@@ -3992,7 +4016,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
3992
4016
|
* are reported as a single change record.
|
|
3993
4017
|
*/
|
|
3994
4018
|
async diffMetaItem(request) {
|
|
3995
|
-
const singularType =
|
|
4019
|
+
const singularType = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
3996
4020
|
const orgId = request.organizationId ?? null;
|
|
3997
4021
|
const events = (await this.historyMetaItem({
|
|
3998
4022
|
type: singularType,
|
|
@@ -4094,7 +4118,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
4094
4118
|
});
|
|
4095
4119
|
if (lockErr) throw lockErr;
|
|
4096
4120
|
}
|
|
4097
|
-
const singularTypeForRepo =
|
|
4121
|
+
const singularTypeForRepo = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
4098
4122
|
const overlayAllowedForRepoDel = _ObjectStackProtocolImplementation.isOverlayAllowed(singularTypeForRepo);
|
|
4099
4123
|
const runtimeCreateAllowedForRepoDel = _ObjectStackProtocolImplementation.isRuntimeCreateAllowed(singularTypeForRepo);
|
|
4100
4124
|
const useRepoPath = overlayAllowedForRepoDel || runtimeCreateAllowedForRepoDel;
|
|
@@ -4230,7 +4254,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
4230
4254
|
for (const record of records) {
|
|
4231
4255
|
try {
|
|
4232
4256
|
const data = typeof record.metadata === "string" ? JSON.parse(record.metadata) : record.metadata;
|
|
4233
|
-
const normalizedType =
|
|
4257
|
+
const normalizedType = import_shared4.PLURAL_TO_SINGULAR[record.type] ?? record.type;
|
|
4234
4258
|
if (normalizedType === "object") {
|
|
4235
4259
|
this.engine.registry.registerObject(data, record.packageId || "sys_metadata");
|
|
4236
4260
|
} else {
|
|
@@ -4264,7 +4288,7 @@ var _ObjectStackProtocolImplementation = class _ObjectStackProtocolImplementatio
|
|
|
4264
4288
|
* — the engine never throws.
|
|
4265
4289
|
*/
|
|
4266
4290
|
async findReferencesToMeta(request) {
|
|
4267
|
-
const singularTarget =
|
|
4291
|
+
const singularTarget = import_shared4.PLURAL_TO_SINGULAR[request.type] ?? request.type;
|
|
4268
4292
|
const targetName = request.name;
|
|
4269
4293
|
const matchers = REFERENCE_PATHS[singularTarget];
|
|
4270
4294
|
if (!matchers || matchers.length === 0) {
|
|
@@ -4458,13 +4482,13 @@ _ObjectStackProtocolImplementation.OVERLAY_ALLOWED_TYPES = (() => {
|
|
|
4458
4482
|
for (const entry of import_kernel4.DEFAULT_METADATA_TYPE_REGISTRY) {
|
|
4459
4483
|
if (!entry.allowOrgOverride) continue;
|
|
4460
4484
|
out.add(entry.type);
|
|
4461
|
-
const plural =
|
|
4485
|
+
const plural = import_shared4.SINGULAR_TO_PLURAL[entry.type];
|
|
4462
4486
|
if (plural) out.add(plural);
|
|
4463
4487
|
}
|
|
4464
4488
|
return out;
|
|
4465
4489
|
})();
|
|
4466
4490
|
/**
|
|
4467
|
-
* Phase 3a-env-writable: parse `
|
|
4491
|
+
* Phase 3a-env-writable: parse `OS_METADATA_WRITABLE` once.
|
|
4468
4492
|
* Comma-separated singular type names. When the env var is set, the
|
|
4469
4493
|
* listed types get treated as `allowOrgOverride: true` regardless of
|
|
4470
4494
|
* their static registry entry. This is the runtime escape hatch admins
|
|
@@ -4495,7 +4519,7 @@ _ObjectStackProtocolImplementation.STATIC_REGISTRY_TYPES = (() => {
|
|
|
4495
4519
|
const out = /* @__PURE__ */ new Set();
|
|
4496
4520
|
for (const entry of import_kernel4.DEFAULT_METADATA_TYPE_REGISTRY) {
|
|
4497
4521
|
out.add(entry.type);
|
|
4498
|
-
const plural =
|
|
4522
|
+
const plural = import_shared4.SINGULAR_TO_PLURAL[entry.type];
|
|
4499
4523
|
if (plural) out.add(plural);
|
|
4500
4524
|
}
|
|
4501
4525
|
return out;
|
|
@@ -4505,7 +4529,7 @@ _ObjectStackProtocolImplementation.RUNTIME_CREATE_ALLOWED_TYPES = (() => {
|
|
|
4505
4529
|
for (const entry of import_kernel4.DEFAULT_METADATA_TYPE_REGISTRY) {
|
|
4506
4530
|
if (!entry.allowRuntimeCreate) continue;
|
|
4507
4531
|
out.add(entry.type);
|
|
4508
|
-
const plural =
|
|
4532
|
+
const plural = import_shared4.SINGULAR_TO_PLURAL[entry.type];
|
|
4509
4533
|
if (plural) out.add(plural);
|
|
4510
4534
|
}
|
|
4511
4535
|
return out;
|
|
@@ -4516,7 +4540,7 @@ var ObjectStackProtocolImplementation = _ObjectStackProtocolImplementation;
|
|
|
4516
4540
|
var import_kernel6 = require("@objectstack/spec/kernel");
|
|
4517
4541
|
var import_core = require("@objectstack/core");
|
|
4518
4542
|
var import_system2 = require("@objectstack/spec/system");
|
|
4519
|
-
var
|
|
4543
|
+
var import_shared5 = require("@objectstack/spec/shared");
|
|
4520
4544
|
var import_formula2 = require("@objectstack/formula");
|
|
4521
4545
|
|
|
4522
4546
|
// src/hook-wrappers.ts
|
|
@@ -5787,9 +5811,9 @@ var _ObjectQL = class _ObjectQL {
|
|
|
5787
5811
|
const itemName = resolveMetadataItemName(key, item);
|
|
5788
5812
|
if (itemName) {
|
|
5789
5813
|
const toRegister = item.name === itemName ? item : { ...item, name: itemName };
|
|
5790
|
-
this._registry.registerItem((0,
|
|
5814
|
+
this._registry.registerItem((0, import_shared5.pluralToSingular)(key), toRegister, "name", id);
|
|
5791
5815
|
} else {
|
|
5792
|
-
this.logger.warn(`Skipping ${(0,
|
|
5816
|
+
this.logger.warn(`Skipping ${(0, import_shared5.pluralToSingular)(key)} without a derivable name`, { id });
|
|
5793
5817
|
}
|
|
5794
5818
|
}
|
|
5795
5819
|
}
|
|
@@ -5916,7 +5940,7 @@ var _ObjectQL = class _ObjectQL {
|
|
|
5916
5940
|
const itemName = resolveMetadataItemName(key, item);
|
|
5917
5941
|
if (itemName) {
|
|
5918
5942
|
const toRegister = item.name === itemName ? item : { ...item, name: itemName };
|
|
5919
|
-
this._registry.registerItem((0,
|
|
5943
|
+
this._registry.registerItem((0, import_shared5.pluralToSingular)(key), toRegister, "name", ownerId);
|
|
5920
5944
|
}
|
|
5921
5945
|
}
|
|
5922
5946
|
}
|