@teambit/semantics.entities.semantic-schema 0.0.100 → 0.0.102

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 (41) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +42 -0
  3. package/dist/index.js.map +1 -1
  4. package/dist/schema-diff-members.d.ts +3 -0
  5. package/dist/schema-diff-members.js +171 -0
  6. package/dist/schema-diff-members.js.map +1 -0
  7. package/dist/schema-diff.d.ts +13 -0
  8. package/dist/schema-diff.js +138 -0
  9. package/dist/schema-diff.js.map +1 -0
  10. package/dist/schema-node.d.ts +10 -2
  11. package/dist/schema-node.js +49 -0
  12. package/dist/schema-node.js.map +1 -1
  13. package/dist/schemas/class.d.ts +2 -0
  14. package/dist/schemas/class.js +11 -0
  15. package/dist/schemas/class.js.map +1 -1
  16. package/dist/schemas/enum.d.ts +2 -0
  17. package/dist/schemas/enum.js +55 -0
  18. package/dist/schemas/enum.js.map +1 -1
  19. package/dist/schemas/function-like.d.ts +9 -0
  20. package/dist/schemas/function-like.js +300 -0
  21. package/dist/schemas/function-like.js.map +1 -1
  22. package/dist/schemas/interface.d.ts +2 -0
  23. package/dist/schemas/interface.js +11 -0
  24. package/dist/schemas/interface.js.map +1 -1
  25. package/dist/schemas/type.d.ts +2 -0
  26. package/dist/schemas/type.js +25 -0
  27. package/dist/schemas/type.js.map +1 -1
  28. package/dist/schemas/variable-like.d.ts +2 -0
  29. package/dist/schemas/variable-like.js +60 -0
  30. package/dist/schemas/variable-like.js.map +1 -1
  31. package/index.ts +2 -0
  32. package/package.json +2 -2
  33. package/schema-diff-members.ts +164 -0
  34. package/schema-diff.ts +168 -0
  35. package/schema-node.ts +37 -2
  36. package/schemas/class.ts +7 -0
  37. package/schemas/enum.ts +46 -0
  38. package/schemas/function-like.ts +277 -0
  39. package/schemas/interface.ts +7 -0
  40. package/schemas/type.ts +18 -0
  41. package/schemas/variable-like.ts +54 -0
@@ -1,6 +1,8 @@
1
1
  import chalk from 'chalk';
2
2
  import type { SchemaLocation } from '../schema-node';
3
3
  import { SchemaNode } from '../schema-node';
4
+ import type { SchemaChangeFact } from '../schema-diff';
5
+ import { typesAreSemanticallyEqual, typeStr, diffDoc } from '../schema-diff';
4
6
  import { DocSchema } from './docs';
5
7
  import { SchemaRegistry } from '../schema-registry';
6
8
 
@@ -64,6 +66,58 @@ export class VariableLikeSchema extends SchemaNode {
64
66
  };
65
67
  }
66
68
 
69
+ diff(other: SchemaNode): SchemaChangeFact[] {
70
+ if (!(other instanceof VariableLikeSchema)) return super.diff(other);
71
+ const facts: SchemaChangeFact[] = [];
72
+ if (!typesAreSemanticallyEqual(this.type.toObject(), other.type.toObject())) {
73
+ facts.push({
74
+ changeKind: 'type-annotation-changed',
75
+ description: `type changed: ${typeStr(this.type.toObject())} → ${typeStr(other.type.toObject())}`,
76
+ context: {
77
+ fromType: typeStr(this.type.toObject()),
78
+ toType: typeStr(other.type.toObject()),
79
+ position: 'variable',
80
+ },
81
+ from: typeStr(this.type.toObject()),
82
+ to: typeStr(other.type.toObject()),
83
+ });
84
+ }
85
+ if (this.isOptional && !other.isOptional) {
86
+ facts.push({
87
+ changeKind: 'became-required',
88
+ description: 'became required (was optional)',
89
+ context: { position: 'variable' },
90
+ from: 'optional',
91
+ to: 'required',
92
+ });
93
+ } else if (!this.isOptional && other.isOptional) {
94
+ facts.push({
95
+ changeKind: 'became-optional',
96
+ description: 'became optional (was required)',
97
+ context: { position: 'variable' },
98
+ from: 'required',
99
+ to: 'optional',
100
+ });
101
+ }
102
+ if (this.defaultValue !== other.defaultValue) {
103
+ const changeKind =
104
+ this.defaultValue === undefined
105
+ ? 'parameter-default-added'
106
+ : other.defaultValue === undefined
107
+ ? 'parameter-default-removed'
108
+ : 'parameter-default-changed';
109
+ facts.push({
110
+ changeKind,
111
+ description: `default value changed: ${this.defaultValue ?? 'none'} → ${other.defaultValue ?? 'none'}`,
112
+ context: { previousDefault: this.defaultValue, newDefault: other.defaultValue },
113
+ from: this.defaultValue,
114
+ to: other.defaultValue,
115
+ });
116
+ }
117
+ facts.push(...diffDoc(this.doc?.toObject(), other.doc?.toObject()));
118
+ return facts;
119
+ }
120
+
67
121
  static fromObject(obj: Record<string, any>): VariableLikeSchema {
68
122
  const location = obj.location;
69
123
  const name = obj.name;