@cratis/components 4.28.0 → 4.29.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.
Files changed (48) hide show
  1. package/compat-manifest.json +11 -11
  2. package/dist/esm/SchemaEditor/SchemaEditor.d.ts.map +1 -1
  3. package/dist/esm/SchemaEditor/SchemaEditor.js +3 -1
  4. package/dist/esm/SchemaEditor/SchemaEditor.js.map +1 -1
  5. package/dist/esm/SchemaEditor/Tree/KeywordFamily.d.ts +14 -0
  6. package/dist/esm/SchemaEditor/Tree/KeywordFamily.d.ts.map +1 -0
  7. package/dist/esm/SchemaEditor/Tree/KeywordFamily.js +11 -0
  8. package/dist/esm/SchemaEditor/Tree/KeywordFamily.js.map +1 -0
  9. package/dist/esm/SchemaEditor/Tree/Property.d.ts +8 -0
  10. package/dist/esm/SchemaEditor/Tree/Property.d.ts.map +1 -1
  11. package/dist/esm/SchemaEditor/Tree/Property.js.map +1 -1
  12. package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.d.ts +9 -2
  13. package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.d.ts.map +1 -1
  14. package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.js +7 -5
  15. package/dist/esm/SchemaEditor/Tree/SchemaOrderedProperty.js.map +1 -1
  16. package/dist/esm/SchemaEditor/Tree/SchemaOriginalShape.d.ts +21 -0
  17. package/dist/esm/SchemaEditor/Tree/SchemaOriginalShape.d.ts.map +1 -0
  18. package/dist/esm/SchemaEditor/Tree/SchemaOriginalShape.js +4 -0
  19. package/dist/esm/SchemaEditor/Tree/SchemaOriginalShape.js.map +1 -0
  20. package/dist/esm/SchemaEditor/Tree/keywordApplicability.d.ts +41 -0
  21. package/dist/esm/SchemaEditor/Tree/keywordApplicability.d.ts.map +1 -0
  22. package/dist/esm/SchemaEditor/Tree/keywordApplicability.js +56 -0
  23. package/dist/esm/SchemaEditor/Tree/keywordApplicability.js.map +1 -0
  24. package/dist/esm/SchemaEditor/Tree/originalShape.d.ts +30 -0
  25. package/dist/esm/SchemaEditor/Tree/originalShape.d.ts.map +1 -0
  26. package/dist/esm/SchemaEditor/Tree/originalShape.js +70 -0
  27. package/dist/esm/SchemaEditor/Tree/originalShape.js.map +1 -0
  28. package/dist/esm/SchemaEditor/Tree/schemaConversion.d.ts +5 -3
  29. package/dist/esm/SchemaEditor/Tree/schemaConversion.d.ts.map +1 -1
  30. package/dist/esm/SchemaEditor/Tree/schemaConversion.js +43 -43
  31. package/dist/esm/SchemaEditor/Tree/schemaConversion.js.map +1 -1
  32. package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.d.ts +2 -0
  33. package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.d.ts.map +1 -1
  34. package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.js +4 -1
  35. package/dist/esm/SchemaEditor/Tree/schemaInOriginalOrder.js.map +1 -1
  36. package/dist/esm/SchemaEditor/Tree/schemaPropertyType.d.ts +11 -0
  37. package/dist/esm/SchemaEditor/Tree/schemaPropertyType.d.ts.map +1 -0
  38. package/dist/esm/SchemaEditor/Tree/schemaPropertyType.js +31 -0
  39. package/dist/esm/SchemaEditor/Tree/schemaPropertyType.js.map +1 -0
  40. package/dist/esm/SchemaEditor/Tree/standardKeywords.d.ts +18 -0
  41. package/dist/esm/SchemaEditor/Tree/standardKeywords.d.ts.map +1 -0
  42. package/dist/esm/SchemaEditor/Tree/standardKeywords.js +22 -0
  43. package/dist/esm/SchemaEditor/Tree/standardKeywords.js.map +1 -0
  44. package/dist/esm/SchemaEditor/schemaHelpers.d.ts +9 -0
  45. package/dist/esm/SchemaEditor/schemaHelpers.d.ts.map +1 -1
  46. package/dist/esm/SchemaEditor/schemaHelpers.js +20 -1
  47. package/dist/esm/SchemaEditor/schemaHelpers.js.map +1 -1
  48. package/package.json +1 -1
@@ -1,3 +1,5 @@
1
1
  /** Retains the positions of surviving schema keywords and appends new keywords. */
2
2
  export declare function schemaInOriginalOrder(schema: Record<string, unknown>, order?: readonly string[]): Record<string, unknown>;
3
+ /** Lists the names that remain in the order they had, followed by new names in their given order. */
4
+ export declare function requiredInOriginalOrder(required: readonly string[], order?: readonly string[]): string[];
3
5
  //# sourceMappingURL=schemaInOriginalOrder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaInOriginalOrder.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/schemaInOriginalOrder.ts"],"names":[],"mappings":"AAGA,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAG7H"}
1
+ {"version":3,"file":"schemaInOriginalOrder.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/schemaInOriginalOrder.ts"],"names":[],"mappings":"AAGA,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAG7H;AAED,qGAAqG;AACrG,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,MAAM,EAAE,CAE5G"}
@@ -2,6 +2,9 @@ function schemaInOriginalOrder(schema, order = []) {
2
2
  const names = new Set([...order, ...Object.keys(schema)]);
3
3
  return Object.fromEntries([...names].filter(name => Object.hasOwn(schema, name)).map(name => [name, schema[name]]));
4
4
  }
5
+ function requiredInOriginalOrder(required, order = []) {
6
+ return [...order.filter(name => required.includes(name)), ...required.filter(name => !order.includes(name))];
7
+ }
5
8
 
6
- export { schemaInOriginalOrder };
9
+ export { requiredInOriginalOrder, schemaInOriginalOrder };
7
10
  //# sourceMappingURL=schemaInOriginalOrder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaInOriginalOrder.js","sources":["../../../../SchemaEditor/Tree/schemaInOriginalOrder.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/** Retains the positions of surviving schema keywords and appends new keywords. */\nexport function schemaInOriginalOrder(schema: Record<string, unknown>, order: readonly string[] = []): Record<string, unknown> {\n const names = new Set([...order, ...Object.keys(schema)]);\n return Object.fromEntries([...names].filter(name => Object.hasOwn(schema, name)).map(name => [name, schema[name]]));\n}\n"],"names":[],"mappings":"SAIgB,qBAAqB,CAAC,MAA+B,EAAE,QAA2B,EAAE,EAAA;AAChG,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACzD,IAAA,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvH;;"}
1
+ {"version":3,"file":"schemaInOriginalOrder.js","sources":["../../../../SchemaEditor/Tree/schemaInOriginalOrder.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\n/** Retains the positions of surviving schema keywords and appends new keywords. */\nexport function schemaInOriginalOrder(schema: Record<string, unknown>, order: readonly string[] = []): Record<string, unknown> {\n const names = new Set([...order, ...Object.keys(schema)]);\n return Object.fromEntries([...names].filter(name => Object.hasOwn(schema, name)).map(name => [name, schema[name]]));\n}\n\n/** Lists the names that remain in the order they had, followed by new names in their given order. */\nexport function requiredInOriginalOrder(required: readonly string[], order: readonly string[] = []): string[] {\n return [...order.filter(name => required.includes(name)), ...required.filter(name => !order.includes(name))];\n}\n"],"names":[],"mappings":"SAIgB,qBAAqB,CAAC,MAA+B,EAAE,QAA2B,EAAE,EAAA;AAChG,IAAA,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;AACzD,IAAA,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACvH;SAGgB,uBAAuB,CAAC,QAA2B,EAAE,QAA2B,EAAE,EAAA;AAC9F,IAAA,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAChH;;"}
@@ -0,0 +1,11 @@
1
+ import { PropertyType } from './PropertyType.js';
2
+ type SchemaNode = Record<string, unknown>;
3
+ /**
4
+ * The property type a schema node reads as. An unknown or missing `type` reads as text, and a list whose
5
+ * items are not numbers or objects reads as a list of text.
6
+ * @param value The property schema node.
7
+ * @returns The property type.
8
+ */
9
+ export declare function schemaPropertyType(value: SchemaNode): PropertyType;
10
+ export {};
11
+ //# sourceMappingURL=schemaPropertyType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaPropertyType.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/schemaPropertyType.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;AAE9C,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE1C;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CAsBlE"}
@@ -0,0 +1,31 @@
1
+ import { PropertyType } from './PropertyType.js';
2
+
3
+ function schemaPropertyType(value) {
4
+ const items = value.items;
5
+ switch (value.type) {
6
+ case 'string':
7
+ if (value.format === 'date')
8
+ return PropertyType.Date;
9
+ if (value.format === 'time')
10
+ return PropertyType.Time;
11
+ return PropertyType.String;
12
+ case 'number':
13
+ case 'integer':
14
+ return PropertyType.Number;
15
+ case 'boolean':
16
+ return PropertyType.Boolean;
17
+ case 'object':
18
+ return PropertyType.Object;
19
+ case 'array':
20
+ if (items?.type === 'number' || items?.type === 'integer')
21
+ return PropertyType.NumberArray;
22
+ if (items?.type === 'object')
23
+ return PropertyType.ObjectArray;
24
+ return PropertyType.StringArray;
25
+ default:
26
+ return PropertyType.String;
27
+ }
28
+ }
29
+
30
+ export { schemaPropertyType };
31
+ //# sourceMappingURL=schemaPropertyType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaPropertyType.js","sources":["../../../../SchemaEditor/Tree/schemaPropertyType.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { PropertyType } from './PropertyType';\n\ntype SchemaNode = Record<string, unknown>;\n\n/**\n * The property type a schema node reads as. An unknown or missing `type` reads as text, and a list whose\n * items are not numbers or objects reads as a list of text.\n * @param value The property schema node.\n * @returns The property type.\n */\nexport function schemaPropertyType(value: SchemaNode): PropertyType {\n const items = value.items as { type?: string } | undefined;\n\n switch (value.type) {\n case 'string':\n if (value.format === 'date') return PropertyType.Date;\n if (value.format === 'time') return PropertyType.Time;\n return PropertyType.String;\n case 'number':\n case 'integer':\n return PropertyType.Number;\n case 'boolean':\n return PropertyType.Boolean;\n case 'object':\n return PropertyType.Object;\n case 'array':\n if (items?.type === 'number' || items?.type === 'integer') return PropertyType.NumberArray;\n if (items?.type === 'object') return PropertyType.ObjectArray;\n return PropertyType.StringArray;\n default:\n return PropertyType.String;\n }\n}\n"],"names":[],"mappings":";;AAaM,SAAU,kBAAkB,CAAC,KAAiB,EAAA;AAChD,IAAA,MAAM,KAAK,GAAG,KAAK,CAAC,KAAsC;AAE1D,IAAA,QAAQ,KAAK,CAAC,IAAI;AACd,QAAA,KAAK,QAAQ;AACT,YAAA,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;gBAAE,OAAO,YAAY,CAAC,IAAI;AACrD,YAAA,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;gBAAE,OAAO,YAAY,CAAC,IAAI;YACrD,OAAO,YAAY,CAAC,MAAM;AAC9B,QAAA,KAAK,QAAQ;AACb,QAAA,KAAK,SAAS;YACV,OAAO,YAAY,CAAC,MAAM;AAC9B,QAAA,KAAK,SAAS;YACV,OAAO,YAAY,CAAC,OAAO;AAC/B,QAAA,KAAK,QAAQ;YACT,OAAO,YAAY,CAAC,MAAM;AAC9B,QAAA,KAAK,OAAO;YACR,IAAI,KAAK,EAAE,IAAI,KAAK,QAAQ,IAAI,KAAK,EAAE,IAAI,KAAK,SAAS;gBAAE,OAAO,YAAY,CAAC,WAAW;AAC1F,YAAA,IAAI,KAAK,EAAE,IAAI,KAAK,QAAQ;gBAAE,OAAO,YAAY,CAAC,WAAW;YAC7D,OAAO,YAAY,CAAC,WAAW;AACnC,QAAA;YACI,OAAO,YAAY,CAAC,MAAM;;AAEtC;;"}
@@ -0,0 +1,18 @@
1
+ import { PropertyType } from './PropertyType.js';
2
+ type SchemaNode = Record<string, unknown>;
3
+ /**
4
+ * Reads the standard keywords of a property node that the editor does not model.
5
+ * @param node The property schema node.
6
+ * @param type The property type the node reads as.
7
+ * @returns The keywords, or undefined when there are none.
8
+ */
9
+ export declare function standardPropertyKeywords(node: SchemaNode, type: PropertyType): Readonly<Record<string, unknown>> | undefined;
10
+ /**
11
+ * Reads the standard keywords of an array's items node that the editor does not model.
12
+ * @param items The items schema node.
13
+ * @param type The property type of the array.
14
+ * @returns The keywords, or undefined when there are none.
15
+ */
16
+ export declare function standardItemKeywords(items: SchemaNode, type: PropertyType): Readonly<Record<string, unknown>> | undefined;
17
+ export {};
18
+ //# sourceMappingURL=standardKeywords.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standardKeywords.d.ts","sourceRoot":"","sources":["../../../../SchemaEditor/Tree/standardKeywords.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAgB,CAAC;AAE9C,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAS1C;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAO5H;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,SAAS,CAEzH"}
@@ -0,0 +1,22 @@
1
+ import { isNode } from './originalShape.js';
2
+ import { PropertyType } from './PropertyType.js';
3
+
4
+ const arrayTypes = [PropertyType.StringArray, PropertyType.NumberArray, PropertyType.ObjectArray];
5
+ function unmodelled(node, modelled) {
6
+ const entries = Object.entries(node).filter(([name]) => !name.startsWith('x-') && !modelled.includes(name));
7
+ return entries.length > 0 ? Object.fromEntries(entries) : undefined;
8
+ }
9
+ function standardPropertyKeywords(node, type) {
10
+ return unmodelled(node, [
11
+ 'type',
12
+ 'format',
13
+ ...(arrayTypes.includes(type) && isNode(node.items) ? ['items'] : []),
14
+ ...(type === PropertyType.Object && isNode(node.properties) ? ['properties', 'required'] : []),
15
+ ]);
16
+ }
17
+ function standardItemKeywords(items, type) {
18
+ return unmodelled(items, ['type', 'format', ...(type === PropertyType.ObjectArray && isNode(items.properties) ? ['properties', 'required'] : [])]);
19
+ }
20
+
21
+ export { standardItemKeywords, standardPropertyKeywords };
22
+ //# sourceMappingURL=standardKeywords.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"standardKeywords.js","sources":["../../../../SchemaEditor/Tree/standardKeywords.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { isNode } from './originalShape';\nimport { PropertyType } from './PropertyType';\n\ntype SchemaNode = Record<string, unknown>;\n\nconst arrayTypes: readonly PropertyType[] = [PropertyType.StringArray, PropertyType.NumberArray, PropertyType.ObjectArray];\n\nfunction unmodelled(node: SchemaNode, modelled: readonly string[]): Readonly<Record<string, unknown>> | undefined {\n const entries = Object.entries(node).filter(([name]) => !name.startsWith('x-') && !modelled.includes(name));\n return entries.length > 0 ? Object.fromEntries(entries) : undefined;\n}\n\n/**\n * Reads the standard keywords of a property node that the editor does not model.\n * @param node The property schema node.\n * @param type The property type the node reads as.\n * @returns The keywords, or undefined when there are none.\n */\nexport function standardPropertyKeywords(node: SchemaNode, type: PropertyType): Readonly<Record<string, unknown>> | undefined {\n return unmodelled(node, [\n 'type',\n 'format',\n ...(arrayTypes.includes(type) && isNode(node.items) ? ['items'] : []),\n ...(type === PropertyType.Object && isNode(node.properties) ? ['properties', 'required'] : []),\n ]);\n}\n\n/**\n * Reads the standard keywords of an array's items node that the editor does not model.\n * @param items The items schema node.\n * @param type The property type of the array.\n * @returns The keywords, or undefined when there are none.\n */\nexport function standardItemKeywords(items: SchemaNode, type: PropertyType): Readonly<Record<string, unknown>> | undefined {\n return unmodelled(items, ['type', 'format', ...(type === PropertyType.ObjectArray && isNode(items.properties) ? ['properties', 'required'] : [])]);\n}\n"],"names":[],"mappings":";;;AAQA,MAAM,UAAU,GAA4B,CAAC,YAAY,CAAC,WAAW,EAAE,YAAY,CAAC,WAAW,EAAE,YAAY,CAAC,WAAW,CAAC;AAE1H,SAAS,UAAU,CAAC,IAAgB,EAAE,QAA2B,EAAA;AAC7D,IAAA,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAC3G,IAAA,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,SAAS;AACvE;AAQM,SAAU,wBAAwB,CAAC,IAAgB,EAAE,IAAkB,EAAA;IACzE,OAAO,UAAU,CAAC,IAAI,EAAE;QACpB,MAAM;QACN,QAAQ;QACR,IAAI,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;QACrE,IAAI,IAAI,KAAK,YAAY,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC;AACjG,KAAA,CAAC;AACN;AAQM,SAAU,oBAAoB,CAAC,KAAiB,EAAE,IAAkB,EAAA;AACtE,IAAA,OAAO,UAAU,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,IAAI,KAAK,YAAY,CAAC,WAAW,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AACtJ;;"}
@@ -1,4 +1,13 @@
1
1
  import type { JsonSchemaProperty, NavigationItem } from '../types/JsonSchema.js';
2
+ /**
3
+ * Removes the standard keywords that no longer apply after a property's type changed, in place. The type,
4
+ * format, items, properties and `required` keywords and every `x-` keyword are left to the caller. A change
5
+ * between refinements of one type, such as integer and number, keeps the constraints and drops the value
6
+ * keywords and `multipleOf`; choosing the type the node already has keeps everything.
7
+ * @param node The property node after the type change.
8
+ * @param previous The property node before the type change.
9
+ */
10
+ export declare function dropInapplicableKeywords(node: Record<string, unknown>, previous: Record<string, unknown>): void;
2
11
  /**
3
12
  * Validates a property name, returning an error string or undefined if valid.
4
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"schemaHelpers.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/schemaHelpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAqB,CAAC;AAI9E;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,kBAAkB,EAAE,GACpC,MAAM,GAAG,SAAS,CAsBpB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EAAE,GACtB,cAAc,EAAE,CAalB"}
1
+ {"version":3,"file":"schemaHelpers.d.ts","sourceRoot":"","sources":["../../../SchemaEditor/schemaHelpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAqB,CAAC;AAM9E;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAY/G;AAID;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,kBAAkB,EAAE,GACpC,MAAM,GAAG,SAAS,CAsBpB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAChC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EAAE,GACtB,cAAc,EAAE,CAalB"}
@@ -1,3 +1,22 @@
1
+ import { jsonTypeFamily, isKeywordApplicableToRefinement, isKeywordApplicable } from './Tree/keywordApplicability.js';
2
+ import { schemaPropertyType } from './Tree/schemaPropertyType.js';
3
+
4
+ const modelledKeywords = new Set(['type', 'format', 'items', 'properties', 'required']);
5
+ function dropInapplicableKeywords(node, previous) {
6
+ const kindOf = (candidate) => schemaPropertyType({ ...candidate, items: undefined });
7
+ const sameKind = kindOf(node) === kindOf(previous);
8
+ if (sameKind && node.type === previous.type)
9
+ return;
10
+ const from = jsonTypeFamily(previous.type);
11
+ const to = jsonTypeFamily(node.type);
12
+ const isApplicable = sameKind ? isKeywordApplicableToRefinement : (keyword) => isKeywordApplicable(keyword, from, to);
13
+ for (const keyword of Object.keys(node)) {
14
+ if (modelledKeywords.has(keyword) || keyword.startsWith('x-'))
15
+ continue;
16
+ if (!isApplicable(keyword))
17
+ delete node[keyword];
18
+ }
19
+ }
1
20
  const reservedPrototypeKeys = new Set(['__proto__', 'constructor', 'prototype']);
2
21
  function validatePropertyName(name, propertyId, allProperties) {
3
22
  if (!name || name.trim() === '') {
@@ -30,5 +49,5 @@ function buildBreadcrumbItems(eventTypeName, currentPath) {
30
49
  return items;
31
50
  }
32
51
 
33
- export { buildBreadcrumbItems, validatePropertyName };
52
+ export { buildBreadcrumbItems, dropInapplicableKeywords, validatePropertyName };
34
53
  //# sourceMappingURL=schemaHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaHelpers.js","sources":["../../../SchemaEditor/schemaHelpers.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { JsonSchemaProperty, NavigationItem } from '../types/JsonSchema';\n\nconst reservedPrototypeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Validates a property name, returning an error string or undefined if valid.\n */\nexport function validatePropertyName(\n name: string,\n propertyId: string,\n allProperties: JsonSchemaProperty[],\n): string | undefined {\n if (!name || name.trim() === '') {\n return 'Property name cannot be empty';\n }\n\n if (reservedPrototypeKeys.has(name)) {\n return 'Property name cannot be a reserved prototype key';\n }\n\n const validIdentifierPattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;\n if (!validIdentifierPattern.test(name)) {\n return 'Property name must start with a letter or underscore and contain only letters, numbers, and underscores';\n }\n\n const duplicates = allProperties.filter(\n (p) => p.name === name && p.id !== propertyId,\n );\n if (duplicates.length > 0) {\n return 'Property name must be unique';\n }\n\n return undefined;\n}\n\n/**\n * Builds the list of breadcrumb navigation items from a path, using the event type name as the root.\n */\nexport function buildBreadcrumbItems(\n eventTypeName: string,\n currentPath: string[],\n): NavigationItem[] {\n const items: NavigationItem[] = [{ name: eventTypeName, path: [] }];\n\n for (let i = 0; i < currentPath.length; i++) {\n const segment = currentPath[i];\n if (segment === '$items') {\n items.push({ name: '[items]', path: currentPath.slice(0, i + 1) });\n } else {\n items.push({ name: segment, path: currentPath.slice(0, i + 1) });\n }\n }\n\n return items;\n}\n"],"names":[],"mappings":"AAKA,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;SAKhE,oBAAoB,CAChC,IAAY,EACZ,UAAkB,EAClB,aAAmC,EAAA;IAEnC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;AAC7B,QAAA,OAAO,+BAA+B;IAC1C;AAEA,IAAA,IAAI,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;AACjC,QAAA,OAAO,kDAAkD;IAC7D;IAEA,MAAM,sBAAsB,GAAG,0BAA0B;IACzD,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACpC,QAAA,OAAO,yGAAyG;IACpH;IAEA,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CACnC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,CAAC,EAAE,KAAK,UAAU,CAChD;AACD,IAAA,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;AACvB,QAAA,OAAO,8BAA8B;IACzC;AAEA,IAAA,OAAO,SAAS;AACpB;AAKM,SAAU,oBAAoB,CAChC,aAAqB,EACrB,WAAqB,EAAA;AAErB,IAAA,MAAM,KAAK,GAAqB,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAEnE,IAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACzC,QAAA,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC;AAC9B,QAAA,IAAI,OAAO,KAAK,QAAQ,EAAE;YACtB,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACtE;aAAO;YACH,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACpE;IACJ;AAEA,IAAA,OAAO,KAAK;AAChB;;"}
1
+ {"version":3,"file":"schemaHelpers.js","sources":["../../../SchemaEditor/schemaHelpers.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport type { JsonSchemaProperty, NavigationItem } from '../types/JsonSchema';\nimport { isKeywordApplicable, isKeywordApplicableToRefinement, jsonTypeFamily } from './Tree/keywordApplicability';\nimport { schemaPropertyType } from './Tree/schemaPropertyType';\n\nconst modelledKeywords = new Set(['type', 'format', 'items', 'properties', 'required']);\n\n/**\n * Removes the standard keywords that no longer apply after a property's type changed, in place. The type,\n * format, items, properties and `required` keywords and every `x-` keyword are left to the caller. A change\n * between refinements of one type, such as integer and number, keeps the constraints and drops the value\n * keywords and `multipleOf`; choosing the type the node already has keeps everything.\n * @param node The property node after the type change.\n * @param previous The property node before the type change.\n */\nexport function dropInapplicableKeywords(node: Record<string, unknown>, previous: Record<string, unknown>): void {\n const kindOf = (candidate: Record<string, unknown>) => schemaPropertyType({ ...candidate, items: undefined });\n const sameKind = kindOf(node) === kindOf(previous);\n if (sameKind && node.type === previous.type) return;\n\n const from = jsonTypeFamily(previous.type);\n const to = jsonTypeFamily(node.type);\n const isApplicable = sameKind ? isKeywordApplicableToRefinement : (keyword: string) => isKeywordApplicable(keyword, from, to);\n for (const keyword of Object.keys(node)) {\n if (modelledKeywords.has(keyword) || keyword.startsWith('x-')) continue;\n if (!isApplicable(keyword)) delete node[keyword];\n }\n}\n\nconst reservedPrototypeKeys = new Set(['__proto__', 'constructor', 'prototype']);\n\n/**\n * Validates a property name, returning an error string or undefined if valid.\n */\nexport function validatePropertyName(\n name: string,\n propertyId: string,\n allProperties: JsonSchemaProperty[],\n): string | undefined {\n if (!name || name.trim() === '') {\n return 'Property name cannot be empty';\n }\n\n if (reservedPrototypeKeys.has(name)) {\n return 'Property name cannot be a reserved prototype key';\n }\n\n const validIdentifierPattern = /^[a-zA-Z_][a-zA-Z0-9_]*$/;\n if (!validIdentifierPattern.test(name)) {\n return 'Property name must start with a letter or underscore and contain only letters, numbers, and underscores';\n }\n\n const duplicates = allProperties.filter(\n (p) => p.name === name && p.id !== propertyId,\n );\n if (duplicates.length > 0) {\n return 'Property name must be unique';\n }\n\n return undefined;\n}\n\n/**\n * Builds the list of breadcrumb navigation items from a path, using the event type name as the root.\n */\nexport function buildBreadcrumbItems(\n eventTypeName: string,\n currentPath: string[],\n): NavigationItem[] {\n const items: NavigationItem[] = [{ name: eventTypeName, path: [] }];\n\n for (let i = 0; i < currentPath.length; i++) {\n const segment = currentPath[i];\n if (segment === '$items') {\n items.push({ name: '[items]', path: currentPath.slice(0, i + 1) });\n } else {\n items.push({ name: segment, path: currentPath.slice(0, i + 1) });\n }\n }\n\n return items;\n}\n"],"names":[],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/components",
3
- "version": "4.28.0",
3
+ "version": "4.29.0",
4
4
  "description": "React components for CQRS and event-sourced apps — command dialogs, typed forms, and query-backed data tables for Cratis Arc",
5
5
  "keywords": [
6
6
  "react",