@twin.org/entity 0.0.3-next.36 → 0.0.3-next.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/index.js +2 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IEntitySchemaDiff.js +2 -0
- package/dist/es/models/IEntitySchemaDiff.js.map +1 -0
- package/dist/es/utils/entitySchemaDiff.js +67 -0
- package/dist/es/utils/entitySchemaDiff.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/models/IEntitySchemaDiff.d.ts +35 -0
- package/dist/types/utils/entitySchemaDiff.d.ts +22 -0
- package/docs/changelog.md +38 -0
- package/docs/reference/functions/entitySchemaDiff.md +38 -0
- package/docs/reference/functions/isEmptyDiff.md +25 -0
- package/docs/reference/index.md +3 -0
- package/docs/reference/interfaces/IEntitySchemaDiff.md +53 -0
- package/package.json +3 -3
package/dist/es/index.js
CHANGED
|
@@ -18,5 +18,7 @@ export * from "./models/sortDirection.js";
|
|
|
18
18
|
export * from "./utils/decoratorHelper.js";
|
|
19
19
|
export * from "./utils/entityConditions.js";
|
|
20
20
|
export * from "./utils/entitySchemaHelper.js";
|
|
21
|
+
export * from "./utils/entitySchemaDiff.js";
|
|
21
22
|
export * from "./utils/entitySorter.js";
|
|
23
|
+
export * from "./models/IEntitySchemaDiff.js";
|
|
22
24
|
//# sourceMappingURL=index.js.map
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,yBAAyB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./decorators/entityDecorator.js\";\nexport * from \"./decorators/propertyDecorator.js\";\nexport * from \"./factories/entitySchemaFactory.js\";\nexport * from \"./models/comparisonOperator.js\";\nexport * from \"./models/entityCondition.js\";\nexport * from \"./models/entitySchemaPropertyFormat.js\";\nexport * from \"./models/entitySchemaPropertyType.js\";\nexport * from \"./models/IComparator.js\";\nexport * from \"./models/IComparatorGroup.js\";\nexport * from \"./models/IEntitySchema.js\";\nexport * from \"./models/IEntitySchemaOptions.js\";\nexport * from \"./models/IEntitySchemaProperty.js\";\nexport * from \"./models/IEntitySort.js\";\nexport * from \"./models/logicalOperator.js\";\nexport * from \"./models/sortDirection.js\";\nexport * from \"./utils/decoratorHelper.js\";\nexport * from \"./utils/entityConditions.js\";\nexport * from \"./utils/entitySchemaHelper.js\";\nexport * from \"./utils/entitySorter.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mCAAmC,CAAC;AAClD,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAClD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./decorators/entityDecorator.js\";\nexport * from \"./decorators/propertyDecorator.js\";\nexport * from \"./factories/entitySchemaFactory.js\";\nexport * from \"./models/comparisonOperator.js\";\nexport * from \"./models/entityCondition.js\";\nexport * from \"./models/entitySchemaPropertyFormat.js\";\nexport * from \"./models/entitySchemaPropertyType.js\";\nexport * from \"./models/IComparator.js\";\nexport * from \"./models/IComparatorGroup.js\";\nexport * from \"./models/IEntitySchema.js\";\nexport * from \"./models/IEntitySchemaOptions.js\";\nexport * from \"./models/IEntitySchemaProperty.js\";\nexport * from \"./models/IEntitySort.js\";\nexport * from \"./models/logicalOperator.js\";\nexport * from \"./models/sortDirection.js\";\nexport * from \"./utils/decoratorHelper.js\";\nexport * from \"./utils/entityConditions.js\";\nexport * from \"./utils/entitySchemaHelper.js\";\nexport * from \"./utils/entitySchemaDiff.js\";\nexport * from \"./utils/entitySorter.js\";\nexport * from \"./models/IEntitySchemaDiff.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IEntitySchemaDiff.js","sourceRoot":"","sources":["../../../src/models/IEntitySchemaDiff.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEntitySchemaProperty } from \"./IEntitySchemaProperty.js\";\n\n/**\n * The result of comparing two sets of entity schema properties.\n */\nexport interface IEntitySchemaDiff<T = unknown> {\n\t/**\n\t * Properties present in the new schema but absent from the old one.\n\t * Each entry is the full property descriptor from the new schema, so it can\n\t * be passed directly to bootstrap / table-creation logic.\n\t */\n\tadded: IEntitySchemaProperty<T>[];\n\n\t/**\n\t * Properties present in the old schema but absent from the new one.\n\t * Each entry is the full property descriptor from the old schema, allowing\n\t * connectors to drop the correct column, index, or field by name.\n\t */\n\tremoved: IEntitySchemaProperty<T>[];\n\n\t/**\n\t * Properties that exist in both schemas but differ in at least one structural\n\t * field (type, format, isSecondary, sortDirection, optional, itemType, itemTypeRef).\n\t * `from` is the old descriptor; `to` is the new one.\n\t * Both are full property objects so connectors can drop the old definition and\n\t * create the new one using the same bootstrap code path.\n\t */\n\tmodified: {\n\t\t/**\n\t\t * The old property descriptor.\n\t\t */\n\t\tfrom: IEntitySchemaProperty<T>;\n\t\t/**\n\t\t * The new property descriptor.\n\t\t */\n\t\tto: IEntitySchemaProperty<T>;\n\t}[];\n}\n"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compare two arrays of entity schema properties and return a structured diff.
|
|
3
|
+
*
|
|
4
|
+
* Properties are matched by their `property` key name. A property is considered
|
|
5
|
+
* modified when any structural field differs: `type`, `format`, `isPrimary`,
|
|
6
|
+
* `isSecondary`, `sortDirection`, `optional`, `itemType`, or `itemTypeRef`.
|
|
7
|
+
* Documentation-only fields (`description`, `examples`) are intentionally
|
|
8
|
+
* excluded from the comparison to avoid spurious diffs.
|
|
9
|
+
* @param oldProperties The property descriptors from the current (live) schema.
|
|
10
|
+
* @param newProperties The property descriptors from the target (new) schema.
|
|
11
|
+
* @returns A diff object with `added`, `removed`, and `modified` arrays, each
|
|
12
|
+
* containing full `IEntitySchemaProperty` descriptors.
|
|
13
|
+
*/
|
|
14
|
+
export function entitySchemaDiff(oldProperties, newProperties) {
|
|
15
|
+
const added = [];
|
|
16
|
+
const removed = [];
|
|
17
|
+
const modified = [];
|
|
18
|
+
const oldMap = new Map();
|
|
19
|
+
for (const prop of oldProperties) {
|
|
20
|
+
oldMap.set(prop.property, prop);
|
|
21
|
+
}
|
|
22
|
+
const newMap = new Map();
|
|
23
|
+
for (const prop of newProperties) {
|
|
24
|
+
newMap.set(prop.property, prop);
|
|
25
|
+
}
|
|
26
|
+
for (const newProp of newProperties) {
|
|
27
|
+
const oldProp = oldMap.get(newProp.property);
|
|
28
|
+
if (!oldProp) {
|
|
29
|
+
added.push(newProp);
|
|
30
|
+
}
|
|
31
|
+
else if (!schemaPropertiesEqual(oldProp, newProp)) {
|
|
32
|
+
modified.push({ from: oldProp, to: newProp });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const oldProp of oldProperties) {
|
|
36
|
+
if (!newMap.has(oldProp.property)) {
|
|
37
|
+
removed.push(oldProp);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { added, removed, modified };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Returns true when the diff contains no changes (nothing added, removed, or modified).
|
|
44
|
+
* @param diff The diff to check.
|
|
45
|
+
* @returns True if the diff is empty.
|
|
46
|
+
*/
|
|
47
|
+
export function isEmptyDiff(diff) {
|
|
48
|
+
return diff.added.length === 0 && diff.removed.length === 0 && diff.modified.length === 0;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Compare two property descriptors for structural equality.
|
|
52
|
+
* Documentation fields (description, examples) are excluded.
|
|
53
|
+
* @param a The first property descriptor.
|
|
54
|
+
* @param b The second property descriptor.
|
|
55
|
+
* @returns True if all structural fields are equal.
|
|
56
|
+
*/
|
|
57
|
+
function schemaPropertiesEqual(a, b) {
|
|
58
|
+
return (a.type === b.type &&
|
|
59
|
+
a.format === b.format &&
|
|
60
|
+
a.isPrimary === b.isPrimary &&
|
|
61
|
+
a.isSecondary === b.isSecondary &&
|
|
62
|
+
a.sortDirection === b.sortDirection &&
|
|
63
|
+
a.optional === b.optional &&
|
|
64
|
+
a.itemType === b.itemType &&
|
|
65
|
+
a.itemTypeRef === b.itemTypeRef);
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=entitySchemaDiff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitySchemaDiff.js","sourceRoot":"","sources":["../../../src/utils/entitySchemaDiff.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAC/B,aAAyC,EACzC,aAAyC;IAEzC,MAAM,KAAK,GAA+B,EAAE,CAAC;IAC7C,MAAM,OAAO,GAA+B,EAAE,CAAC;IAC/C,MAAM,QAAQ,GAAqC,EAAE,CAAC;IAEtD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoC,CAAC;IAC3D,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QAClC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAkB,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoC,CAAC;IAC3D,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QAClC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,QAAkB,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACrC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,QAAkB,CAAC,CAAC;QACvD,IAAI,CAAC,OAAO,EAAE,CAAC;YACd,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC;aAAM,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;YACrD,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;QAC/C,CAAC;IACF,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,aAAa,EAAE,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,QAAkB,CAAC,EAAE,CAAC;YAC7C,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;IACF,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAI,IAA0B;IACxD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;AAC3F,CAAC;AAED;;;;;;GAMG;AACH,SAAS,qBAAqB,CAC7B,CAA2B,EAC3B,CAA2B;IAE3B,OAAO,CACN,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI;QACjB,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QACrB,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS;QAC3B,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,WAAW;QAC/B,CAAC,CAAC,aAAa,KAAK,CAAC,CAAC,aAAa;QACnC,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ;QACzB,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,QAAQ;QACzB,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,WAAW,CAC/B,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEntitySchemaDiff } from \"../models/IEntitySchemaDiff.js\";\nimport type { IEntitySchemaProperty } from \"../models/IEntitySchemaProperty.js\";\n\n/**\n * Compare two arrays of entity schema properties and return a structured diff.\n *\n * Properties are matched by their `property` key name. A property is considered\n * modified when any structural field differs: `type`, `format`, `isPrimary`,\n * `isSecondary`, `sortDirection`, `optional`, `itemType`, or `itemTypeRef`.\n * Documentation-only fields (`description`, `examples`) are intentionally\n * excluded from the comparison to avoid spurious diffs.\n * @param oldProperties The property descriptors from the current (live) schema.\n * @param newProperties The property descriptors from the target (new) schema.\n * @returns A diff object with `added`, `removed`, and `modified` arrays, each\n * containing full `IEntitySchemaProperty` descriptors.\n */\nexport function entitySchemaDiff<T>(\n\toldProperties: IEntitySchemaProperty<T>[],\n\tnewProperties: IEntitySchemaProperty<T>[]\n): IEntitySchemaDiff<T> {\n\tconst added: IEntitySchemaProperty<T>[] = [];\n\tconst removed: IEntitySchemaProperty<T>[] = [];\n\tconst modified: IEntitySchemaDiff<T>[\"modified\"] = [];\n\n\tconst oldMap = new Map<string, IEntitySchemaProperty<T>>();\n\tfor (const prop of oldProperties) {\n\t\toldMap.set(prop.property as string, prop);\n\t}\n\n\tconst newMap = new Map<string, IEntitySchemaProperty<T>>();\n\tfor (const prop of newProperties) {\n\t\tnewMap.set(prop.property as string, prop);\n\t}\n\n\tfor (const newProp of newProperties) {\n\t\tconst oldProp = oldMap.get(newProp.property as string);\n\t\tif (!oldProp) {\n\t\t\tadded.push(newProp);\n\t\t} else if (!schemaPropertiesEqual(oldProp, newProp)) {\n\t\t\tmodified.push({ from: oldProp, to: newProp });\n\t\t}\n\t}\n\n\tfor (const oldProp of oldProperties) {\n\t\tif (!newMap.has(oldProp.property as string)) {\n\t\t\tremoved.push(oldProp);\n\t\t}\n\t}\n\n\treturn { added, removed, modified };\n}\n\n/**\n * Returns true when the diff contains no changes (nothing added, removed, or modified).\n * @param diff The diff to check.\n * @returns True if the diff is empty.\n */\nexport function isEmptyDiff<T>(diff: IEntitySchemaDiff<T>): boolean {\n\treturn diff.added.length === 0 && diff.removed.length === 0 && diff.modified.length === 0;\n}\n\n/**\n * Compare two property descriptors for structural equality.\n * Documentation fields (description, examples) are excluded.\n * @param a The first property descriptor.\n * @param b The second property descriptor.\n * @returns True if all structural fields are equal.\n */\nfunction schemaPropertiesEqual<T>(\n\ta: IEntitySchemaProperty<T>,\n\tb: IEntitySchemaProperty<T>\n): boolean {\n\treturn (\n\t\ta.type === b.type &&\n\t\ta.format === b.format &&\n\t\ta.isPrimary === b.isPrimary &&\n\t\ta.isSecondary === b.isSecondary &&\n\t\ta.sortDirection === b.sortDirection &&\n\t\ta.optional === b.optional &&\n\t\ta.itemType === b.itemType &&\n\t\ta.itemTypeRef === b.itemTypeRef\n\t);\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -16,4 +16,6 @@ export * from "./models/sortDirection.js";
|
|
|
16
16
|
export * from "./utils/decoratorHelper.js";
|
|
17
17
|
export * from "./utils/entityConditions.js";
|
|
18
18
|
export * from "./utils/entitySchemaHelper.js";
|
|
19
|
+
export * from "./utils/entitySchemaDiff.js";
|
|
19
20
|
export * from "./utils/entitySorter.js";
|
|
21
|
+
export * from "./models/IEntitySchemaDiff.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { IEntitySchemaProperty } from "./IEntitySchemaProperty.js";
|
|
2
|
+
/**
|
|
3
|
+
* The result of comparing two sets of entity schema properties.
|
|
4
|
+
*/
|
|
5
|
+
export interface IEntitySchemaDiff<T = unknown> {
|
|
6
|
+
/**
|
|
7
|
+
* Properties present in the new schema but absent from the old one.
|
|
8
|
+
* Each entry is the full property descriptor from the new schema, so it can
|
|
9
|
+
* be passed directly to bootstrap / table-creation logic.
|
|
10
|
+
*/
|
|
11
|
+
added: IEntitySchemaProperty<T>[];
|
|
12
|
+
/**
|
|
13
|
+
* Properties present in the old schema but absent from the new one.
|
|
14
|
+
* Each entry is the full property descriptor from the old schema, allowing
|
|
15
|
+
* connectors to drop the correct column, index, or field by name.
|
|
16
|
+
*/
|
|
17
|
+
removed: IEntitySchemaProperty<T>[];
|
|
18
|
+
/**
|
|
19
|
+
* Properties that exist in both schemas but differ in at least one structural
|
|
20
|
+
* field (type, format, isSecondary, sortDirection, optional, itemType, itemTypeRef).
|
|
21
|
+
* `from` is the old descriptor; `to` is the new one.
|
|
22
|
+
* Both are full property objects so connectors can drop the old definition and
|
|
23
|
+
* create the new one using the same bootstrap code path.
|
|
24
|
+
*/
|
|
25
|
+
modified: {
|
|
26
|
+
/**
|
|
27
|
+
* The old property descriptor.
|
|
28
|
+
*/
|
|
29
|
+
from: IEntitySchemaProperty<T>;
|
|
30
|
+
/**
|
|
31
|
+
* The new property descriptor.
|
|
32
|
+
*/
|
|
33
|
+
to: IEntitySchemaProperty<T>;
|
|
34
|
+
}[];
|
|
35
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IEntitySchemaDiff } from "../models/IEntitySchemaDiff.js";
|
|
2
|
+
import type { IEntitySchemaProperty } from "../models/IEntitySchemaProperty.js";
|
|
3
|
+
/**
|
|
4
|
+
* Compare two arrays of entity schema properties and return a structured diff.
|
|
5
|
+
*
|
|
6
|
+
* Properties are matched by their `property` key name. A property is considered
|
|
7
|
+
* modified when any structural field differs: `type`, `format`, `isPrimary`,
|
|
8
|
+
* `isSecondary`, `sortDirection`, `optional`, `itemType`, or `itemTypeRef`.
|
|
9
|
+
* Documentation-only fields (`description`, `examples`) are intentionally
|
|
10
|
+
* excluded from the comparison to avoid spurious diffs.
|
|
11
|
+
* @param oldProperties The property descriptors from the current (live) schema.
|
|
12
|
+
* @param newProperties The property descriptors from the target (new) schema.
|
|
13
|
+
* @returns A diff object with `added`, `removed`, and `modified` arrays, each
|
|
14
|
+
* containing full `IEntitySchemaProperty` descriptors.
|
|
15
|
+
*/
|
|
16
|
+
export declare function entitySchemaDiff<T>(oldProperties: IEntitySchemaProperty<T>[], newProperties: IEntitySchemaProperty<T>[]): IEntitySchemaDiff<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns true when the diff contains no changes (nothing added, removed, or modified).
|
|
19
|
+
* @param diff The diff to check.
|
|
20
|
+
* @returns True if the diff is empty.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isEmptyDiff<T>(diff: IEntitySchemaDiff<T>): boolean;
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.3-next.38](https://github.com/iotaledger/twin-framework/compare/entity-v0.0.3-next.37...entity-v0.0.3-next.38) (2026-05-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* typescript 6 update ([1d10f31](https://github.com/iotaledger/twin-framework/commit/1d10f31e6516ec622773f45e88af82fe749b384a))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/nameof bumped from 0.0.3-next.37 to 0.0.3-next.38
|
|
16
|
+
* @twin.org/core bumped from 0.0.3-next.37 to 0.0.3-next.38
|
|
17
|
+
* devDependencies
|
|
18
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.37 to 0.0.3-next.38
|
|
19
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.37 to 0.0.3-next.38
|
|
20
|
+
* @twin.org/validate-locales bumped from 0.0.3-next.37 to 0.0.3-next.38
|
|
21
|
+
|
|
22
|
+
## [0.0.3-next.37](https://github.com/iotaledger/twin-framework/compare/entity-v0.0.3-next.36...entity-v0.0.3-next.37) (2026-05-07)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* add IEntitySchemaDiff and entitySchemaDiff utility ([#282](https://github.com/iotaledger/twin-framework/issues/282)) ([9d63e94](https://github.com/iotaledger/twin-framework/commit/9d63e94021ee2ffc138004ee68cf53d08a6b17f9))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Dependencies
|
|
31
|
+
|
|
32
|
+
* The following workspace dependencies were updated
|
|
33
|
+
* dependencies
|
|
34
|
+
* @twin.org/nameof bumped from 0.0.3-next.36 to 0.0.3-next.37
|
|
35
|
+
* @twin.org/core bumped from 0.0.3-next.36 to 0.0.3-next.37
|
|
36
|
+
* devDependencies
|
|
37
|
+
* @twin.org/nameof-transformer bumped from 0.0.3-next.36 to 0.0.3-next.37
|
|
38
|
+
* @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.36 to 0.0.3-next.37
|
|
39
|
+
* @twin.org/validate-locales bumped from 0.0.3-next.36 to 0.0.3-next.37
|
|
40
|
+
|
|
3
41
|
## [0.0.3-next.36](https://github.com/iotaledger/twin-framework/compare/entity-v0.0.3-next.35...entity-v0.0.3-next.36) (2026-05-07)
|
|
4
42
|
|
|
5
43
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Function: entitySchemaDiff()
|
|
2
|
+
|
|
3
|
+
> **entitySchemaDiff**\<`T`\>(`oldProperties`, `newProperties`): [`IEntitySchemaDiff`](../interfaces/IEntitySchemaDiff.md)\<`T`\>
|
|
4
|
+
|
|
5
|
+
Compare two arrays of entity schema properties and return a structured diff.
|
|
6
|
+
|
|
7
|
+
Properties are matched by their `property` key name. A property is considered
|
|
8
|
+
modified when any structural field differs: `type`, `format`, `isPrimary`,
|
|
9
|
+
`isSecondary`, `sortDirection`, `optional`, `itemType`, or `itemTypeRef`.
|
|
10
|
+
Documentation-only fields (`description`, `examples`) are intentionally
|
|
11
|
+
excluded from the comparison to avoid spurious diffs.
|
|
12
|
+
|
|
13
|
+
## Type Parameters
|
|
14
|
+
|
|
15
|
+
### T
|
|
16
|
+
|
|
17
|
+
`T`
|
|
18
|
+
|
|
19
|
+
## Parameters
|
|
20
|
+
|
|
21
|
+
### oldProperties
|
|
22
|
+
|
|
23
|
+
[`IEntitySchemaProperty`](../interfaces/IEntitySchemaProperty.md)\<`T`\>[]
|
|
24
|
+
|
|
25
|
+
The property descriptors from the current (live) schema.
|
|
26
|
+
|
|
27
|
+
### newProperties
|
|
28
|
+
|
|
29
|
+
[`IEntitySchemaProperty`](../interfaces/IEntitySchemaProperty.md)\<`T`\>[]
|
|
30
|
+
|
|
31
|
+
The property descriptors from the target (new) schema.
|
|
32
|
+
|
|
33
|
+
## Returns
|
|
34
|
+
|
|
35
|
+
[`IEntitySchemaDiff`](../interfaces/IEntitySchemaDiff.md)\<`T`\>
|
|
36
|
+
|
|
37
|
+
A diff object with `added`, `removed`, and `modified` arrays, each
|
|
38
|
+
containing full `IEntitySchemaProperty` descriptors.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Function: isEmptyDiff()
|
|
2
|
+
|
|
3
|
+
> **isEmptyDiff**\<`T`\>(`diff`): `boolean`
|
|
4
|
+
|
|
5
|
+
Returns true when the diff contains no changes (nothing added, removed, or modified).
|
|
6
|
+
|
|
7
|
+
## Type Parameters
|
|
8
|
+
|
|
9
|
+
### T
|
|
10
|
+
|
|
11
|
+
`T`
|
|
12
|
+
|
|
13
|
+
## Parameters
|
|
14
|
+
|
|
15
|
+
### diff
|
|
16
|
+
|
|
17
|
+
[`IEntitySchemaDiff`](../interfaces/IEntitySchemaDiff.md)\<`T`\>
|
|
18
|
+
|
|
19
|
+
The diff to check.
|
|
20
|
+
|
|
21
|
+
## Returns
|
|
22
|
+
|
|
23
|
+
`boolean`
|
|
24
|
+
|
|
25
|
+
True if the diff is empty.
|
package/docs/reference/index.md
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
- [IComparator](interfaces/IComparator.md)
|
|
13
13
|
- [IComparatorGroup](interfaces/IComparatorGroup.md)
|
|
14
14
|
- [IEntitySchema](interfaces/IEntitySchema.md)
|
|
15
|
+
- [IEntitySchemaDiff](interfaces/IEntitySchemaDiff.md)
|
|
15
16
|
- [IEntitySchemaOptions](interfaces/IEntitySchemaOptions.md)
|
|
16
17
|
- [IEntitySchemaProperty](interfaces/IEntitySchemaProperty.md)
|
|
17
18
|
- [IEntitySort](interfaces/IEntitySort.md)
|
|
@@ -38,3 +39,5 @@
|
|
|
38
39
|
|
|
39
40
|
- [entity](functions/entity.md)
|
|
40
41
|
- [property](functions/property.md)
|
|
42
|
+
- [entitySchemaDiff](functions/entitySchemaDiff.md)
|
|
43
|
+
- [isEmptyDiff](functions/isEmptyDiff.md)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Interface: IEntitySchemaDiff\<T\>
|
|
2
|
+
|
|
3
|
+
The result of comparing two sets of entity schema properties.
|
|
4
|
+
|
|
5
|
+
## Type Parameters
|
|
6
|
+
|
|
7
|
+
### T
|
|
8
|
+
|
|
9
|
+
`T` = `unknown`
|
|
10
|
+
|
|
11
|
+
## Properties
|
|
12
|
+
|
|
13
|
+
### added {#added}
|
|
14
|
+
|
|
15
|
+
> **added**: [`IEntitySchemaProperty`](IEntitySchemaProperty.md)\<`T`\>[]
|
|
16
|
+
|
|
17
|
+
Properties present in the new schema but absent from the old one.
|
|
18
|
+
Each entry is the full property descriptor from the new schema, so it can
|
|
19
|
+
be passed directly to bootstrap / table-creation logic.
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### removed {#removed}
|
|
24
|
+
|
|
25
|
+
> **removed**: [`IEntitySchemaProperty`](IEntitySchemaProperty.md)\<`T`\>[]
|
|
26
|
+
|
|
27
|
+
Properties present in the old schema but absent from the new one.
|
|
28
|
+
Each entry is the full property descriptor from the old schema, allowing
|
|
29
|
+
connectors to drop the correct column, index, or field by name.
|
|
30
|
+
|
|
31
|
+
***
|
|
32
|
+
|
|
33
|
+
### modified {#modified}
|
|
34
|
+
|
|
35
|
+
> **modified**: `object`[]
|
|
36
|
+
|
|
37
|
+
Properties that exist in both schemas but differ in at least one structural
|
|
38
|
+
field (type, format, isSecondary, sortDirection, optional, itemType, itemTypeRef).
|
|
39
|
+
`from` is the old descriptor; `to` is the new one.
|
|
40
|
+
Both are full property objects so connectors can drop the old definition and
|
|
41
|
+
create the new one using the same bootstrap code path.
|
|
42
|
+
|
|
43
|
+
#### from
|
|
44
|
+
|
|
45
|
+
> **from**: [`IEntitySchemaProperty`](IEntitySchemaProperty.md)\<`T`\>
|
|
46
|
+
|
|
47
|
+
The old property descriptor.
|
|
48
|
+
|
|
49
|
+
#### to
|
|
50
|
+
|
|
51
|
+
> **to**: [`IEntitySchemaProperty`](IEntitySchemaProperty.md)\<`T`\>
|
|
52
|
+
|
|
53
|
+
The new property descriptor.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/entity",
|
|
3
|
-
"version": "0.0.3-next.
|
|
3
|
+
"version": "0.0.3-next.38",
|
|
4
4
|
"description": "Helpers for defining and working with entities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/core": "0.0.3-next.
|
|
18
|
-
"@twin.org/nameof": "0.0.3-next.
|
|
17
|
+
"@twin.org/core": "0.0.3-next.38",
|
|
18
|
+
"@twin.org/nameof": "0.0.3-next.38",
|
|
19
19
|
"reflect-metadata": "0.2.2",
|
|
20
20
|
"tslib": "2.8.1"
|
|
21
21
|
},
|