@ai-matrx/content-ir 0.19.21 → 0.19.26
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/CHANGELOG.md +29 -0
- package/dist/convert.cjs +158 -6
- package/dist/convert.cjs.map +1 -1
- package/dist/convert.d.cts +71 -2
- package/dist/convert.d.ts +71 -2
- package/dist/convert.js +152 -7
- package/dist/convert.js.map +1 -1
- package/dist/core.cjs +19 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +19 -1
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +159 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +152 -7
- package/dist/index.js.map +1 -1
- package/dist/registry.d.cts +1 -1
- package/dist/registry.d.ts +1 -1
- package/dist/source.cjs +1 -0
- package/dist/source.d.cts +9 -1
- package/dist/source.d.ts +9 -1
- package/dist/source.js +1 -1
- package/dist/text-case.cjs +322 -0
- package/dist/text-case.cjs.map +1 -0
- package/dist/text-case.d.cts +81 -0
- package/dist/text-case.d.ts +81 -0
- package/dist/text-case.js +309 -0
- package/dist/text-case.js.map +1 -0
- package/dist/wire.cjs.map +1 -1
- package/dist/wire.d.cts +2 -2
- package/dist/wire.d.ts +2 -2
- package/dist/wire.js.map +1 -1
- package/package.json +11 -1
package/dist/convert.d.cts
CHANGED
|
@@ -219,12 +219,81 @@ type KindSchemaFromJsonResult = {
|
|
|
219
219
|
/** Conversion notes. `severity: "error"` entries are worth screaming about. */
|
|
220
220
|
problems: ConversionProblem[];
|
|
221
221
|
};
|
|
222
|
+
type KindSchemaFromJsonOptions = {
|
|
223
|
+
/**
|
|
224
|
+
* The registry row's `metadata.disposition`. A `record` kind's schema gains the four
|
|
225
|
+
* control keys (`_replaces`, `_new`, `_record_id`, `_records`) as optional render fields
|
|
226
|
+
* (`withControlKeys`, KINDS-GLUE wave 2 §1.4), so an agent's patch, batch or signal draws
|
|
227
|
+
* through its kind instead of reading as unknown keys. Any other value adds nothing.
|
|
228
|
+
*/
|
|
229
|
+
disposition?: string | null;
|
|
230
|
+
};
|
|
222
231
|
/**
|
|
223
232
|
* Derive `kind`'s field schema from its JSON Schema.
|
|
224
233
|
*
|
|
225
234
|
* Pure and synchronous — no registry, no IO — so a host can call it from a
|
|
226
235
|
* warm load, a cold fetch, a reducer, or a test.
|
|
227
236
|
*/
|
|
228
|
-
declare function kindSchemaFromJsonSchema(kind: string, jsonSchema: unknown): KindSchemaFromJsonResult;
|
|
237
|
+
declare function kindSchemaFromJsonSchema(kind: string, jsonSchema: unknown, options?: KindSchemaFromJsonOptions): KindSchemaFromJsonResult;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The four control keys an agent may put beside a kind's values — the TypeScript twin of
|
|
241
|
+
* `matrx_graph.kind_control_keys.with_control_keys` (aidream). ONE definition, two languages:
|
|
242
|
+
* for the same input both produce the same JSON (guard W2-G7, the shared golden
|
|
243
|
+
* `packages/matrx-graph/tests/fixtures/kind_control_keys_golden.json`).
|
|
244
|
+
*
|
|
245
|
+
* `_replaces` ("this replaces that output"), `_new` ("this is something new"), `_record_id`
|
|
246
|
+
* ("change this record") and `_records` ("several records") are never part of a kind and no
|
|
247
|
+
* registry row carries them — they are added where a schema is USED, for `record` kinds and
|
|
248
|
+
* table kinds only:
|
|
249
|
+
*
|
|
250
|
+
* - `withControlKeys(schema, { mode: "stored" })` — the JSON Schema a value is validated
|
|
251
|
+
* against: all four declared optional (nullable), and the root's required Fields lifted when
|
|
252
|
+
* the value is a patch (`_record_id`) or a batch (`_records`) — one branch APPENDED to `allOf`,
|
|
253
|
+
* never replacing it.
|
|
254
|
+
* - `withControlKeys(schema, { mode: "authored", many, allowEdit })` — what the model is shown:
|
|
255
|
+
* `_replaces`/`_new` always, `_record_id` only with `allowEdit`, and with `many` the root is
|
|
256
|
+
* the batch `{__kind, _records: [<record without __kind>], ...}`. Signals are OPTIONAL — the
|
|
257
|
+
* provider translators widen them to required-and-nullable on the wire and prune a null back.
|
|
258
|
+
* - `withControlKeyFields(kindSchema)` — the render-level twin: the four keys as optional
|
|
259
|
+
* render fields of a `KindSchema`, so a patch, a batch or a signal is drawn by its kind's
|
|
260
|
+
* component instead of being reported as unknown keys. The web schema is never stricter
|
|
261
|
+
* than the store.
|
|
262
|
+
*
|
|
263
|
+
* Design: common-docs `projects/data-doctrine-adoption/v6/KINDS-GLUE-WAVE2-DESIGN.md` §1.4.
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
/** The four keys, in the order they are declared. */
|
|
267
|
+
declare const CONTROL_KEYS: readonly ["_replaces", "_new", "_record_id", "_records"];
|
|
268
|
+
type ControlKey = (typeof CONTROL_KEYS)[number];
|
|
269
|
+
/** The one disposition whose kinds take the control keys (table kinds are always `record`). */
|
|
270
|
+
declare const RECORD_DISPOSITION = "record";
|
|
271
|
+
type ControlKeysMode = "stored" | "authored";
|
|
272
|
+
type WithControlKeysOptions = {
|
|
273
|
+
mode: ControlKeysMode;
|
|
274
|
+
/** Authored mode: the root becomes the batch `{__kind, _records: [...]}`. */
|
|
275
|
+
many?: boolean;
|
|
276
|
+
/** Authored mode: the model may name `_record_id` (the run may edit its own outputs). */
|
|
277
|
+
allowEdit?: boolean;
|
|
278
|
+
};
|
|
279
|
+
/** Whether a kind with this disposition takes the control keys. */
|
|
280
|
+
declare function controlKeysApplyTo(disposition: string | null | undefined): boolean;
|
|
281
|
+
/**
|
|
282
|
+
* A copy of `schema` that carries the control keys for `mode`. A schema that is not an object
|
|
283
|
+
* with `properties` (a root-form kind, the "any value" `{}`) is returned unchanged.
|
|
284
|
+
*/
|
|
285
|
+
declare function withControlKeys<T>(schema: T, options: WithControlKeysOptions): T;
|
|
286
|
+
/** The render fields the control keys add to a `KindSchema` — all optional, none stricter than the store. */
|
|
287
|
+
declare const CONTROL_KEY_FIELDS: Readonly<Record<ControlKey, FieldSchema>>;
|
|
288
|
+
/**
|
|
289
|
+
* `schema` with the four control keys as optional render fields. A root-form kind (no field
|
|
290
|
+
* map) is returned unchanged. Keys the kind itself declares are left as the kind declares them.
|
|
291
|
+
*/
|
|
292
|
+
declare function withControlKeyFields(schema: KindSchema): KindSchema;
|
|
293
|
+
/** Split a value into (values without the control keys, the control keys present). */
|
|
294
|
+
declare function stripControlKeys(value: Record<string, unknown>): {
|
|
295
|
+
values: Record<string, unknown>;
|
|
296
|
+
signals: Partial<Record<ControlKey, unknown>>;
|
|
297
|
+
};
|
|
229
298
|
|
|
230
|
-
export { type ArrayItemKindBinding, type BlockSchemaDraft, type ConversionProblem, type DroppedMetadata, type FieldComparison, type ItemKindRefCheck, type JsonSchemaNode, type KindJsonSchemaExport, type KindJsonSchemaOptions, type KindSchemaFromJsonResult, type SavePlanEntry, type SavePlanValidation, type SchemaConversionResult, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, validateBlockSchemaSavePlan };
|
|
299
|
+
export { type ArrayItemKindBinding, type BlockSchemaDraft, CONTROL_KEYS, CONTROL_KEY_FIELDS, type ControlKey, type ControlKeysMode, type ConversionProblem, type DroppedMetadata, type FieldComparison, type ItemKindRefCheck, type JsonSchemaNode, type KindJsonSchemaExport, type KindJsonSchemaOptions, type KindSchemaFromJsonOptions, type KindSchemaFromJsonResult, RECORD_DISPOSITION, type SavePlanEntry, type SavePlanValidation, type SchemaConversionResult, type WithControlKeysOptions, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, controlKeysApplyTo, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, stripControlKeys, validateBlockSchemaSavePlan, withControlKeyFields, withControlKeys };
|
package/dist/convert.d.ts
CHANGED
|
@@ -219,12 +219,81 @@ type KindSchemaFromJsonResult = {
|
|
|
219
219
|
/** Conversion notes. `severity: "error"` entries are worth screaming about. */
|
|
220
220
|
problems: ConversionProblem[];
|
|
221
221
|
};
|
|
222
|
+
type KindSchemaFromJsonOptions = {
|
|
223
|
+
/**
|
|
224
|
+
* The registry row's `metadata.disposition`. A `record` kind's schema gains the four
|
|
225
|
+
* control keys (`_replaces`, `_new`, `_record_id`, `_records`) as optional render fields
|
|
226
|
+
* (`withControlKeys`, KINDS-GLUE wave 2 §1.4), so an agent's patch, batch or signal draws
|
|
227
|
+
* through its kind instead of reading as unknown keys. Any other value adds nothing.
|
|
228
|
+
*/
|
|
229
|
+
disposition?: string | null;
|
|
230
|
+
};
|
|
222
231
|
/**
|
|
223
232
|
* Derive `kind`'s field schema from its JSON Schema.
|
|
224
233
|
*
|
|
225
234
|
* Pure and synchronous — no registry, no IO — so a host can call it from a
|
|
226
235
|
* warm load, a cold fetch, a reducer, or a test.
|
|
227
236
|
*/
|
|
228
|
-
declare function kindSchemaFromJsonSchema(kind: string, jsonSchema: unknown): KindSchemaFromJsonResult;
|
|
237
|
+
declare function kindSchemaFromJsonSchema(kind: string, jsonSchema: unknown, options?: KindSchemaFromJsonOptions): KindSchemaFromJsonResult;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* The four control keys an agent may put beside a kind's values — the TypeScript twin of
|
|
241
|
+
* `matrx_graph.kind_control_keys.with_control_keys` (aidream). ONE definition, two languages:
|
|
242
|
+
* for the same input both produce the same JSON (guard W2-G7, the shared golden
|
|
243
|
+
* `packages/matrx-graph/tests/fixtures/kind_control_keys_golden.json`).
|
|
244
|
+
*
|
|
245
|
+
* `_replaces` ("this replaces that output"), `_new` ("this is something new"), `_record_id`
|
|
246
|
+
* ("change this record") and `_records` ("several records") are never part of a kind and no
|
|
247
|
+
* registry row carries them — they are added where a schema is USED, for `record` kinds and
|
|
248
|
+
* table kinds only:
|
|
249
|
+
*
|
|
250
|
+
* - `withControlKeys(schema, { mode: "stored" })` — the JSON Schema a value is validated
|
|
251
|
+
* against: all four declared optional (nullable), and the root's required Fields lifted when
|
|
252
|
+
* the value is a patch (`_record_id`) or a batch (`_records`) — one branch APPENDED to `allOf`,
|
|
253
|
+
* never replacing it.
|
|
254
|
+
* - `withControlKeys(schema, { mode: "authored", many, allowEdit })` — what the model is shown:
|
|
255
|
+
* `_replaces`/`_new` always, `_record_id` only with `allowEdit`, and with `many` the root is
|
|
256
|
+
* the batch `{__kind, _records: [<record without __kind>], ...}`. Signals are OPTIONAL — the
|
|
257
|
+
* provider translators widen them to required-and-nullable on the wire and prune a null back.
|
|
258
|
+
* - `withControlKeyFields(kindSchema)` — the render-level twin: the four keys as optional
|
|
259
|
+
* render fields of a `KindSchema`, so a patch, a batch or a signal is drawn by its kind's
|
|
260
|
+
* component instead of being reported as unknown keys. The web schema is never stricter
|
|
261
|
+
* than the store.
|
|
262
|
+
*
|
|
263
|
+
* Design: common-docs `projects/data-doctrine-adoption/v6/KINDS-GLUE-WAVE2-DESIGN.md` §1.4.
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
/** The four keys, in the order they are declared. */
|
|
267
|
+
declare const CONTROL_KEYS: readonly ["_replaces", "_new", "_record_id", "_records"];
|
|
268
|
+
type ControlKey = (typeof CONTROL_KEYS)[number];
|
|
269
|
+
/** The one disposition whose kinds take the control keys (table kinds are always `record`). */
|
|
270
|
+
declare const RECORD_DISPOSITION = "record";
|
|
271
|
+
type ControlKeysMode = "stored" | "authored";
|
|
272
|
+
type WithControlKeysOptions = {
|
|
273
|
+
mode: ControlKeysMode;
|
|
274
|
+
/** Authored mode: the root becomes the batch `{__kind, _records: [...]}`. */
|
|
275
|
+
many?: boolean;
|
|
276
|
+
/** Authored mode: the model may name `_record_id` (the run may edit its own outputs). */
|
|
277
|
+
allowEdit?: boolean;
|
|
278
|
+
};
|
|
279
|
+
/** Whether a kind with this disposition takes the control keys. */
|
|
280
|
+
declare function controlKeysApplyTo(disposition: string | null | undefined): boolean;
|
|
281
|
+
/**
|
|
282
|
+
* A copy of `schema` that carries the control keys for `mode`. A schema that is not an object
|
|
283
|
+
* with `properties` (a root-form kind, the "any value" `{}`) is returned unchanged.
|
|
284
|
+
*/
|
|
285
|
+
declare function withControlKeys<T>(schema: T, options: WithControlKeysOptions): T;
|
|
286
|
+
/** The render fields the control keys add to a `KindSchema` — all optional, none stricter than the store. */
|
|
287
|
+
declare const CONTROL_KEY_FIELDS: Readonly<Record<ControlKey, FieldSchema>>;
|
|
288
|
+
/**
|
|
289
|
+
* `schema` with the four control keys as optional render fields. A root-form kind (no field
|
|
290
|
+
* map) is returned unchanged. Keys the kind itself declares are left as the kind declares them.
|
|
291
|
+
*/
|
|
292
|
+
declare function withControlKeyFields(schema: KindSchema): KindSchema;
|
|
293
|
+
/** Split a value into (values without the control keys, the control keys present). */
|
|
294
|
+
declare function stripControlKeys(value: Record<string, unknown>): {
|
|
295
|
+
values: Record<string, unknown>;
|
|
296
|
+
signals: Partial<Record<ControlKey, unknown>>;
|
|
297
|
+
};
|
|
229
298
|
|
|
230
|
-
export { type ArrayItemKindBinding, type BlockSchemaDraft, type ConversionProblem, type DroppedMetadata, type FieldComparison, type ItemKindRefCheck, type JsonSchemaNode, type KindJsonSchemaExport, type KindJsonSchemaOptions, type KindSchemaFromJsonResult, type SavePlanEntry, type SavePlanValidation, type SchemaConversionResult, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, validateBlockSchemaSavePlan };
|
|
299
|
+
export { type ArrayItemKindBinding, type BlockSchemaDraft, CONTROL_KEYS, CONTROL_KEY_FIELDS, type ControlKey, type ControlKeysMode, type ConversionProblem, type DroppedMetadata, type FieldComparison, type ItemKindRefCheck, type JsonSchemaNode, type KindJsonSchemaExport, type KindJsonSchemaOptions, type KindSchemaFromJsonOptions, type KindSchemaFromJsonResult, RECORD_DISPOSITION, type SavePlanEntry, type SavePlanValidation, type SchemaConversionResult, type WithControlKeysOptions, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, controlKeysApplyTo, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, stripControlKeys, validateBlockSchemaSavePlan, withControlKeyFields, withControlKeys };
|
package/dist/convert.js
CHANGED
|
@@ -6,7 +6,7 @@ function scalarArrayItemType(type) {
|
|
|
6
6
|
return "string";
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// text-case.ts
|
|
10
10
|
var DEFAULT_WORD_REPLACEMENTS = {
|
|
11
11
|
// Acronyms & initialisms
|
|
12
12
|
"api": "API",
|
|
@@ -274,6 +274,24 @@ function formatText(text, options = {}) {
|
|
|
274
274
|
}
|
|
275
275
|
return result;
|
|
276
276
|
}
|
|
277
|
+
var IDENTIFIER_ACRONYMS = [
|
|
278
|
+
"ID",
|
|
279
|
+
"URL",
|
|
280
|
+
"PDF",
|
|
281
|
+
"HTML",
|
|
282
|
+
"JSON",
|
|
283
|
+
"API",
|
|
284
|
+
"AI",
|
|
285
|
+
"UI",
|
|
286
|
+
"CSV",
|
|
287
|
+
"SMS",
|
|
288
|
+
"SEO",
|
|
289
|
+
"LLM",
|
|
290
|
+
"MCP",
|
|
291
|
+
"UUID",
|
|
292
|
+
"ISO"
|
|
293
|
+
];
|
|
294
|
+
new Set(IDENTIFIER_ACRONYMS.map((a) => a.toLowerCase()));
|
|
277
295
|
|
|
278
296
|
// core/schema-structure.ts
|
|
279
297
|
function formatBlockLabel(key) {
|
|
@@ -423,13 +441,13 @@ function makeKindJsonSchemaProperty(kindSlug, strict) {
|
|
|
423
441
|
return { ...base, enum: [kindSlug] };
|
|
424
442
|
}
|
|
425
443
|
function injectKindIntoObjectSchema(objectSchema, kindSlug, strict) {
|
|
426
|
-
const
|
|
427
|
-
const properties = isRecord(
|
|
444
|
+
const clone2 = deepClone(objectSchema);
|
|
445
|
+
const properties = isRecord(clone2.properties) ? { ...clone2.properties } : {};
|
|
428
446
|
properties[KIND_KEY] = makeKindJsonSchemaProperty(kindSlug, strict);
|
|
429
|
-
const required = Array.isArray(
|
|
447
|
+
const required = Array.isArray(clone2.required) ? clone2.required.filter((k) => typeof k === "string") : [];
|
|
430
448
|
const nextRequired = required.includes(KIND_KEY) ? required : [KIND_KEY, ...required];
|
|
431
449
|
return {
|
|
432
|
-
...
|
|
450
|
+
...clone2,
|
|
433
451
|
properties,
|
|
434
452
|
required: nextRequired,
|
|
435
453
|
...strict ? { additionalProperties: false } : {}
|
|
@@ -1626,8 +1644,132 @@ function kindSchemaToJsonSchema(kind, resolve, options = {}) {
|
|
|
1626
1644
|
return { name: kind, schema: { ...rootNode, $defs: defs }, strict, unresolved };
|
|
1627
1645
|
}
|
|
1628
1646
|
|
|
1647
|
+
// convert/control-keys.ts
|
|
1648
|
+
var CONTROL_KEYS = ["_replaces", "_new", "_record_id", "_records"];
|
|
1649
|
+
var RECORD_DISPOSITION = "record";
|
|
1650
|
+
var KIND_KEY2 = "__kind";
|
|
1651
|
+
var DOCUMENT_KEYS = /* @__PURE__ */ new Set(["$schema", "$id", "$defs", "definitions", "title", "description"]);
|
|
1652
|
+
var CONTROL = new Set(CONTROL_KEYS);
|
|
1653
|
+
function controlKeysApplyTo(disposition) {
|
|
1654
|
+
return disposition === RECORD_DISPOSITION;
|
|
1655
|
+
}
|
|
1656
|
+
function clone(value) {
|
|
1657
|
+
return value === void 0 ? value : JSON.parse(JSON.stringify(value));
|
|
1658
|
+
}
|
|
1659
|
+
function isObjectSchema(schema) {
|
|
1660
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema)) return false;
|
|
1661
|
+
const s = schema;
|
|
1662
|
+
return s.type === "object" && !!s.properties && typeof s.properties === "object" && !Array.isArray(s.properties);
|
|
1663
|
+
}
|
|
1664
|
+
function requiredOf(schema) {
|
|
1665
|
+
return Array.isArray(schema.required) ? schema.required : [];
|
|
1666
|
+
}
|
|
1667
|
+
function recordObject(schema) {
|
|
1668
|
+
const item = {};
|
|
1669
|
+
for (const [k, v] of Object.entries(schema)) {
|
|
1670
|
+
if (!DOCUMENT_KEYS.has(k)) item[k] = clone(v);
|
|
1671
|
+
}
|
|
1672
|
+
const props = {};
|
|
1673
|
+
for (const [k, v] of Object.entries(item.properties)) {
|
|
1674
|
+
if (k !== KIND_KEY2 && !CONTROL.has(k)) props[k] = v;
|
|
1675
|
+
}
|
|
1676
|
+
item.properties = props;
|
|
1677
|
+
const required = requiredOf(item).filter((k) => k !== KIND_KEY2 && !CONTROL.has(k));
|
|
1678
|
+
if (required.length > 0) item.required = required;
|
|
1679
|
+
else delete item.required;
|
|
1680
|
+
return item;
|
|
1681
|
+
}
|
|
1682
|
+
function stored(schema) {
|
|
1683
|
+
const out = clone(schema);
|
|
1684
|
+
const item = recordObject(schema);
|
|
1685
|
+
const props = out.properties;
|
|
1686
|
+
props._replaces = { type: ["string", "null"], format: "uuid" };
|
|
1687
|
+
props._new = { type: ["boolean", "null"] };
|
|
1688
|
+
props._record_id = { type: ["string", "null"], format: "uuid" };
|
|
1689
|
+
props._records = { type: ["array", "null"], items: item };
|
|
1690
|
+
const rootRequired = requiredOf(out).filter((k) => !CONTROL.has(k));
|
|
1691
|
+
const lifted = rootRequired.filter((k) => k !== KIND_KEY2);
|
|
1692
|
+
if (lifted.length > 0) {
|
|
1693
|
+
const kept = rootRequired.filter((k) => k === KIND_KEY2);
|
|
1694
|
+
if (kept.length > 0) out.required = kept;
|
|
1695
|
+
else delete out.required;
|
|
1696
|
+
const branch = {
|
|
1697
|
+
if: {
|
|
1698
|
+
anyOf: [
|
|
1699
|
+
{ required: ["_record_id"], properties: { _record_id: { type: "string" } } },
|
|
1700
|
+
{ required: ["_records"], properties: { _records: { type: "array" } } }
|
|
1701
|
+
]
|
|
1702
|
+
},
|
|
1703
|
+
else: { required: lifted }
|
|
1704
|
+
};
|
|
1705
|
+
out.allOf = Array.isArray(out.allOf) ? [...out.allOf, branch] : [branch];
|
|
1706
|
+
}
|
|
1707
|
+
return out;
|
|
1708
|
+
}
|
|
1709
|
+
function authored(schema, many, allowEdit) {
|
|
1710
|
+
const signals = {
|
|
1711
|
+
_replaces: { type: "string", format: "uuid" },
|
|
1712
|
+
_new: { type: "boolean" }
|
|
1713
|
+
};
|
|
1714
|
+
if (allowEdit) signals._record_id = { type: "string", format: "uuid" };
|
|
1715
|
+
if (!many) {
|
|
1716
|
+
const out2 = clone(schema);
|
|
1717
|
+
Object.assign(out2.properties, clone(signals));
|
|
1718
|
+
const required = requiredOf(out2).filter((k) => !CONTROL.has(k));
|
|
1719
|
+
if (required.length > 0 || "required" in out2) out2.required = required;
|
|
1720
|
+
return out2;
|
|
1721
|
+
}
|
|
1722
|
+
const out = {};
|
|
1723
|
+
for (const [k, v] of Object.entries(schema)) {
|
|
1724
|
+
if (DOCUMENT_KEYS.has(k)) out[k] = clone(v);
|
|
1725
|
+
}
|
|
1726
|
+
out.type = "object";
|
|
1727
|
+
const kindProp = schema.properties[KIND_KEY2];
|
|
1728
|
+
const properties = {};
|
|
1729
|
+
if (kindProp !== void 0) properties[KIND_KEY2] = clone(kindProp);
|
|
1730
|
+
properties._records = { type: "array", items: recordObject(schema) };
|
|
1731
|
+
Object.assign(properties, clone(signals));
|
|
1732
|
+
out.properties = properties;
|
|
1733
|
+
out.required = [KIND_KEY2, "_records"].filter((k) => k in properties);
|
|
1734
|
+
out.additionalProperties = false;
|
|
1735
|
+
return out;
|
|
1736
|
+
}
|
|
1737
|
+
function withControlKeys(schema, options) {
|
|
1738
|
+
const { mode, many = false, allowEdit = false } = options;
|
|
1739
|
+
if (mode !== "stored" && mode !== "authored") {
|
|
1740
|
+
throw new Error(`withControlKeys: mode must be "stored" or "authored", got ${String(mode)}`);
|
|
1741
|
+
}
|
|
1742
|
+
if (!isObjectSchema(schema)) return schema;
|
|
1743
|
+
return mode === "stored" ? stored(schema) : authored(schema, many, allowEdit);
|
|
1744
|
+
}
|
|
1745
|
+
var CONTROL_KEY_FIELDS = Object.freeze({
|
|
1746
|
+
_replaces: { type: "string", nullable: true },
|
|
1747
|
+
_new: { type: "boolean", nullable: true },
|
|
1748
|
+
_record_id: { type: "string", nullable: true },
|
|
1749
|
+
// A batch's items are records of this kind WITHOUT `__kind`; the render layer reads them
|
|
1750
|
+
// as opaque JSON (never stricter than the store, which validates each item).
|
|
1751
|
+
_records: { type: "json[]", nullable: true }
|
|
1752
|
+
});
|
|
1753
|
+
function withControlKeyFields(schema) {
|
|
1754
|
+
if (schema.root) return schema;
|
|
1755
|
+
const fields = { ...schema.fields };
|
|
1756
|
+
for (const key of CONTROL_KEYS) {
|
|
1757
|
+
if (!(key in fields)) fields[key] = { ...CONTROL_KEY_FIELDS[key] };
|
|
1758
|
+
}
|
|
1759
|
+
return { ...schema, fields };
|
|
1760
|
+
}
|
|
1761
|
+
function stripControlKeys(value) {
|
|
1762
|
+
const values = {};
|
|
1763
|
+
const signals = {};
|
|
1764
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1765
|
+
if (CONTROL.has(k)) signals[k] = v;
|
|
1766
|
+
else values[k] = v;
|
|
1767
|
+
}
|
|
1768
|
+
return { values, signals };
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1629
1771
|
// convert/json-schema-to-kind.ts
|
|
1630
|
-
function kindSchemaFromJsonSchema(kind, jsonSchema) {
|
|
1772
|
+
function kindSchemaFromJsonSchema(kind, jsonSchema, options = {}) {
|
|
1631
1773
|
if (jsonSchema === null || jsonSchema === void 0) {
|
|
1632
1774
|
return { schema: null, children: {}, problems: [] };
|
|
1633
1775
|
}
|
|
@@ -1658,9 +1800,12 @@ function kindSchemaFromJsonSchema(kind, jsonSchema) {
|
|
|
1658
1800
|
if (draft.slug === kind) schema = asKindSchema;
|
|
1659
1801
|
else children[draft.slug] = asKindSchema;
|
|
1660
1802
|
}
|
|
1803
|
+
if (schema && controlKeysApplyTo(options.disposition)) {
|
|
1804
|
+
schema = withControlKeyFields(schema);
|
|
1805
|
+
}
|
|
1661
1806
|
return { schema, children, problems: converted.problems };
|
|
1662
1807
|
}
|
|
1663
1808
|
|
|
1664
|
-
export { buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, validateBlockSchemaSavePlan };
|
|
1809
|
+
export { CONTROL_KEYS, CONTROL_KEY_FIELDS, RECORD_DISPOSITION, buildAgentSchemaWithRenderBlockSupport, collectReferencedKinds, collectSchemaReferencedKinds, compareWithExistingKindSchema, controlKeysApplyTo, convertAiSchemaToBlockFields, fieldsToDbPayload, injectKindIntoObjectSchema, isDuplicateBlockSlug, kindSchemaFromJsonSchema, kindSchemaToJsonSchema, normalizeAiSchemaInput, runSchemaConversion, stripControlKeys, validateBlockSchemaSavePlan, withControlKeyFields, withControlKeys };
|
|
1665
1810
|
//# sourceMappingURL=convert.js.map
|
|
1666
1811
|
//# sourceMappingURL=convert.js.map
|