@kaskad/schema 0.0.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.
Files changed (134) hide show
  1. package/README.md +217 -0
  2. package/esm2022/index.js +17 -0
  3. package/esm2022/index.js.map +1 -0
  4. package/esm2022/kaskad-schema.js +5 -0
  5. package/esm2022/kaskad-schema.js.map +1 -0
  6. package/esm2022/lib/load/load-schema.js +16 -0
  7. package/esm2022/lib/load/load-schema.js.map +1 -0
  8. package/esm2022/lib/load/load-templates.js +136 -0
  9. package/esm2022/lib/load/load-templates.js.map +1 -0
  10. package/esm2022/lib/load/register-declared-type.js +28 -0
  11. package/esm2022/lib/load/register-declared-type.js.map +1 -0
  12. package/esm2022/lib/load/schema-component-extractor.js +101 -0
  13. package/esm2022/lib/load/schema-component-extractor.js.map +1 -0
  14. package/esm2022/lib/load/template-registry.js +51 -0
  15. package/esm2022/lib/load/template-registry.js.map +1 -0
  16. package/esm2022/lib/types/component-definition.js +1 -0
  17. package/esm2022/lib/types/component-definition.js.map +1 -0
  18. package/esm2022/lib/types/component-schema.js +1 -0
  19. package/esm2022/lib/types/component-schema.js.map +1 -0
  20. package/esm2022/lib/types/raw-schemas.js +3 -0
  21. package/esm2022/lib/types/raw-schemas.js.map +1 -0
  22. package/esm2022/lib/types/template-raw-definition.js +1 -0
  23. package/esm2022/lib/types/template-raw-definition.js.map +1 -0
  24. package/esm2022/lib/unfolding/computation/unfold-computation-schema.js +70 -0
  25. package/esm2022/lib/unfolding/computation/unfold-computation-schema.js.map +1 -0
  26. package/esm2022/lib/unfolding/computation/unfold-for-new-syntax.js +147 -0
  27. package/esm2022/lib/unfolding/computation/unfold-for-new-syntax.js.map +1 -0
  28. package/esm2022/lib/unfolding/computation/unfold-for.js +45 -0
  29. package/esm2022/lib/unfolding/computation/unfold-for.js.map +1 -0
  30. package/esm2022/lib/unfolding/computation/unfold-if.js +18 -0
  31. package/esm2022/lib/unfolding/computation/unfold-if.js.map +1 -0
  32. package/esm2022/lib/unfolding/computation/unfold-import.js +26 -0
  33. package/esm2022/lib/unfolding/computation/unfold-import.js.map +1 -0
  34. package/esm2022/lib/unfolding/computation/unfold-interpolation.js +44 -0
  35. package/esm2022/lib/unfolding/computation/unfold-interpolation.js.map +1 -0
  36. package/esm2022/lib/unfolding/parse-binding-shorthand.js +40 -0
  37. package/esm2022/lib/unfolding/parse-binding-shorthand.js.map +1 -0
  38. package/esm2022/lib/unfolding/parse-property-key-shorthand.js +9 -0
  39. package/esm2022/lib/unfolding/parse-property-key-shorthand.js.map +1 -0
  40. package/esm2022/lib/unfolding/parse-value-type.js +115 -0
  41. package/esm2022/lib/unfolding/parse-value-type.js.map +1 -0
  42. package/esm2022/lib/unfolding/to-full-notation.js +124 -0
  43. package/esm2022/lib/unfolding/to-full-notation.js.map +1 -0
  44. package/esm2022/lib/unfolding/unfold-flat-wrapper-notation.js +72 -0
  45. package/esm2022/lib/unfolding/unfold-flat-wrapper-notation.js.map +1 -0
  46. package/esm2022/lib/unfolding/unfold-node-schema.js +35 -0
  47. package/esm2022/lib/unfolding/unfold-node-schema.js.map +1 -0
  48. package/esm2022/lib/unfolding/unfold-property.js +21 -0
  49. package/esm2022/lib/unfolding/unfold-property.js.map +1 -0
  50. package/esm2022/lib/unfolding/value/handlers/index.js +11 -0
  51. package/esm2022/lib/unfolding/value/handlers/index.js.map +1 -0
  52. package/esm2022/lib/unfolding/value/handlers/unfold-array.js +9 -0
  53. package/esm2022/lib/unfolding/value/handlers/unfold-array.js.map +1 -0
  54. package/esm2022/lib/unfolding/value/handlers/unfold-boolean.js +8 -0
  55. package/esm2022/lib/unfolding/value/handlers/unfold-boolean.js.map +1 -0
  56. package/esm2022/lib/unfolding/value/handlers/unfold-command.js +22 -0
  57. package/esm2022/lib/unfolding/value/handlers/unfold-command.js.map +1 -0
  58. package/esm2022/lib/unfolding/value/handlers/unfold-component-schema.js +14 -0
  59. package/esm2022/lib/unfolding/value/handlers/unfold-component-schema.js.map +1 -0
  60. package/esm2022/lib/unfolding/value/handlers/unfold-component.js +66 -0
  61. package/esm2022/lib/unfolding/value/handlers/unfold-component.js.map +1 -0
  62. package/esm2022/lib/unfolding/value/handlers/unfold-map.js +13 -0
  63. package/esm2022/lib/unfolding/value/handlers/unfold-map.js.map +1 -0
  64. package/esm2022/lib/unfolding/value/handlers/unfold-number.js +11 -0
  65. package/esm2022/lib/unfolding/value/handlers/unfold-number.js.map +1 -0
  66. package/esm2022/lib/unfolding/value/handlers/unfold-object.js +15 -0
  67. package/esm2022/lib/unfolding/value/handlers/unfold-object.js.map +1 -0
  68. package/esm2022/lib/unfolding/value/handlers/unfold-set.js +6 -0
  69. package/esm2022/lib/unfolding/value/handlers/unfold-set.js.map +1 -0
  70. package/esm2022/lib/unfolding/value/handlers/unfold-shape.js +13 -0
  71. package/esm2022/lib/unfolding/value/handlers/unfold-shape.js.map +1 -0
  72. package/esm2022/lib/unfolding/value/handlers/unfold-string.js +8 -0
  73. package/esm2022/lib/unfolding/value/handlers/unfold-string.js.map +1 -0
  74. package/esm2022/lib/unfolding/value/handlers/unfold-unknown.js +4 -0
  75. package/esm2022/lib/unfolding/value/handlers/unfold-unknown.js.map +1 -0
  76. package/esm2022/lib/unfolding/value/handlers/unfold-variant-shape.js +61 -0
  77. package/esm2022/lib/unfolding/value/handlers/unfold-variant-shape.js.map +1 -0
  78. package/esm2022/lib/unfolding/value/handlers/validate-props.js +20 -0
  79. package/esm2022/lib/unfolding/value/handlers/validate-props.js.map +1 -0
  80. package/esm2022/lib/unfolding/value/throw-unfold-value-error.js +11 -0
  81. package/esm2022/lib/unfolding/value/throw-unfold-value-error.js.map +1 -0
  82. package/esm2022/lib/unfolding/value/unfold-node-value.js +30 -0
  83. package/esm2022/lib/unfolding/value/unfold-node-value.js.map +1 -0
  84. package/esm2022/lib/util/is-object.js +4 -0
  85. package/esm2022/lib/util/is-object.js.map +1 -0
  86. package/esm2022/lib/util/stringify-object.js +4 -0
  87. package/esm2022/lib/util/stringify-object.js.map +1 -0
  88. package/esm2022/lib/util/unfold-component-definitions.js +21 -0
  89. package/esm2022/lib/util/unfold-component-definitions.js.map +1 -0
  90. package/index.d.ts +16 -0
  91. package/kaskad-schema.d.ts +5 -0
  92. package/lib/load/load-schema.d.ts +3 -0
  93. package/lib/load/load-templates.d.ts +2 -0
  94. package/lib/load/register-declared-type.d.ts +1 -0
  95. package/lib/load/schema-component-extractor.d.ts +2 -0
  96. package/lib/load/template-registry.d.ts +16 -0
  97. package/lib/types/component-definition.d.ts +5 -0
  98. package/lib/types/component-schema.d.ts +26 -0
  99. package/lib/types/raw-schemas.d.ts +25 -0
  100. package/lib/types/template-raw-definition.d.ts +7 -0
  101. package/lib/unfolding/computation/unfold-computation-schema.d.ts +2 -0
  102. package/lib/unfolding/computation/unfold-for-new-syntax.d.ts +6 -0
  103. package/lib/unfolding/computation/unfold-for.d.ts +2 -0
  104. package/lib/unfolding/computation/unfold-if.d.ts +3 -0
  105. package/lib/unfolding/computation/unfold-import.d.ts +2 -0
  106. package/lib/unfolding/computation/unfold-interpolation.d.ts +3 -0
  107. package/lib/unfolding/parse-binding-shorthand.d.ts +3 -0
  108. package/lib/unfolding/parse-property-key-shorthand.d.ts +2 -0
  109. package/lib/unfolding/parse-value-type.d.ts +2 -0
  110. package/lib/unfolding/to-full-notation.d.ts +8 -0
  111. package/lib/unfolding/unfold-flat-wrapper-notation.d.ts +13 -0
  112. package/lib/unfolding/unfold-node-schema.d.ts +3 -0
  113. package/lib/unfolding/unfold-property.d.ts +2 -0
  114. package/lib/unfolding/value/handlers/index.d.ts +10 -0
  115. package/lib/unfolding/value/handlers/unfold-array.d.ts +3 -0
  116. package/lib/unfolding/value/handlers/unfold-boolean.d.ts +2 -0
  117. package/lib/unfolding/value/handlers/unfold-command.d.ts +3 -0
  118. package/lib/unfolding/value/handlers/unfold-component-schema.d.ts +4 -0
  119. package/lib/unfolding/value/handlers/unfold-component.d.ts +3 -0
  120. package/lib/unfolding/value/handlers/unfold-map.d.ts +3 -0
  121. package/lib/unfolding/value/handlers/unfold-number.d.ts +2 -0
  122. package/lib/unfolding/value/handlers/unfold-object.d.ts +3 -0
  123. package/lib/unfolding/value/handlers/unfold-set.d.ts +3 -0
  124. package/lib/unfolding/value/handlers/unfold-shape.d.ts +3 -0
  125. package/lib/unfolding/value/handlers/unfold-string.d.ts +2 -0
  126. package/lib/unfolding/value/handlers/unfold-unknown.d.ts +2 -0
  127. package/lib/unfolding/value/handlers/unfold-variant-shape.d.ts +3 -0
  128. package/lib/unfolding/value/handlers/validate-props.d.ts +2 -0
  129. package/lib/unfolding/value/throw-unfold-value-error.d.ts +2 -0
  130. package/lib/unfolding/value/unfold-node-value.d.ts +8 -0
  131. package/lib/util/is-object.d.ts +1 -0
  132. package/lib/util/stringify-object.d.ts +1 -0
  133. package/lib/util/unfold-component-definitions.d.ts +4 -0
  134. package/package.json +28 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-map.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-map.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,UAAU,SAAS,CAAC,GAA4B;IACpD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAA6B,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACjG,SAAS,CAAC,GAAG,CAAC,GAAG,gBAAgB,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;QACrF,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import { MapValueType, NodeSchema } from '@kaskad/types';\n\nimport { isObject } from '../../../util/is-object';\nimport { unfoldNodeSchema } from '../../unfold-node-schema';\nimport { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nexport function unfoldMap(ctx: UnfoldCtx<MapValueType>) {\n if (!isObject(ctx.rawValue)) {\n throwUnfoldError(ctx);\n }\n return Object.entries(ctx.rawValue).reduce<Record<string, NodeSchema>>((structure, [key, child]) => {\n structure[key] = unfoldNodeSchema(child, ctx.valueType.item, [...ctx.nodePath, key]);\n return structure;\n }, {});\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { throwUnfoldError } from '../throw-unfold-value-error';
2
+ export function unfoldNumber(ctx) {
3
+ if (!isValidNumber(ctx.rawValue)) {
4
+ throwUnfoldError(ctx);
5
+ }
6
+ return ctx.rawValue;
7
+ }
8
+ function isValidNumber(value) {
9
+ return typeof value === 'number' && !isNaN(value);
10
+ }
11
+ //# sourceMappingURL=unfold-number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-number.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,UAAU,YAAY,CAAC,GAAc;IACzC,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC;AACtB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC","sourcesContent":["import { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nexport function unfoldNumber(ctx: UnfoldCtx) {\n if (!isValidNumber(ctx.rawValue)) {\n throwUnfoldError(ctx);\n }\n return ctx.rawValue;\n}\n\nfunction isValidNumber(value: unknown) {\n return typeof value === 'number' && !isNaN(value);\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { isObject } from '../../../util/is-object';
2
+ import { unfoldNodeSchema } from '../../unfold-node-schema';
3
+ import { throwUnfoldError } from '../throw-unfold-value-error';
4
+ export function unfoldObject(ctx) {
5
+ if (!isObject(ctx.rawValue)) {
6
+ throwUnfoldError(ctx);
7
+ }
8
+ const rawObject = ctx.rawValue;
9
+ return Object.entries(ctx.valueType.fields).reduce((structure, [fieldKey, fieldValueType]) => {
10
+ const fieldValue = fieldKey in rawObject ? rawObject[fieldKey] : null;
11
+ structure[fieldKey] = unfoldNodeSchema(fieldValue, fieldValueType, [...ctx.nodePath, fieldKey]);
12
+ return structure;
13
+ }, {});
14
+ }
15
+ //# sourceMappingURL=unfold-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-object.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-object.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,UAAU,YAAY,CAAC,GAA+B;IAC1D,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,CAAC,QAAmC,CAAC;IAE1D,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,MAAM,CAChD,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,EAAE,EAAE;QACxC,MAAM,UAAU,GAAG,QAAQ,IAAI,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACtE,SAAS,CAAC,QAAQ,CAAC,GAAG,gBAAgB,CAAC,UAAU,EAAE,cAAc,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;QAChG,OAAO,SAAS,CAAC;IACnB,CAAC,EACD,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { NodeSchema, ObjectValueType } from '@kaskad/types';\n\nimport { isObject } from '../../../util/is-object';\nimport { unfoldNodeSchema } from '../../unfold-node-schema';\nimport { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nexport function unfoldObject(ctx: UnfoldCtx<ObjectValueType>) {\n if (!isObject(ctx.rawValue)) {\n throwUnfoldError(ctx);\n }\n\n const rawObject = ctx.rawValue as Record<string, unknown>;\n\n return Object.entries(ctx.valueType.fields).reduce<Record<string, NodeSchema>>(\n (structure, [fieldKey, fieldValueType]) => {\n const fieldValue = fieldKey in rawObject ? rawObject[fieldKey] : null;\n structure[fieldKey] = unfoldNodeSchema(fieldValue, fieldValueType, [...ctx.nodePath, fieldKey]);\n return structure;\n },\n {},\n );\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { unfoldNodeSchema } from '../../unfold-node-schema';
2
+ export function unfoldSet(ctx) {
3
+ const items = ctx.rawValue instanceof Set ? Array.from(ctx.rawValue) : Array.isArray(ctx.rawValue) ? ctx.rawValue : [];
4
+ return items.map((item, index) => unfoldNodeSchema(item, ctx.valueType.item, [...ctx.nodePath, index]));
5
+ }
6
+ //# sourceMappingURL=unfold-set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-set.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-set.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAG5D,MAAM,UAAU,SAAS,CAAC,GAA4B;IACpD,MAAM,KAAK,GACT,GAAG,CAAC,QAAQ,YAAY,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAE3G,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC","sourcesContent":["import { SetValueType } from '@kaskad/types';\n\nimport { unfoldNodeSchema } from '../../unfold-node-schema';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nexport function unfoldSet(ctx: UnfoldCtx<SetValueType>) {\n const items =\n ctx.rawValue instanceof Set ? Array.from(ctx.rawValue) : Array.isArray(ctx.rawValue) ? ctx.rawValue : [];\n\n return items.map((item, index) => unfoldNodeSchema(item, ctx.valueType.item, [...ctx.nodePath, index]));\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { DefinitionStore } from '@kaskad/definition';
2
+ import { isObject } from '../../../util/is-object';
3
+ import { throwUnfoldError } from '../throw-unfold-value-error';
4
+ import { unfoldObject } from './unfold-object';
5
+ export function unfoldShape(ctx) {
6
+ if (!isObject(ctx.rawValue)) {
7
+ throwUnfoldError(ctx);
8
+ }
9
+ const rawValue = ctx.rawValue;
10
+ const objectValueType = DefinitionStore.getInstance().getShape(ctx.valueType.shapeType);
11
+ return unfoldObject({ rawValue, valueType: objectValueType, nodePath: ctx.nodePath });
12
+ }
13
+ //# sourceMappingURL=unfold-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-shape.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,UAAU,WAAW,CAAC,GAA8B;IACxD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAmC,CAAC;IACzD,MAAM,eAAe,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACxF,OAAO,YAAY,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;AACxF,CAAC","sourcesContent":["import { DefinitionStore } from '@kaskad/definition';\nimport { ShapeValue, ShapeValueType } from '@kaskad/types';\n\nimport { isObject } from '../../../util/is-object';\nimport { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\nimport { unfoldObject } from './unfold-object';\n\nexport function unfoldShape(ctx: UnfoldCtx<ShapeValueType>): ShapeValue {\n if (!isObject(ctx.rawValue)) {\n throwUnfoldError(ctx);\n }\n\n const rawValue = ctx.rawValue as Record<string, unknown>;\n const objectValueType = DefinitionStore.getInstance().getShape(ctx.valueType.shapeType);\n return unfoldObject({ rawValue, valueType: objectValueType, nodePath: ctx.nodePath });\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { throwUnfoldError } from '../throw-unfold-value-error';
2
+ export function unfoldString(ctx) {
3
+ if (typeof ctx.rawValue !== 'string') {
4
+ throwUnfoldError(ctx);
5
+ }
6
+ return ctx.rawValue;
7
+ }
8
+ //# sourceMappingURL=unfold-string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-string.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,MAAM,UAAU,YAAY,CAAC,GAAc;IACzC,IAAI,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACrC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC;AACtB,CAAC","sourcesContent":["import { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nexport function unfoldString(ctx: UnfoldCtx) {\n if (typeof ctx.rawValue !== 'string') {\n throwUnfoldError(ctx);\n }\n return ctx.rawValue;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export function unfoldUnknown(ctx) {
2
+ return ctx.rawValue;
3
+ }
4
+ //# sourceMappingURL=unfold-unknown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-unknown.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-unknown.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,aAAa,CAAC,GAAc;IAC1C,OAAO,GAAG,CAAC,QAAQ,CAAC;AACtB,CAAC","sourcesContent":["import { UnfoldCtx } from '../unfold-node-value';\n\nexport function unfoldUnknown(ctx: UnfoldCtx) {\n return ctx.rawValue;\n}\n"]}
@@ -0,0 +1,61 @@
1
+ import { DefinitionStore } from '@kaskad/definition';
2
+ import { isObject } from '../../../util/is-object';
3
+ import { unfoldNodeSchema } from '../../unfold-node-schema';
4
+ import { throwUnfoldError } from '../throw-unfold-value-error';
5
+ function unfoldShortValidatorSyntax(rawValue) {
6
+ if ('validatorType' in rawValue) {
7
+ return rawValue;
8
+ }
9
+ const entries = Object.entries(rawValue);
10
+ const validatorEntries = entries.filter(([key]) => key !== 'message' && key !== 'disabled');
11
+ if (validatorEntries.length === 0) {
12
+ throw new Error(`Validator must have at least one validator type specified. Raw value: ${JSON.stringify(rawValue)}`);
13
+ }
14
+ if (validatorEntries.length > 1) {
15
+ throw new Error(`Validator can only have one validator type specified. Raw value: ${JSON.stringify(rawValue)}`);
16
+ }
17
+ const [validatorType, param] = validatorEntries[0];
18
+ const validator = {
19
+ validatorType,
20
+ params: {},
21
+ message: rawValue['message'] || '',
22
+ disabled: !!rawValue['disabled'],
23
+ };
24
+ if (isObject(param)) {
25
+ validator.params = param;
26
+ }
27
+ else {
28
+ validator.params = { [validatorType]: param };
29
+ }
30
+ return validator;
31
+ }
32
+ export function unfoldVariantShape(ctx) {
33
+ if (!isObject(ctx.rawValue)) {
34
+ throwUnfoldError(ctx);
35
+ }
36
+ let rawValue = ctx.rawValue;
37
+ if ('kind' in rawValue && 'fields' in rawValue) {
38
+ const kindKey = `${ctx.valueType.shapeType}Type`;
39
+ const kind = rawValue['kind'];
40
+ const fields = rawValue['fields'];
41
+ return {
42
+ ...fields,
43
+ [kindKey]: kind,
44
+ };
45
+ }
46
+ const kindKey = `${ctx.valueType.shapeType}Type`;
47
+ if (kindKey === 'validatorType') {
48
+ rawValue = unfoldShortValidatorSyntax(rawValue);
49
+ }
50
+ const kind = rawValue[kindKey];
51
+ if (!kind) {
52
+ throw new Error(`Missing the kind field "${kindKey}"`);
53
+ }
54
+ const objectValueType = DefinitionStore.getInstance().getVariantShape(ctx.valueType.shapeType, kind);
55
+ const objectNode = unfoldNodeSchema(rawValue, objectValueType, ctx.nodePath);
56
+ return {
57
+ ...objectNode.value,
58
+ [kindKey]: kind,
59
+ };
60
+ }
61
+ //# sourceMappingURL=unfold-variant-shape.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-variant-shape.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/unfold-variant-shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGrD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAG/D,SAAS,0BAA0B,CAAC,QAAiC;IACnE,IAAI,eAAe,IAAI,QAAQ,EAAE,CAAC;QAChC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACzC,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,UAAU,CAAC,CAAC;IAE5F,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CACb,yEAAyE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CACpG,CAAC;IACJ,CAAC;IACD,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,oEAAoE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAClH,CAAC;IAED,MAAM,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAEnD,MAAM,SAAS,GAAG;QAChB,aAAa;QACb,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,IAAI,EAAE;QAClC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC;KACjC,CAAC;IAEF,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACpB,SAAS,CAAC,MAAM,GAAG,KAAK,CAAC;IAC3B,CAAC;SAAM,CAAC;QACN,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC;IAChD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,GAAqC;IACtE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAmC,CAAC;IAEvD,IAAI,MAAM,IAAI,QAAQ,IAAI,QAAQ,IAAI,QAAQ,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,SAAS,MAAM,CAAC;QACjD,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAW,CAAC;QACxC,MAAM,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAA4B,CAAC;QAE7D,OAAO;YACL,GAAG,MAAM;YACT,CAAC,OAAO,CAAC,EAAE,IAAI;SACK,CAAC;IACzB,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,SAAS,MAAM,CAAC;IAEjD,IAAI,OAAO,KAAK,eAAe,EAAE,CAAC;QAChC,QAAQ,GAAG,0BAA0B,CAAC,QAAQ,CAAC,CAAC;IAClD,CAAC;IAED,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAW,CAAC;IAEzC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,2BAA2B,OAAO,GAAG,CAAC,CAAC;IACzD,CAAC;IAED,MAAM,eAAe,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAErG,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7E,OAAO;QACL,GAAI,UAAU,CAAC,KAAoC;QACnD,CAAC,OAAO,CAAC,EAAE,IAAI;KAChB,CAAC;AACJ,CAAC","sourcesContent":["import { DefinitionStore } from '@kaskad/definition';\nimport { NodeSchema, VariantShapeValue, VariantShapeValueType } from '@kaskad/types';\n\nimport { isObject } from '../../../util/is-object';\nimport { unfoldNodeSchema } from '../../unfold-node-schema';\nimport { throwUnfoldError } from '../throw-unfold-value-error';\nimport { UnfoldCtx } from '../unfold-node-value';\n\nfunction unfoldShortValidatorSyntax(rawValue: Record<string, unknown>) {\n if ('validatorType' in rawValue) {\n return rawValue;\n }\n\n const entries = Object.entries(rawValue);\n const validatorEntries = entries.filter(([key]) => key !== 'message' && key !== 'disabled');\n\n if (validatorEntries.length === 0) {\n throw new Error(\n `Validator must have at least one validator type specified. Raw value: ${JSON.stringify(rawValue)}`,\n );\n }\n if (validatorEntries.length > 1) {\n throw new Error(`Validator can only have one validator type specified. Raw value: ${JSON.stringify(rawValue)}`);\n }\n\n const [validatorType, param] = validatorEntries[0];\n\n const validator = {\n validatorType,\n params: {},\n message: rawValue['message'] || '',\n disabled: !!rawValue['disabled'],\n };\n\n if (isObject(param)) {\n validator.params = param;\n } else {\n validator.params = { [validatorType]: param };\n }\n\n return validator;\n}\n\nexport function unfoldVariantShape(ctx: UnfoldCtx<VariantShapeValueType>): VariantShapeValue {\n if (!isObject(ctx.rawValue)) {\n throwUnfoldError(ctx);\n }\n\n let rawValue = ctx.rawValue as Record<string, unknown>;\n\n if ('kind' in rawValue && 'fields' in rawValue) {\n const kindKey = `${ctx.valueType.shapeType}Type`;\n const kind = rawValue['kind'] as string;\n const fields = rawValue['fields'] as Record<string, unknown>;\n\n return {\n ...fields,\n [kindKey]: kind,\n } as VariantShapeValue;\n }\n\n const kindKey = `${ctx.valueType.shapeType}Type`;\n\n if (kindKey === 'validatorType') {\n rawValue = unfoldShortValidatorSyntax(rawValue);\n }\n\n const kind = rawValue[kindKey] as string;\n\n if (!kind) {\n throw new Error(`Missing the kind field \"${kindKey}\"`);\n }\n\n const objectValueType = DefinitionStore.getInstance().getVariantShape(ctx.valueType.shapeType, kind);\n\n const objectNode = unfoldNodeSchema(rawValue, objectValueType, ctx.nodePath);\n return {\n ...(objectNode.value as Record<string, NodeSchema>),\n [kindKey]: kind,\n };\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import { Delimiters } from '@kaskad/config';
2
+ import { DefinitionStore } from '@kaskad/definition';
3
+ export function validateProps(rawSchema) {
4
+ const componentDefinitionProps = DefinitionStore.getInstance().getComputedComponentContract(rawSchema.componentType);
5
+ const ignoredSchemaProps = new Set([
6
+ 'componentType',
7
+ 'onNodeChange',
8
+ 'ref',
9
+ 'contract',
10
+ 'defaultSlot',
11
+ 'context',
12
+ 'types',
13
+ 'importTypes',
14
+ ]);
15
+ const invalidProps = Object.keys(rawSchema).filter((prop) => !componentDefinitionProps[prop] && !ignoredSchemaProps.has(prop) && !prop.startsWith(Delimiters.Variable));
16
+ if (invalidProps.length) {
17
+ throw new Error(`Component schema "${rawSchema.componentType}" contains unknown properties: ${invalidProps.join(', ')}`);
18
+ }
19
+ }
20
+ //# sourceMappingURL=validate-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-props.js","sourceRoot":"","sources":["../../../../../../../../libs/schema/src/lib/unfolding/value/handlers/validate-props.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAIrD,MAAM,UAAU,aAAa,CAAC,SAA0B;IACtD,MAAM,wBAAwB,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC,4BAA4B,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IACrH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC;QACjC,eAAe;QACf,cAAc;QACd,KAAK;QACL,UAAU;QACV,aAAa;QACb,SAAS;QACT,OAAO;QACP,aAAa;KACd,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,MAAM,CAChD,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CACpH,CAAC;IAEF,IAAI,YAAY,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,qBAAqB,SAAS,CAAC,aAAa,kCAAkC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACxG,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { Delimiters } from '@kaskad/config';\nimport { DefinitionStore } from '@kaskad/definition';\n\nimport { ComponentRecipe } from '../../../types/component-schema';\n\nexport function validateProps(rawSchema: ComponentRecipe) {\n const componentDefinitionProps = DefinitionStore.getInstance().getComputedComponentContract(rawSchema.componentType);\n const ignoredSchemaProps = new Set([\n 'componentType',\n 'onNodeChange',\n 'ref',\n 'contract',\n 'defaultSlot',\n 'context',\n 'types',\n 'importTypes',\n ]);\n\n const invalidProps = Object.keys(rawSchema).filter(\n (prop) => !componentDefinitionProps[prop] && !ignoredSchemaProps.has(prop) && !prop.startsWith(Delimiters.Variable),\n );\n\n if (invalidProps.length) {\n throw new Error(\n `Component schema \"${rawSchema.componentType}\" contains unknown properties: ${invalidProps.join(', ')}`,\n );\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { stringifyObject } from '../../util/stringify-object';
2
+ export function throwUnfoldError(ctx) {
3
+ let message = 'Error happened while unfolding node';
4
+ if (ctx.nodePath) {
5
+ message += `\nPath: ${JSON.stringify(ctx.nodePath)}.`;
6
+ }
7
+ message += stringifyObject('ValueType', ctx.valueType);
8
+ message += stringifyObject('Provided value', ctx.rawValue);
9
+ throw new Error(message);
10
+ }
11
+ //# sourceMappingURL=throw-unfold-value-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throw-unfold-value-error.js","sourceRoot":"","sources":["../../../../../../../libs/schema/src/lib/unfolding/value/throw-unfold-value-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,MAAM,UAAU,gBAAgB,CAAC,GAAc;IAC7C,IAAI,OAAO,GAAG,qCAAqC,CAAC;IACpD,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;QACjB,OAAO,IAAI,WAAW,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC;IACxD,CAAC;IACD,OAAO,IAAI,eAAe,CAAC,WAAW,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;IACvD,OAAO,IAAI,eAAe,CAAC,gBAAgB,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE3D,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { stringifyObject } from '../../util/stringify-object';\nimport { UnfoldCtx } from './unfold-node-value';\n\nexport function throwUnfoldError(ctx: UnfoldCtx): never {\n let message = 'Error happened while unfolding node';\n if (ctx.nodePath) {\n message += `\\nPath: ${JSON.stringify(ctx.nodePath)}.`;\n }\n message += stringifyObject('ValueType', ctx.valueType);\n message += stringifyObject('Provided value', ctx.rawValue);\n\n throw new Error(message);\n}\n"]}
@@ -0,0 +1,30 @@
1
+ import { unfoldArray, unfoldBoolean, unfoldCommand, unfoldComponent, unfoldComponentSchema, unfoldMap, unfoldNumber, unfoldObject, unfoldString, unfoldUnknown, } from './handlers';
2
+ import { unfoldSet } from './handlers/unfold-set';
3
+ import { unfoldShape } from './handlers/unfold-shape';
4
+ import { unfoldVariantShape } from './handlers/unfold-variant-shape';
5
+ const handlers = {
6
+ unknown: unfoldUnknown,
7
+ number: unfoldNumber,
8
+ string: unfoldString,
9
+ boolean: unfoldBoolean,
10
+ array: unfoldArray,
11
+ map: unfoldMap,
12
+ set: unfoldSet,
13
+ object: unfoldObject,
14
+ shape: unfoldShape,
15
+ variantShape: unfoldVariantShape,
16
+ command: unfoldCommand,
17
+ componentSchema: unfoldComponentSchema,
18
+ component: unfoldComponent,
19
+ };
20
+ export function unfoldValue(ctx) {
21
+ const handler = handlers[ctx.valueType.type];
22
+ if (!handler) {
23
+ throw new Error(`Cannot unfold value "${ctx.rawValue}". Unknown value type '${ctx.valueType.type}'`);
24
+ }
25
+ if (ctx.rawValue === undefined || ctx.rawValue === null) {
26
+ return null;
27
+ }
28
+ return handler(ctx);
29
+ }
30
+ //# sourceMappingURL=unfold-node-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-node-value.js","sourceRoot":"","sources":["../../../../../../../libs/schema/src/lib/unfolding/value/unfold-node-value.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,WAAW,EACX,aAAa,EACb,aAAa,EACb,eAAe,EACf,qBAAqB,EACrB,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAUrE,MAAM,QAAQ,GAAuC;IACnD,OAAO,EAAE,aAAa;IACtB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,aAAa;IACtB,KAAK,EAAE,WAAW;IAClB,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,WAAW;IAClB,YAAY,EAAE,kBAAkB;IAChC,OAAO,EAAE,aAAa;IACtB,eAAe,EAAE,qBAAqB;IACtC,SAAS,EAAE,eAAe;CAC3B,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,GAAc;IACxC,MAAM,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAY,CAAC;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,CAAC,QAAQ,0BAA0B,GAAG,CAAC,SAAS,CAAC,IAAI,GAAG,CAAC,CAAC;IACvG,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,GAAG,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QACxD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC;AACtB,CAAC","sourcesContent":["import { NodePath, NodeSchema, ValueType } from '@kaskad/types';\n\nimport {\n unfoldArray,\n unfoldBoolean,\n unfoldCommand,\n unfoldComponent,\n unfoldComponentSchema,\n unfoldMap,\n unfoldNumber,\n unfoldObject,\n unfoldString,\n unfoldUnknown,\n} from './handlers';\nimport { unfoldSet } from './handlers/unfold-set';\nimport { unfoldShape } from './handlers/unfold-shape';\nimport { unfoldVariantShape } from './handlers/unfold-variant-shape';\n\nexport type UnfoldCtx<T extends ValueType = ValueType> = {\n rawValue: unknown;\n valueType: T;\n nodePath: NodePath;\n};\n\nexport type Handler = (ctx: UnfoldCtx) => NodeSchema['value'];\n\nconst handlers: Record<ValueType['type'], unknown> = {\n unknown: unfoldUnknown,\n number: unfoldNumber,\n string: unfoldString,\n boolean: unfoldBoolean,\n array: unfoldArray,\n map: unfoldMap,\n set: unfoldSet,\n object: unfoldObject,\n shape: unfoldShape,\n variantShape: unfoldVariantShape,\n command: unfoldCommand,\n componentSchema: unfoldComponentSchema,\n component: unfoldComponent,\n};\n\nexport function unfoldValue(ctx: UnfoldCtx) {\n const handler = handlers[ctx.valueType.type] as Handler;\n if (!handler) {\n throw new Error(`Cannot unfold value \"${ctx.rawValue}\". Unknown value type '${ctx.valueType.type}'`);\n }\n if (ctx.rawValue === undefined || ctx.rawValue === null) {\n return null;\n }\n return handler(ctx);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export function isObject(value) {
2
+ return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Set);
3
+ }
4
+ //# sourceMappingURL=is-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-object.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/util/is-object.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,CAAC;AACzG,CAAC","sourcesContent":["export function isObject(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Set);\n}\n"]}
@@ -0,0 +1,4 @@
1
+ export function stringifyObject(label, data) {
2
+ return `\n${label}:\n${JSON.stringify(data, null, 2)}`;
3
+ }
4
+ //# sourceMappingURL=stringify-object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringify-object.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/util/stringify-object.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,IAAa;IAC1D,OAAO,KAAK,KAAK,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;AACzD,CAAC","sourcesContent":["export function stringifyObject(label: string, data: unknown): string {\n return `\\n${label}:\\n${JSON.stringify(data, null, 2)}`;\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import { unfoldProperty } from '../unfolding/unfold-property';
2
+ export function unfoldComponentDefinition(rawDefinition) {
3
+ const properties = {};
4
+ for (const entry of Object.entries(rawDefinition.properties)) {
5
+ const [key, prop] = unfoldProperty(...entry);
6
+ properties[key] = prop;
7
+ }
8
+ return {
9
+ traits: rawDefinition.traits,
10
+ properties,
11
+ defaultSlot: rawDefinition.defaultSlot,
12
+ };
13
+ }
14
+ export function unfoldComponentDefinitions(rawDefinitions) {
15
+ const result = {};
16
+ for (const [componentType, rawDefinition] of Object.entries(rawDefinitions)) {
17
+ result[componentType] = unfoldComponentDefinition(rawDefinition);
18
+ }
19
+ return result;
20
+ }
21
+ //# sourceMappingURL=unfold-component-definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unfold-component-definitions.js","sourceRoot":"","sources":["../../../../../../libs/schema/src/lib/util/unfold-component-definitions.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,MAAM,UAAU,yBAAyB,CAAC,aAAqC;IAC7E,MAAM,UAAU,GAA+B,EAAE,CAAC;IAElD,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7D,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,cAAc,CAAC,GAAG,KAAK,CAAC,CAAC;QAC7C,UAAU,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,OAAO;QACL,MAAM,EAAE,aAAa,CAAC,MAAM;QAC5B,UAAU;QACV,WAAW,EAAE,aAAa,CAAC,WAAW;KACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,cAAsD;IAEtD,MAAM,MAAM,GAAwC,EAAE,CAAC;IAEvD,KAAK,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;QAC5E,MAAM,CAAC,aAAa,CAAC,GAAG,yBAAyB,CAAC,aAAa,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ComponentDefinition } from '@kaskad/definition';\nimport { NodeSchema } from '@kaskad/types';\n\nimport { ComponentRawDefinition } from '../types/component-definition';\nimport { unfoldProperty } from '../unfolding/unfold-property';\n\nexport function unfoldComponentDefinition(rawDefinition: ComponentRawDefinition): ComponentDefinition {\n const properties: Record<string, NodeSchema> = {};\n\n for (const entry of Object.entries(rawDefinition.properties)) {\n const [key, prop] = unfoldProperty(...entry);\n properties[key] = prop;\n }\n\n return {\n traits: rawDefinition.traits,\n properties,\n defaultSlot: rawDefinition.defaultSlot,\n };\n}\n\nexport function unfoldComponentDefinitions(\n rawDefinitions: Record<string, ComponentRawDefinition>,\n): Record<string, ComponentDefinition> {\n const result: Record<string, ComponentDefinition> = {};\n\n for (const [componentType, rawDefinition] of Object.entries(rawDefinitions)) {\n result[componentType] = unfoldComponentDefinition(rawDefinition);\n }\n\n return result;\n}\n"]}
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export * from './lib/types/component-schema';
2
+ export * from './lib/types/raw-schemas';
3
+ export * from './lib/types/component-definition';
4
+ export * from './lib/types/template-raw-definition';
5
+ export * from './lib/unfolding/unfold-node-schema';
6
+ export * from './lib/unfolding/unfold-property';
7
+ export * from './lib/unfolding/unfold-flat-wrapper-notation';
8
+ export * from './lib/unfolding/parse-value-type';
9
+ export * from './lib/unfolding/to-full-notation';
10
+ export * from './lib/load/schema-component-extractor';
11
+ export * from './lib/load/template-registry';
12
+ export * from './lib/load/load-templates';
13
+ export * from './lib/load/load-schema';
14
+ export * from './lib/load/register-declared-type';
15
+ export * from './lib/util/unfold-component-definitions';
16
+ export * from './lib/util/is-object';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Generated bundle index. Do not edit.
3
+ */
4
+ /// <amd-module name="@kaskad/schema" />
5
+ export * from './index';
@@ -0,0 +1,3 @@
1
+ import { TemplateRecipeDefinition } from '../types/template-raw-definition';
2
+ export declare const withBaseTemplateUrl: (url: string) => string;
3
+ export declare function loadRecipe(url: string): Promise<TemplateRecipeDefinition>;
@@ -0,0 +1,2 @@
1
+ import { ComponentRecipe, TemplateRecipe } from '../types/component-schema';
2
+ export declare function loadTemplates(recipe: TemplateRecipe | ComponentRecipe): Promise<void>;
@@ -0,0 +1 @@
1
+ export declare function registerDeclaredType(name: string, definition: string | Record<string, string>): void;
@@ -0,0 +1,2 @@
1
+ import { NodeSchema } from '@kaskad/types';
2
+ export declare function extractComponentTypes(schema: NodeSchema, types?: Set<string>): Set<string>;
@@ -0,0 +1,16 @@
1
+ import { TemplateRecipeDefinition } from '../types/template-raw-definition';
2
+ interface TemplateEntry {
3
+ recipe: TemplateRecipeDefinition;
4
+ ownComponentTypes: Set<string>;
5
+ dependencies: Set<string>;
6
+ }
7
+ export declare const templateRegistry: {
8
+ entries: Map<string, TemplateEntry>;
9
+ get(url: string): TemplateEntry | undefined;
10
+ getAggregatedComponentTypes(url: string): Set<string>;
11
+ getAllComponentTypes(): Set<string>;
12
+ set(url: string, recipe: TemplateRecipeDefinition, ownComponentTypes: Set<string>, dependencies?: Set<string>): void;
13
+ has(url: string): boolean;
14
+ reset(): void;
15
+ };
16
+ export {};
@@ -0,0 +1,5 @@
1
+ export type ComponentRawDefinition = {
2
+ readonly traits?: string[];
3
+ readonly properties: Record<string, unknown>;
4
+ readonly defaultSlot?: string;
5
+ };
@@ -0,0 +1,26 @@
1
+ import { ComponentRef } from '@kaskad/types';
2
+ export type Defer = {
3
+ placeholder?: {
4
+ componentType: string;
5
+ } & {
6
+ [key: string]: unknown;
7
+ };
8
+ error?: {
9
+ componentType: string;
10
+ } & {
11
+ [key: string]: unknown;
12
+ };
13
+ };
14
+ export interface NodeChangeHandlerRecipe {
15
+ selector: string;
16
+ command: unknown;
17
+ }
18
+ export interface ComponentRecipe {
19
+ ref?: ComponentRef;
20
+ componentType: string;
21
+ onNodeChange?: NodeChangeHandlerRecipe[];
22
+ [propOrVariable: string]: unknown;
23
+ }
24
+ export type TemplateRecipe = Omit<ComponentRecipe, 'componentType'> & {
25
+ templateUrl: string;
26
+ };
@@ -0,0 +1,25 @@
1
+ export type FormulaComputationRecipe = {
2
+ formula: string;
3
+ };
4
+ export type ForComputationRecipe = {
5
+ items: unknown[];
6
+ as?: {
7
+ item: unknown;
8
+ index: unknown;
9
+ first?: unknown;
10
+ last?: unknown;
11
+ };
12
+ yield: unknown;
13
+ };
14
+ export type IfComputationRecipe = Record<'if' | 'then' | 'else', unknown> | ({
15
+ if: unknown;
16
+ } & Record<string, unknown>);
17
+ export type SwitchComputationRecipe = {
18
+ computationType: 'switch';
19
+ source: unknown;
20
+ cases: {
21
+ equals: unknown;
22
+ then: unknown;
23
+ }[];
24
+ default: unknown;
25
+ };
@@ -0,0 +1,7 @@
1
+ import { ComponentRecipe } from './component-schema';
2
+ export interface TemplateRecipeDefinition extends ComponentRecipe {
3
+ types?: Record<string, string | Record<string, string>>;
4
+ importTypes?: string[];
5
+ contract?: Record<string, string>;
6
+ defaultSlot?: string;
7
+ }
@@ -0,0 +1,2 @@
1
+ import { ComputationSchema } from '@kaskad/types';
2
+ export declare function unfoldComputationSchema(schema: unknown): ComputationSchema | null;
@@ -0,0 +1,6 @@
1
+ import { ComputationSchema } from '@kaskad/types';
2
+ /**
3
+ * Unfolds the new for-loop syntax into a ForComputationSchema
4
+ * Supports: for: "$item@Type of $items" or for: ["$item1@Type1 of $items1", "$item2@Type2 of $items2"]
5
+ */
6
+ export declare function unfoldForWithNewSyntax(schema: unknown): ComputationSchema | null;
@@ -0,0 +1,2 @@
1
+ import { ComputationSchema } from '@kaskad/types';
2
+ export declare function unfoldForComputationSchema(schema: unknown): ComputationSchema | null;
@@ -0,0 +1,3 @@
1
+ import { ComputationSchema } from '@kaskad/types';
2
+ import { IfComputationRecipe } from '../../types/raw-schemas';
3
+ export declare function unfoldIfComputationSchema(schema: IfComputationRecipe): ComputationSchema;
@@ -0,0 +1,2 @@
1
+ import { TemplateComputationSchema } from '@kaskad/types';
2
+ export declare function unfoldImportComputationSchema(schema: unknown): TemplateComputationSchema | null;
@@ -0,0 +1,3 @@
1
+ import { ComputationSchema } from '@kaskad/types';
2
+ export declare function unfoldInterpolationComputationSchema(schema: string): ComputationSchema | null;
3
+ export declare function replaceInterpolationsInFormula(formula: string): string;
@@ -0,0 +1,3 @@
1
+ import { BindingSchema } from '@kaskad/types';
2
+ export declare function parseBindingShorthand(value: string): BindingSchema | null;
3
+ export declare function isBindingShorthand(value: string): boolean;
@@ -0,0 +1,2 @@
1
+ import { ValueType } from '@kaskad/types';
2
+ export declare function parsePropertyKeyShorthand(shorthand: string): [string, ValueType];
@@ -0,0 +1,2 @@
1
+ import { ValueType } from '@kaskad/types';
2
+ export declare function parseValueType(type: string): ValueType;
@@ -0,0 +1,8 @@
1
+ import { ValueType } from '@kaskad/types';
2
+ export type RawNode = {
3
+ _valueType: ValueType;
4
+ _value: unknown;
5
+ _computation: unknown;
6
+ _binding: unknown;
7
+ };
8
+ export declare function toFullNotation(nodeSchema: unknown, valueType: ValueType): RawNode;
@@ -0,0 +1,13 @@
1
+ import { ComponentRecipe, TemplateRecipe } from '../types/component-schema';
2
+ import { RawNode } from './to-full-notation';
3
+ type WrapperEntity = [string, Record<string, unknown>];
4
+ type ComposedSchema = ComponentRecipe | RawNode | {
5
+ computationType: string;
6
+ [x: string]: unknown;
7
+ };
8
+ export declare const WrapperPrefix = "+";
9
+ export declare const PathSymbol = "/";
10
+ export declare function unfoldFlatWrappers(wrappers: WrapperEntity[], schema: ComposedSchema, resultingNode: RawNode): RawNode;
11
+ export declare function extractWrappers(schema: ComponentRecipe | TemplateRecipe): [WrapperEntity[], ComponentRecipe | TemplateRecipe];
12
+ export declare function hasWrappers(schema: ComponentRecipe | TemplateRecipe): boolean;
13
+ export {};
@@ -0,0 +1,3 @@
1
+ import { NodePath, NodeSchema, ValueType } from '@kaskad/types';
2
+ export declare function unfoldNodeSchema(rawSchema: unknown, valueType: ValueType, nodePath?: NodePath): NodeSchema;
3
+ export declare function isUnfoldedNodeSchema(nodeSchema: unknown): nodeSchema is NodeSchema;
@@ -0,0 +1,2 @@
1
+ import { NodeSchema } from '@kaskad/types';
2
+ export declare function unfoldProperty(keyEx: string, rawSchema: unknown): [string, NodeSchema];
@@ -0,0 +1,10 @@
1
+ export * from './unfold-boolean';
2
+ export * from './unfold-number';
3
+ export * from './unfold-string';
4
+ export * from './unfold-unknown';
5
+ export * from './unfold-array';
6
+ export * from './unfold-map';
7
+ export * from './unfold-object';
8
+ export * from './unfold-command';
9
+ export * from './unfold-component-schema';
10
+ export * from './unfold-component';
@@ -0,0 +1,3 @@
1
+ import { ArrayValueType } from '@kaskad/types';
2
+ import { UnfoldCtx } from '../unfold-node-value';
3
+ export declare function unfoldArray(ctx: UnfoldCtx<ArrayValueType>): import("@kaskad/types").NodeSchema[];
@@ -0,0 +1,2 @@
1
+ import { UnfoldCtx } from '../unfold-node-value';
2
+ export declare const unfoldBoolean: (ctx: UnfoldCtx) => boolean;
@@ -0,0 +1,3 @@
1
+ import { CommandValue, CommandValueType } from '@kaskad/types';
2
+ import { UnfoldCtx } from '../unfold-node-value';
3
+ export declare function unfoldCommand(ctx: UnfoldCtx<CommandValueType>): CommandValue;
@@ -0,0 +1,4 @@
1
+ import { ComponentSchemaValueType } from '@kaskad/types';
2
+ import { ComponentRecipe } from '../../../types/component-schema';
3
+ import { UnfoldCtx } from '../unfold-node-value';
4
+ export declare function unfoldComponentSchema(ctx: UnfoldCtx<ComponentSchemaValueType>): ComponentRecipe;
@@ -0,0 +1,3 @@
1
+ import { ComponentNodeValue } from '@kaskad/types';
2
+ import { UnfoldCtx } from '../unfold-node-value';
3
+ export declare function unfoldComponent(ctx: UnfoldCtx): ComponentNodeValue;
@@ -0,0 +1,3 @@
1
+ import { MapValueType, NodeSchema } from '@kaskad/types';
2
+ import { UnfoldCtx } from '../unfold-node-value';
3
+ export declare function unfoldMap(ctx: UnfoldCtx<MapValueType>): Record<string, NodeSchema>;
@@ -0,0 +1,2 @@
1
+ import { UnfoldCtx } from '../unfold-node-value';
2
+ export declare function unfoldNumber(ctx: UnfoldCtx): unknown;
@@ -0,0 +1,3 @@
1
+ import { NodeSchema, ObjectValueType } from '@kaskad/types';
2
+ import { UnfoldCtx } from '../unfold-node-value';
3
+ export declare function unfoldObject(ctx: UnfoldCtx<ObjectValueType>): Record<string, NodeSchema>;
@@ -0,0 +1,3 @@
1
+ import { SetValueType } from '@kaskad/types';
2
+ import { UnfoldCtx } from '../unfold-node-value';
3
+ export declare function unfoldSet(ctx: UnfoldCtx<SetValueType>): import("@kaskad/types").NodeSchema[];
@@ -0,0 +1,3 @@
1
+ import { ShapeValue, ShapeValueType } from '@kaskad/types';
2
+ import { UnfoldCtx } from '../unfold-node-value';
3
+ export declare function unfoldShape(ctx: UnfoldCtx<ShapeValueType>): ShapeValue;
@@ -0,0 +1,2 @@
1
+ import { UnfoldCtx } from '../unfold-node-value';
2
+ export declare function unfoldString(ctx: UnfoldCtx): string;
@@ -0,0 +1,2 @@
1
+ import { UnfoldCtx } from '../unfold-node-value';
2
+ export declare function unfoldUnknown(ctx: UnfoldCtx): unknown;
@@ -0,0 +1,3 @@
1
+ import { VariantShapeValue, VariantShapeValueType } from '@kaskad/types';
2
+ import { UnfoldCtx } from '../unfold-node-value';
3
+ export declare function unfoldVariantShape(ctx: UnfoldCtx<VariantShapeValueType>): VariantShapeValue;