@baseplate-dev/plugin-auth 0.1.2 → 0.1.3
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/auth/core/common.d.ts +1 -0
- package/dist/auth/core/common.d.ts.map +1 -1
- package/dist/auth/core/common.js.map +1 -1
- package/dist/auth/core/schema/models.d.ts.map +1 -1
- package/dist/auth/core/schema/models.js +11 -0
- package/dist/auth/core/schema/models.js.map +1 -1
- package/dist/auth0/core/schema/models.d.ts.map +1 -1
- package/dist/auth0/core/schema/models.js +6 -0
- package/dist/auth0/core/schema/models.js.map +1 -1
- package/dist/web/assets/{__federation_expose_auth0CoreCommon--n6esVYP.js → __federation_expose_auth0CoreCommon-DCwCR5dZ.js} +3 -3
- package/dist/web/assets/{__federation_expose_auth0CoreCommon--n6esVYP.js.map → __federation_expose_auth0CoreCommon-DCwCR5dZ.js.map} +1 -1
- package/dist/web/assets/{__federation_expose_auth0CoreWeb-Ql6gpX5q.js → __federation_expose_auth0CoreWeb-BlCwYpTq.js} +11 -5
- package/dist/web/assets/__federation_expose_auth0CoreWeb-BlCwYpTq.js.map +1 -0
- package/dist/web/assets/{__federation_fn_import-BiwmVFwy.js → __federation_fn_import-dzKjrTzS.js} +2 -2
- package/dist/web/assets/{__federation_fn_import-BiwmVFwy.js.map → __federation_fn_import-dzKjrTzS.js.map} +1 -1
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/{web-CY8oz43s.js → web-BXHJHUXP.js} +18 -7
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/web-BXHJHUXP.js.map +1 -0
- package/dist/web/assets/__federation_shared_@baseplate-dev/{project-builder-lib-B62IPizQ.js → project-builder-lib-GtzVuDsM.js} +17 -675
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib-GtzVuDsM.js.map +1 -0
- package/dist/web/assets/__federation_shared_@baseplate-dev/{ui-components-BU2QTWNs.js → ui-components-ChoqtPkg.js} +11 -6
- package/dist/web/assets/__federation_shared_@baseplate-dev/ui-components-ChoqtPkg.js.map +1 -0
- package/dist/web/assets/{index-CgJx-krK.js → index-BxDOOHD-.js} +2 -2
- package/dist/web/assets/{index-CgJx-krK.js.map → index-BxDOOHD-.js.map} +1 -1
- package/dist/web/assets/{index.esm-BcxPd7Ha.js → index.esm-BZEyAv4m.js} +2 -2
- package/dist/web/assets/{index.esm-BcxPd7Ha.js.map → index.esm-BZEyAv4m.js.map} +1 -1
- package/dist/web/assets/{model-utils-CbQJy1wE.js → model-merger-CdV-7CWE.js} +780 -4
- package/dist/web/assets/model-merger-CdV-7CWE.js.map +1 -0
- package/dist/web/assets/{plugin-definition-BQRupXoQ.js → plugin-definition-C9Q-BrBQ.js} +2 -2
- package/dist/web/assets/{plugin-definition-BQRupXoQ.js.map → plugin-definition-C9Q-BrBQ.js.map} +1 -1
- package/dist/web/assets/{react-2jQE8aG0.js → react-BfiX28GO.js} +2 -2
- package/dist/web/assets/{react-2jQE8aG0.js.map → react-BfiX28GO.js.map} +1 -1
- package/dist/web/assets/remoteEntry.js +2 -2
- package/package.json +15 -13
- package/dist/web/assets/__federation_expose_auth0CoreWeb-Ql6gpX5q.js.map +0 -1
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib/web-CY8oz43s.js.map +0 -1
- package/dist/web/assets/__federation_shared_@baseplate-dev/project-builder-lib-B62IPizQ.js.map +0 -1
- package/dist/web/assets/__federation_shared_@baseplate-dev/ui-components-BU2QTWNs.js.map +0 -1
- package/dist/web/assets/model-utils-CbQJy1wE.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { importShared } from './__federation_fn_import-
|
|
1
|
+
import { importShared } from './__federation_fn_import-dzKjrTzS.js';
|
|
2
2
|
|
|
3
3
|
function createInitializedPluginSpec(spec, implementation) {
|
|
4
4
|
return { spec, implementation };
|
|
@@ -19,10 +19,135 @@ function createPluginSpec(name, options) {
|
|
|
19
19
|
|
|
20
20
|
function noop() { }
|
|
21
21
|
|
|
22
|
+
function isPrimitive(value) {
|
|
23
|
+
return value == null || (typeof value !== 'object' && typeof value !== 'function');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isTypedArray(x) {
|
|
27
|
+
return ArrayBuffer.isView(x) && !(x instanceof DataView);
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
function getSymbols(object) {
|
|
23
31
|
return Object.getOwnPropertySymbols(object).filter(symbol => Object.prototype.propertyIsEnumerable.call(object, symbol));
|
|
24
32
|
}
|
|
25
33
|
|
|
34
|
+
function cloneDeepWithImpl(valueToClone, keyToClone, objectToClone, stack = new Map(), cloneValue = undefined) {
|
|
35
|
+
const cloned = cloneValue?.(valueToClone, keyToClone, objectToClone, stack);
|
|
36
|
+
if (cloned != null) {
|
|
37
|
+
return cloned;
|
|
38
|
+
}
|
|
39
|
+
if (isPrimitive(valueToClone)) {
|
|
40
|
+
return valueToClone;
|
|
41
|
+
}
|
|
42
|
+
if (stack.has(valueToClone)) {
|
|
43
|
+
return stack.get(valueToClone);
|
|
44
|
+
}
|
|
45
|
+
if (Array.isArray(valueToClone)) {
|
|
46
|
+
const result = new Array(valueToClone.length);
|
|
47
|
+
stack.set(valueToClone, result);
|
|
48
|
+
for (let i = 0; i < valueToClone.length; i++) {
|
|
49
|
+
result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
|
|
50
|
+
}
|
|
51
|
+
if (Object.hasOwn(valueToClone, 'index')) {
|
|
52
|
+
result.index = valueToClone.index;
|
|
53
|
+
}
|
|
54
|
+
if (Object.hasOwn(valueToClone, 'input')) {
|
|
55
|
+
result.input = valueToClone.input;
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
if (valueToClone instanceof Date) {
|
|
60
|
+
return new Date(valueToClone.getTime());
|
|
61
|
+
}
|
|
62
|
+
if (valueToClone instanceof RegExp) {
|
|
63
|
+
const result = new RegExp(valueToClone.source, valueToClone.flags);
|
|
64
|
+
result.lastIndex = valueToClone.lastIndex;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
if (valueToClone instanceof Map) {
|
|
68
|
+
const result = new Map();
|
|
69
|
+
stack.set(valueToClone, result);
|
|
70
|
+
for (const [key, value] of valueToClone) {
|
|
71
|
+
result.set(key, cloneDeepWithImpl(value, key, objectToClone, stack, cloneValue));
|
|
72
|
+
}
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
if (valueToClone instanceof Set) {
|
|
76
|
+
const result = new Set();
|
|
77
|
+
stack.set(valueToClone, result);
|
|
78
|
+
for (const value of valueToClone) {
|
|
79
|
+
result.add(cloneDeepWithImpl(value, undefined, objectToClone, stack, cloneValue));
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(valueToClone)) {
|
|
84
|
+
return valueToClone.subarray();
|
|
85
|
+
}
|
|
86
|
+
if (isTypedArray(valueToClone)) {
|
|
87
|
+
const result = new (Object.getPrototypeOf(valueToClone).constructor)(valueToClone.length);
|
|
88
|
+
stack.set(valueToClone, result);
|
|
89
|
+
for (let i = 0; i < valueToClone.length; i++) {
|
|
90
|
+
result[i] = cloneDeepWithImpl(valueToClone[i], i, objectToClone, stack, cloneValue);
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
if (valueToClone instanceof ArrayBuffer ||
|
|
95
|
+
(typeof SharedArrayBuffer !== 'undefined' && valueToClone instanceof SharedArrayBuffer)) {
|
|
96
|
+
return valueToClone.slice(0);
|
|
97
|
+
}
|
|
98
|
+
if (valueToClone instanceof DataView) {
|
|
99
|
+
const result = new DataView(valueToClone.buffer.slice(0), valueToClone.byteOffset, valueToClone.byteLength);
|
|
100
|
+
stack.set(valueToClone, result);
|
|
101
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
if (typeof File !== 'undefined' && valueToClone instanceof File) {
|
|
105
|
+
const result = new File([valueToClone], valueToClone.name, {
|
|
106
|
+
type: valueToClone.type,
|
|
107
|
+
});
|
|
108
|
+
stack.set(valueToClone, result);
|
|
109
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
if (valueToClone instanceof Blob) {
|
|
113
|
+
const result = new Blob([valueToClone], { type: valueToClone.type });
|
|
114
|
+
stack.set(valueToClone, result);
|
|
115
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
if (valueToClone instanceof Error) {
|
|
119
|
+
const result = new valueToClone.constructor();
|
|
120
|
+
stack.set(valueToClone, result);
|
|
121
|
+
result.message = valueToClone.message;
|
|
122
|
+
result.name = valueToClone.name;
|
|
123
|
+
result.stack = valueToClone.stack;
|
|
124
|
+
result.cause = valueToClone.cause;
|
|
125
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
if (typeof valueToClone === 'object' && valueToClone !== null) {
|
|
129
|
+
const result = Object.create(Object.getPrototypeOf(valueToClone));
|
|
130
|
+
stack.set(valueToClone, result);
|
|
131
|
+
copyProperties(result, valueToClone, objectToClone, stack, cloneValue);
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
return valueToClone;
|
|
135
|
+
}
|
|
136
|
+
function copyProperties(target, source, objectToClone = target, stack, cloneValue) {
|
|
137
|
+
const keys = [...Object.keys(source), ...getSymbols(source)];
|
|
138
|
+
for (let i = 0; i < keys.length; i++) {
|
|
139
|
+
const key = keys[i];
|
|
140
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
141
|
+
if (descriptor == null || descriptor.writable) {
|
|
142
|
+
target[key] = cloneDeepWithImpl(source[key], key, objectToClone, stack, cloneValue);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function cloneDeep(obj) {
|
|
148
|
+
return cloneDeepWithImpl(obj, undefined, obj, new Map(), undefined);
|
|
149
|
+
}
|
|
150
|
+
|
|
26
151
|
function isPlainObject(value) {
|
|
27
152
|
if (!value || typeof value !== 'object') {
|
|
28
153
|
return false;
|
|
@@ -37,6 +162,59 @@ function isPlainObject(value) {
|
|
|
37
162
|
return Object.prototype.toString.call(value) === '[object Object]';
|
|
38
163
|
}
|
|
39
164
|
|
|
165
|
+
function mapValues(object, getNewValue) {
|
|
166
|
+
const result = {};
|
|
167
|
+
const keys = Object.keys(object);
|
|
168
|
+
for (let i = 0; i < keys.length; i++) {
|
|
169
|
+
const key = keys[i];
|
|
170
|
+
const value = object[key];
|
|
171
|
+
result[key] = getNewValue(value, key, object);
|
|
172
|
+
}
|
|
173
|
+
return result;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function merge(target, source) {
|
|
177
|
+
const sourceKeys = Object.keys(source);
|
|
178
|
+
for (let i = 0; i < sourceKeys.length; i++) {
|
|
179
|
+
const key = sourceKeys[i];
|
|
180
|
+
const sourceValue = source[key];
|
|
181
|
+
const targetValue = target[key];
|
|
182
|
+
if (Array.isArray(sourceValue)) {
|
|
183
|
+
if (Array.isArray(targetValue)) {
|
|
184
|
+
target[key] = merge(targetValue, sourceValue);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
target[key] = merge([], sourceValue);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else if (isPlainObject(sourceValue)) {
|
|
191
|
+
if (isPlainObject(targetValue)) {
|
|
192
|
+
target[key] = merge(targetValue, sourceValue);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
target[key] = merge({}, sourceValue);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (targetValue === undefined || sourceValue !== undefined) {
|
|
199
|
+
target[key] = sourceValue;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return target;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function omit(obj, keys) {
|
|
206
|
+
const result = { ...obj };
|
|
207
|
+
for (let i = 0; i < keys.length; i++) {
|
|
208
|
+
const key = keys[i];
|
|
209
|
+
delete result[key];
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function toMerged(target, source) {
|
|
215
|
+
return merge(cloneDeep(target), source);
|
|
216
|
+
}
|
|
217
|
+
|
|
40
218
|
function getTag(value) {
|
|
41
219
|
if (value == null) {
|
|
42
220
|
return value === undefined ? '[object Undefined]' : '[object Null]';
|
|
@@ -577,6 +755,107 @@ function getWithPath(object, path, defaultValue) {
|
|
|
577
755
|
return current;
|
|
578
756
|
}
|
|
579
757
|
|
|
758
|
+
function isObject(value) {
|
|
759
|
+
return value !== null && (typeof value === 'object' || typeof value === 'function');
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
function isMatch(target, source) {
|
|
763
|
+
if (source === target) {
|
|
764
|
+
return true;
|
|
765
|
+
}
|
|
766
|
+
switch (typeof source) {
|
|
767
|
+
case 'object': {
|
|
768
|
+
if (source == null) {
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
771
|
+
const keys = Object.keys(source);
|
|
772
|
+
if (target == null) {
|
|
773
|
+
return keys.length === 0;
|
|
774
|
+
}
|
|
775
|
+
if (Array.isArray(source)) {
|
|
776
|
+
return isArrayMatch(target, source);
|
|
777
|
+
}
|
|
778
|
+
if (source instanceof Map) {
|
|
779
|
+
return isMapMatch(target, source);
|
|
780
|
+
}
|
|
781
|
+
if (source instanceof Set) {
|
|
782
|
+
return isSetMatch(target, source);
|
|
783
|
+
}
|
|
784
|
+
for (let i = 0; i < keys.length; i++) {
|
|
785
|
+
const key = keys[i];
|
|
786
|
+
if (!isPrimitive(target) && !(key in target)) {
|
|
787
|
+
return false;
|
|
788
|
+
}
|
|
789
|
+
if (source[key] === undefined && target[key] !== undefined) {
|
|
790
|
+
return false;
|
|
791
|
+
}
|
|
792
|
+
if (source[key] === null && target[key] !== null) {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
if (!isMatch(target[key], source[key])) {
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
return true;
|
|
800
|
+
}
|
|
801
|
+
case 'function': {
|
|
802
|
+
if (Object.keys(source).length > 0) {
|
|
803
|
+
return isMatch(target, { ...source });
|
|
804
|
+
}
|
|
805
|
+
return false;
|
|
806
|
+
}
|
|
807
|
+
default: {
|
|
808
|
+
if (!isObject(target)) {
|
|
809
|
+
return eq(target, source);
|
|
810
|
+
}
|
|
811
|
+
return !source;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
function isMapMatch(target, source) {
|
|
816
|
+
if (source.size === 0) {
|
|
817
|
+
return true;
|
|
818
|
+
}
|
|
819
|
+
if (!(target instanceof Map)) {
|
|
820
|
+
return false;
|
|
821
|
+
}
|
|
822
|
+
for (const [key, value] of source.entries()) {
|
|
823
|
+
if (!isMatch(target.get(key), value)) {
|
|
824
|
+
return false;
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return true;
|
|
828
|
+
}
|
|
829
|
+
function isArrayMatch(target, source) {
|
|
830
|
+
if (source.length === 0) {
|
|
831
|
+
return true;
|
|
832
|
+
}
|
|
833
|
+
if (!Array.isArray(target)) {
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
836
|
+
const countedIndex = new Set();
|
|
837
|
+
for (let i = 0; i < source.length; i++) {
|
|
838
|
+
const sourceItem = source[i];
|
|
839
|
+
const index = target.findIndex((targetItem, index) => {
|
|
840
|
+
return isMatch(targetItem, sourceItem) && !countedIndex.has(index);
|
|
841
|
+
});
|
|
842
|
+
if (index === -1) {
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
countedIndex.add(index);
|
|
846
|
+
}
|
|
847
|
+
return true;
|
|
848
|
+
}
|
|
849
|
+
function isSetMatch(target, source) {
|
|
850
|
+
if (source.size === 0) {
|
|
851
|
+
return true;
|
|
852
|
+
}
|
|
853
|
+
if (!(target instanceof Set)) {
|
|
854
|
+
return false;
|
|
855
|
+
}
|
|
856
|
+
return isArrayMatch([...target], [...source]);
|
|
857
|
+
}
|
|
858
|
+
|
|
580
859
|
const IS_UNSIGNED_INTEGER = /^(?:0|[1-9]\d*)$/;
|
|
581
860
|
function isIndex(value, length = Number.MAX_SAFE_INTEGER) {
|
|
582
861
|
switch (typeof value) {
|
|
@@ -804,7 +1083,7 @@ class ZodRefBuilder {
|
|
|
804
1083
|
const idPath = entity.idPath
|
|
805
1084
|
? this._constructPathWithoutPrefix(entity.idPath)
|
|
806
1085
|
: [...this._constructPathWithoutPrefix(entity.path), 'id'];
|
|
807
|
-
// TODO [>=0.
|
|
1086
|
+
// TODO [>=0.2.0] Remove the fallback to generateNewId once we've released a new major verison.
|
|
808
1087
|
const id = get(this.data, idPath) ??
|
|
809
1088
|
entity.type.generateNewId();
|
|
810
1089
|
if (!get(this.data, idPath)) {
|
|
@@ -1121,6 +1400,19 @@ const featureSchema = zEnt(z.object({
|
|
|
1121
1400
|
}), { type: featureEntityType });
|
|
1122
1401
|
const featuresSchema = z.array(featureSchema).default([]);
|
|
1123
1402
|
|
|
1403
|
+
const modelEntityType = createEntityType('model');
|
|
1404
|
+
const modelScalarFieldEntityType = createEntityType('model-scalar-field', {
|
|
1405
|
+
parentType: modelEntityType,
|
|
1406
|
+
});
|
|
1407
|
+
const modelLocalRelationEntityType = createEntityType('model-local-relation', { parentType: modelEntityType });
|
|
1408
|
+
const modelForeignRelationEntityType = createEntityType('model-foreign-relation', { parentType: modelEntityType });
|
|
1409
|
+
const modelUniqueConstraintEntityType = createEntityType('model-unique-constraint', { parentType: modelEntityType });
|
|
1410
|
+
const modelTransformerEntityType = createEntityType('model-transformer', { parentType: modelEntityType });
|
|
1411
|
+
const modelEnumEntityType = createEntityType('model-enum');
|
|
1412
|
+
const modelEnumValueEntityType = createEntityType('model-enum-value', {
|
|
1413
|
+
parentType: modelEnumEntityType,
|
|
1414
|
+
});
|
|
1415
|
+
|
|
1124
1416
|
function getRootFeatures(projectDefinition) {
|
|
1125
1417
|
return projectDefinition.features.filter((f) => !f.parentRef);
|
|
1126
1418
|
}
|
|
@@ -1259,5 +1551,489 @@ const ModelUtils = {
|
|
|
1259
1551
|
getModelIdByNameOrDefault,
|
|
1260
1552
|
};
|
|
1261
1553
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1554
|
+
/**
|
|
1555
|
+
* Allows diffing of arbitrary JSON objects.
|
|
1556
|
+
*/
|
|
1557
|
+
class DefinitionDiffField {
|
|
1558
|
+
constructor(
|
|
1559
|
+
/**
|
|
1560
|
+
* The name of the field to be presented to the user.
|
|
1561
|
+
*/
|
|
1562
|
+
name) {
|
|
1563
|
+
Object.defineProperty(this, "name", {
|
|
1564
|
+
enumerable: true,
|
|
1565
|
+
configurable: true,
|
|
1566
|
+
writable: true,
|
|
1567
|
+
value: name
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* A field that is an array of objects with a unique key.
|
|
1573
|
+
*/
|
|
1574
|
+
class DefinitionDiffKeyedArrayField extends DefinitionDiffField {
|
|
1575
|
+
constructor(name, getKey, options = {}) {
|
|
1576
|
+
super(name);
|
|
1577
|
+
Object.defineProperty(this, "getKey", {
|
|
1578
|
+
enumerable: true,
|
|
1579
|
+
configurable: true,
|
|
1580
|
+
writable: true,
|
|
1581
|
+
value: getKey
|
|
1582
|
+
});
|
|
1583
|
+
Object.defineProperty(this, "options", {
|
|
1584
|
+
enumerable: true,
|
|
1585
|
+
configurable: true,
|
|
1586
|
+
writable: true,
|
|
1587
|
+
value: options
|
|
1588
|
+
});
|
|
1589
|
+
this.getKey = getKey;
|
|
1590
|
+
}
|
|
1591
|
+
diff(current, desired) {
|
|
1592
|
+
const currentValue = current ?? [];
|
|
1593
|
+
const desiredValue = desired ?? [];
|
|
1594
|
+
if (!Array.isArray(currentValue) || !Array.isArray(desiredValue)) {
|
|
1595
|
+
throw new TypeError('Current and desired must be arrays');
|
|
1596
|
+
}
|
|
1597
|
+
const ops = [];
|
|
1598
|
+
const { allowRemove, ignoreFields = ['id'] } = this.options;
|
|
1599
|
+
const currentByKey = new Map(currentValue.map((item) => [this.getKey(item), item]));
|
|
1600
|
+
const desiredByKey = new Map(desiredValue.map((item) => [this.getKey(item), item]));
|
|
1601
|
+
for (const [key, desiredItem] of desiredByKey) {
|
|
1602
|
+
const currentItem = currentByKey.get(key);
|
|
1603
|
+
if (!currentItem) {
|
|
1604
|
+
ops.push({ type: 'add', key, item: desiredItem });
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1607
|
+
if (!isMatch(omit(currentItem, ignoreFields), omit(desiredItem, ignoreFields))) {
|
|
1608
|
+
ops.push({ type: 'update', key, item: desiredItem });
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
if (allowRemove) {
|
|
1612
|
+
for (const [key, currentItem] of currentByKey) {
|
|
1613
|
+
if (!desiredByKey.has(key)) {
|
|
1614
|
+
ops.push({ type: 'remove', key, item: currentItem });
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
return ops;
|
|
1619
|
+
}
|
|
1620
|
+
apply(current, diff) {
|
|
1621
|
+
const patch = diff;
|
|
1622
|
+
const currentValue = current ?? [];
|
|
1623
|
+
if (!Array.isArray(currentValue)) {
|
|
1624
|
+
throw new TypeError('Current must be array');
|
|
1625
|
+
}
|
|
1626
|
+
const items = [...currentValue];
|
|
1627
|
+
for (const { type, key, item } of patch) {
|
|
1628
|
+
const index = items.findIndex((i) => this.getKey(i) === key);
|
|
1629
|
+
switch (type) {
|
|
1630
|
+
case 'add': {
|
|
1631
|
+
items.push(item);
|
|
1632
|
+
break;
|
|
1633
|
+
}
|
|
1634
|
+
case 'update': {
|
|
1635
|
+
if (index === -1) {
|
|
1636
|
+
throw new Error(`Cannot apply patch. Item with key "${key}" not found.`);
|
|
1637
|
+
}
|
|
1638
|
+
// Preserve existing id if present.
|
|
1639
|
+
items[index] = toMerged(items[index], item);
|
|
1640
|
+
break;
|
|
1641
|
+
}
|
|
1642
|
+
case 'remove': {
|
|
1643
|
+
if (index !== -1) {
|
|
1644
|
+
items.splice(index, 1);
|
|
1645
|
+
}
|
|
1646
|
+
break;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
return items;
|
|
1651
|
+
}
|
|
1652
|
+
getActionVerb(isNew) {
|
|
1653
|
+
return isNew ? 'created' : 'added or updated';
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
/**
|
|
1657
|
+
* A field that is a replacement for the entire object or array.
|
|
1658
|
+
*/
|
|
1659
|
+
class DefinitionDiffReplacementField extends DefinitionDiffField {
|
|
1660
|
+
diff(current, desired) {
|
|
1661
|
+
if (desired === undefined) {
|
|
1662
|
+
return [];
|
|
1663
|
+
}
|
|
1664
|
+
if (!isMatch(current, desired)) {
|
|
1665
|
+
return [{ type: 'update', key: '*', item: desired }];
|
|
1666
|
+
}
|
|
1667
|
+
return [];
|
|
1668
|
+
}
|
|
1669
|
+
apply(current, diff) {
|
|
1670
|
+
if (diff.length === 0)
|
|
1671
|
+
return current;
|
|
1672
|
+
return diff[0].item;
|
|
1673
|
+
}
|
|
1674
|
+
getActionVerb(isNew) {
|
|
1675
|
+
return isNew ? 'set' : 'replaced';
|
|
1676
|
+
}
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* A field that ensures an array contains certain values.
|
|
1680
|
+
* This field type only adds items, never removes them.
|
|
1681
|
+
*/
|
|
1682
|
+
class DefinitionDiffArrayIncludesField extends DefinitionDiffField {
|
|
1683
|
+
constructor(name, getKey) {
|
|
1684
|
+
super(name);
|
|
1685
|
+
Object.defineProperty(this, "getKey", {
|
|
1686
|
+
enumerable: true,
|
|
1687
|
+
configurable: true,
|
|
1688
|
+
writable: true,
|
|
1689
|
+
value: getKey
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
diff(current, desired) {
|
|
1693
|
+
const currentValue = current ?? [];
|
|
1694
|
+
const desiredValue = desired ?? [];
|
|
1695
|
+
if (!Array.isArray(currentValue) || !Array.isArray(desiredValue)) {
|
|
1696
|
+
throw new TypeError('Current and desired must be arrays');
|
|
1697
|
+
}
|
|
1698
|
+
const ops = [];
|
|
1699
|
+
const currentSet = new Set(this.getKey ? currentValue.map(this.getKey) : currentValue);
|
|
1700
|
+
for (const item of desiredValue) {
|
|
1701
|
+
const key = this.getKey ? this.getKey(item) : String(item);
|
|
1702
|
+
if (!currentSet.has(key)) {
|
|
1703
|
+
ops.push({ type: 'add', key, item });
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
return ops;
|
|
1707
|
+
}
|
|
1708
|
+
apply(current, diff) {
|
|
1709
|
+
const currentValue = (current ?? []);
|
|
1710
|
+
if (!Array.isArray(currentValue)) {
|
|
1711
|
+
throw new TypeError('Current must be array');
|
|
1712
|
+
}
|
|
1713
|
+
const items = [...currentValue];
|
|
1714
|
+
for (const { type, item } of diff) {
|
|
1715
|
+
if (type === 'add') {
|
|
1716
|
+
items.push(item);
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
return items;
|
|
1720
|
+
}
|
|
1721
|
+
getActionVerb(isNew) {
|
|
1722
|
+
return isNew ? 'created' : 'added';
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
function createDefinitionDiffConfig(config) {
|
|
1726
|
+
return config;
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Creates a diff between two objects.
|
|
1730
|
+
*/
|
|
1731
|
+
function createDefinitionDiff(current, desired, configuration) {
|
|
1732
|
+
const ops = mapValues(configuration, (field, key) => {
|
|
1733
|
+
if (!field)
|
|
1734
|
+
return [];
|
|
1735
|
+
return field.diff(get(current, key), get(desired, key));
|
|
1736
|
+
});
|
|
1737
|
+
if (Object.values(ops).every((ops) => ops.length === 0)) {
|
|
1738
|
+
return undefined;
|
|
1739
|
+
}
|
|
1740
|
+
return ops;
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Applies a diff to an object.
|
|
1744
|
+
*/
|
|
1745
|
+
function applyDefinitionDiff(current, diff, configuration) {
|
|
1746
|
+
const clonedCurrent = cloneDeep(current);
|
|
1747
|
+
for (const [key, ops] of Object.entries(diff)) {
|
|
1748
|
+
if (!ops)
|
|
1749
|
+
continue;
|
|
1750
|
+
const field = configuration[key];
|
|
1751
|
+
const currentValue = get(clonedCurrent, key);
|
|
1752
|
+
set(clonedCurrent, key, field.apply(currentValue, ops));
|
|
1753
|
+
}
|
|
1754
|
+
return clonedCurrent;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
/**
|
|
1758
|
+
* Computes a unique key for a unique constraint by sorting its field refs.
|
|
1759
|
+
*
|
|
1760
|
+
* @param constraint - Unique constraint input.
|
|
1761
|
+
* @returns A key string.
|
|
1762
|
+
*/
|
|
1763
|
+
function getUniqueConstraintKey(constraint) {
|
|
1764
|
+
const fields = constraint.fields.map((f) => f.fieldRef).sort();
|
|
1765
|
+
return fields.join('|');
|
|
1766
|
+
}
|
|
1767
|
+
const modelMergerDefinitionDiffConfig = createDefinitionDiffConfig({
|
|
1768
|
+
'model.fields': new DefinitionDiffKeyedArrayField('fields', (f) => f.name),
|
|
1769
|
+
'model.relations': new DefinitionDiffKeyedArrayField('relations', (r) => r.name),
|
|
1770
|
+
'model.uniqueConstraints': new DefinitionDiffKeyedArrayField('unique constraints', (c) => getUniqueConstraintKey(c)),
|
|
1771
|
+
'model.primaryKeyFieldRefs': new DefinitionDiffReplacementField('primary key fields'),
|
|
1772
|
+
'graphql.objectType.enabled': new DefinitionDiffReplacementField('GraphQL object type enabled'),
|
|
1773
|
+
'graphql.objectType.fields': new DefinitionDiffArrayIncludesField('GraphQL object type fields'),
|
|
1774
|
+
'graphql.objectType.localRelations': new DefinitionDiffArrayIncludesField('GraphQL object type local relations'),
|
|
1775
|
+
'graphql.objectType.foreignRelations': new DefinitionDiffArrayIncludesField('GraphQL object type foreign relations'),
|
|
1776
|
+
});
|
|
1777
|
+
/**
|
|
1778
|
+
* Serializes a model merger model input such that all IDs are replaced with
|
|
1779
|
+
* names.
|
|
1780
|
+
*
|
|
1781
|
+
* @param input - The model merger model input.
|
|
1782
|
+
* @param definitionContainer - The definition container.
|
|
1783
|
+
* @returns The serialized model merger model input.
|
|
1784
|
+
*/
|
|
1785
|
+
function serializeModelMergerModelInput(input, definitionContainer, siblingModels) {
|
|
1786
|
+
const siblingModelFieldIdMap = new Map([
|
|
1787
|
+
...input.model.fields.map((f) => [f.id, f.name]),
|
|
1788
|
+
...siblingModels.flatMap((m) => m.model.fields.map((f) => [f.id, f.name])),
|
|
1789
|
+
]);
|
|
1790
|
+
const siblingModelRelationIdMap = new Map([
|
|
1791
|
+
...(input.model.relations ?? []).map((r) => [r.id, r.name]),
|
|
1792
|
+
...siblingModels.flatMap((m) => (m.model.relations ?? []).map((r) => [r.id, r.name])),
|
|
1793
|
+
...(input.model.relations ?? []).map((r) => [r.foreignId, r.foreignRelationName]),
|
|
1794
|
+
...siblingModels.flatMap((m) => (m.model.relations ?? []).map((r) => [r.foreignId, r.foreignRelationName])),
|
|
1795
|
+
]);
|
|
1796
|
+
const fieldNameFromId = (id) => siblingModelFieldIdMap.get(id) ?? definitionContainer.nameFromId(id);
|
|
1797
|
+
const relationNameFromId = (id) => siblingModelRelationIdMap.get(id) ?? definitionContainer.nameFromId(id);
|
|
1798
|
+
return {
|
|
1799
|
+
...input,
|
|
1800
|
+
model: {
|
|
1801
|
+
...input.model,
|
|
1802
|
+
relations: input.model.relations?.map((r) => ({
|
|
1803
|
+
...r,
|
|
1804
|
+
references: r.references.map((reference) => ({
|
|
1805
|
+
...reference,
|
|
1806
|
+
localRef: fieldNameFromId(reference.localRef),
|
|
1807
|
+
foreignRef: fieldNameFromId(reference.foreignRef),
|
|
1808
|
+
})),
|
|
1809
|
+
})),
|
|
1810
|
+
uniqueConstraints: input.model.uniqueConstraints?.map((c) => ({
|
|
1811
|
+
...c,
|
|
1812
|
+
fields: c.fields.map((f) => ({
|
|
1813
|
+
...f,
|
|
1814
|
+
fieldRef: fieldNameFromId(f.fieldRef),
|
|
1815
|
+
})),
|
|
1816
|
+
})),
|
|
1817
|
+
primaryKeyFieldRefs: input.model.primaryKeyFieldRefs.map(fieldNameFromId),
|
|
1818
|
+
},
|
|
1819
|
+
graphql: {
|
|
1820
|
+
...input.graphql,
|
|
1821
|
+
objectType: {
|
|
1822
|
+
...input.graphql?.objectType,
|
|
1823
|
+
fields: input.graphql?.objectType?.fields.map(fieldNameFromId) ?? [],
|
|
1824
|
+
localRelations: input.graphql?.objectType?.localRelations?.map(relationNameFromId),
|
|
1825
|
+
foreignRelations: input.graphql?.objectType?.foreignRelations?.map(relationNameFromId),
|
|
1826
|
+
},
|
|
1827
|
+
},
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Attaches IDs to the model merger model input.
|
|
1832
|
+
*
|
|
1833
|
+
* @param input - The model merger model input.
|
|
1834
|
+
* @returns The model merger model input with IDs attached.
|
|
1835
|
+
*/
|
|
1836
|
+
function attachIdsToModelMergerModelInput(input) {
|
|
1837
|
+
return {
|
|
1838
|
+
...input,
|
|
1839
|
+
model: {
|
|
1840
|
+
...input.model,
|
|
1841
|
+
fields: input.model.fields.map((f) => ({
|
|
1842
|
+
...f,
|
|
1843
|
+
id: f.id ?? modelScalarFieldEntityType.generateNewId(),
|
|
1844
|
+
})),
|
|
1845
|
+
relations: input.model.relations?.map((r) => ({
|
|
1846
|
+
...r,
|
|
1847
|
+
id: r.id ?? modelLocalRelationEntityType.generateNewId(),
|
|
1848
|
+
foreignId: r.foreignId ?? modelForeignRelationEntityType.generateNewId(),
|
|
1849
|
+
})),
|
|
1850
|
+
uniqueConstraints: input.model.uniqueConstraints?.map((c) => ({
|
|
1851
|
+
...c,
|
|
1852
|
+
id: c.id ?? modelUniqueConstraintEntityType.generateNewId(),
|
|
1853
|
+
})),
|
|
1854
|
+
},
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Deserializes a model merger model input converting all names to IDs.
|
|
1859
|
+
*
|
|
1860
|
+
* @param input - The model merger model input.
|
|
1861
|
+
* @param resolveForeignFieldRef - A function that resolves the foreign field ref.
|
|
1862
|
+
* @returns The deserialized model merger model input.
|
|
1863
|
+
*/
|
|
1864
|
+
function deserializeModelMergerModelInput(input, resolveForeignFieldRef, resolveForeignRelationRef) {
|
|
1865
|
+
const inputWithIds = attachIdsToModelMergerModelInput(input);
|
|
1866
|
+
const resolveLocalFieldName = (name) => {
|
|
1867
|
+
const field = inputWithIds.model.fields.find((f) => f.name === name);
|
|
1868
|
+
if (!field) {
|
|
1869
|
+
throw new Error(`Field ${name} not found`);
|
|
1870
|
+
}
|
|
1871
|
+
return field.id;
|
|
1872
|
+
};
|
|
1873
|
+
const resolveLocalRelationName = (name) => {
|
|
1874
|
+
const relation = inputWithIds.model.relations?.find((r) => r.name === name);
|
|
1875
|
+
if (!relation) {
|
|
1876
|
+
throw new Error(`Relation ${name} not found`);
|
|
1877
|
+
}
|
|
1878
|
+
return relation.id;
|
|
1879
|
+
};
|
|
1880
|
+
return {
|
|
1881
|
+
...inputWithIds,
|
|
1882
|
+
model: {
|
|
1883
|
+
...inputWithIds.model,
|
|
1884
|
+
relations: inputWithIds.model.relations?.map((relation) => ({
|
|
1885
|
+
...relation,
|
|
1886
|
+
references: relation.references.map((reference) => ({
|
|
1887
|
+
...reference,
|
|
1888
|
+
localRef: resolveLocalFieldName(reference.localRef),
|
|
1889
|
+
foreignRef: resolveForeignFieldRef(relation.modelRef, reference.foreignRef),
|
|
1890
|
+
})),
|
|
1891
|
+
})),
|
|
1892
|
+
uniqueConstraints: inputWithIds.model.uniqueConstraints?.map((constraint) => ({
|
|
1893
|
+
...constraint,
|
|
1894
|
+
fields: constraint.fields.map((field) => ({
|
|
1895
|
+
...field,
|
|
1896
|
+
fieldRef: resolveLocalFieldName(field.fieldRef),
|
|
1897
|
+
})),
|
|
1898
|
+
})),
|
|
1899
|
+
primaryKeyFieldRefs: inputWithIds.model.primaryKeyFieldRefs.map((fieldRef) => resolveLocalFieldName(fieldRef)),
|
|
1900
|
+
},
|
|
1901
|
+
graphql: {
|
|
1902
|
+
...inputWithIds.graphql,
|
|
1903
|
+
objectType: {
|
|
1904
|
+
...inputWithIds.graphql?.objectType,
|
|
1905
|
+
fields: inputWithIds.graphql?.objectType?.fields.map((fieldRef) => resolveLocalFieldName(fieldRef)) ?? [],
|
|
1906
|
+
localRelations: inputWithIds.graphql?.objectType?.localRelations?.map((relationRef) => resolveLocalRelationName(relationRef)) ?? [],
|
|
1907
|
+
foreignRelations: inputWithIds.graphql?.objectType?.foreignRelations?.map((relationRef) => resolveForeignRelationRef(relationRef)) ?? [],
|
|
1908
|
+
},
|
|
1909
|
+
},
|
|
1910
|
+
};
|
|
1911
|
+
}
|
|
1912
|
+
/**
|
|
1913
|
+
* Creates a new blank model config input from a name and feature ref.
|
|
1914
|
+
*
|
|
1915
|
+
* @param name - The name of the model.
|
|
1916
|
+
* @param featureRef - The feature ref of the model.
|
|
1917
|
+
* @returns The new model config input.
|
|
1918
|
+
*/
|
|
1919
|
+
function createNewModelConfigInput(name, featureRef) {
|
|
1920
|
+
return {
|
|
1921
|
+
id: modelEntityType.generateNewId(),
|
|
1922
|
+
name,
|
|
1923
|
+
featureRef,
|
|
1924
|
+
model: {
|
|
1925
|
+
fields: [],
|
|
1926
|
+
primaryKeyFieldRefs: [],
|
|
1927
|
+
},
|
|
1928
|
+
};
|
|
1929
|
+
}
|
|
1930
|
+
/**
|
|
1931
|
+
* Diff the model definition.
|
|
1932
|
+
*
|
|
1933
|
+
* @param current - The current model definition or a new model to be created.
|
|
1934
|
+
* @param desired - The desired model definition.
|
|
1935
|
+
* @param definitionContainer - Project definition container.
|
|
1936
|
+
* @param options - Diff options.
|
|
1937
|
+
* @returns A diff output or undefined if there are no differences.
|
|
1938
|
+
*/
|
|
1939
|
+
function createModelMergerResult(current, desired, definitionContainer, { siblingModels = [] } = {}) {
|
|
1940
|
+
const currentModel = current ?? createNewModelConfigInput(desired.name, desired.featureRef);
|
|
1941
|
+
// resolves all the names of the current model config input
|
|
1942
|
+
const resolvedCurrent = serializeModelMergerModelInput(currentModel, definitionContainer, siblingModels);
|
|
1943
|
+
const diff = createDefinitionDiff(resolvedCurrent, desired, modelMergerDefinitionDiffConfig);
|
|
1944
|
+
if (!diff) {
|
|
1945
|
+
return undefined;
|
|
1946
|
+
}
|
|
1947
|
+
return {
|
|
1948
|
+
isNewModel: !current,
|
|
1949
|
+
id: currentModel.id,
|
|
1950
|
+
name: currentModel.name,
|
|
1951
|
+
featureRef: currentModel.featureRef,
|
|
1952
|
+
changes: diff,
|
|
1953
|
+
};
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* Creates a model merger result for a set of models.
|
|
1957
|
+
*
|
|
1958
|
+
* @param current - A map of model IDs
|
|
1959
|
+
* @param desired - The desired model definition.
|
|
1960
|
+
* @param definitionContainer - Project definition container.
|
|
1961
|
+
* @param options - Diff options.
|
|
1962
|
+
* @returns A model merger result for a set of models.
|
|
1963
|
+
*/
|
|
1964
|
+
function createModelMergerResults(current, desired, definitionContainer, { siblingModels = [] } = {}) {
|
|
1965
|
+
return mapValues(desired, (desired, key) => createModelMergerResult(current[key] && modelEntityType.isId(current[key])
|
|
1966
|
+
? ModelUtils.byIdOrThrow(definitionContainer.definition, current[key])
|
|
1967
|
+
: undefined, desired, definitionContainer, {
|
|
1968
|
+
siblingModels,
|
|
1969
|
+
}));
|
|
1970
|
+
}
|
|
1971
|
+
function applyModelMergerDiff(model, diff, definitionContainer, siblingModels = []) {
|
|
1972
|
+
const resolvedCurrent = serializeModelMergerModelInput(model, definitionContainer, siblingModels);
|
|
1973
|
+
const patchedCurrent = applyDefinitionDiff(resolvedCurrent, diff, modelMergerDefinitionDiffConfig);
|
|
1974
|
+
return {
|
|
1975
|
+
...model,
|
|
1976
|
+
...deserializeModelMergerModelInput(patchedCurrent, (modelId, fieldName) => {
|
|
1977
|
+
const siblingModel = siblingModels.find((m) => m.id === modelId);
|
|
1978
|
+
if (siblingModel) {
|
|
1979
|
+
const field = siblingModel.model.fields.find((f) => f.name === fieldName);
|
|
1980
|
+
if (!field) {
|
|
1981
|
+
throw new Error(`Field ${fieldName} not found in sibling model ${modelId}`);
|
|
1982
|
+
}
|
|
1983
|
+
return field.id;
|
|
1984
|
+
}
|
|
1985
|
+
const model = ModelUtils.byIdOrThrow(definitionContainer.definition, modelId);
|
|
1986
|
+
const field = model.model.fields.find((f) => f.name === fieldName);
|
|
1987
|
+
if (!field) {
|
|
1988
|
+
throw new Error(`Field ${fieldName} not found in model ${model.name}`);
|
|
1989
|
+
}
|
|
1990
|
+
return field.id;
|
|
1991
|
+
}, (relationName) => {
|
|
1992
|
+
// Search sibling model first
|
|
1993
|
+
let relationId;
|
|
1994
|
+
for (const siblingModel of siblingModels) {
|
|
1995
|
+
const relation = siblingModel.model.relations?.find((r) => r.foreignRelationName === relationName);
|
|
1996
|
+
if (relation) {
|
|
1997
|
+
relationId = relation.foreignId;
|
|
1998
|
+
break;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
if (relationId) {
|
|
2002
|
+
return relationId;
|
|
2003
|
+
}
|
|
2004
|
+
const relations = ModelUtils.getRelationsToModel(definitionContainer.definition, model.id);
|
|
2005
|
+
const relation = relations.find((r) => r.relation.foreignRelationName === relationName &&
|
|
2006
|
+
r.relation.modelRef === model.id);
|
|
2007
|
+
if (!relation) {
|
|
2008
|
+
throw new Error(`Relation ${relationName} not found in model ${model.name}`);
|
|
2009
|
+
}
|
|
2010
|
+
return relation.relation.foreignId;
|
|
2011
|
+
}),
|
|
2012
|
+
};
|
|
2013
|
+
}
|
|
2014
|
+
function applyModelMergerResultInPlace(draftConfig, result, definitionContainer, { siblingModels = [] } = {}) {
|
|
2015
|
+
const model = result.isNewModel
|
|
2016
|
+
? createNewModelConfigInput(result.name, result.featureRef)
|
|
2017
|
+
: ModelUtils.byIdOrThrow(definitionContainer.definition, result.id);
|
|
2018
|
+
const newModel = applyModelMergerDiff(model, result.changes, definitionContainer, siblingModels);
|
|
2019
|
+
if (result.isNewModel) {
|
|
2020
|
+
draftConfig.models.push(newModel);
|
|
2021
|
+
}
|
|
2022
|
+
else {
|
|
2023
|
+
const index = draftConfig.models.findIndex((m) => m.id === result.id);
|
|
2024
|
+
if (index === -1) {
|
|
2025
|
+
throw new Error(`Model ${result.id} not found`);
|
|
2026
|
+
}
|
|
2027
|
+
draftConfig.models[index] = newModel;
|
|
2028
|
+
}
|
|
2029
|
+
return newModel.id;
|
|
2030
|
+
}
|
|
2031
|
+
function createAndApplyModelMergerResults(draftConfig, current, desired, definitionContainer, { siblingModels = [] } = {}) {
|
|
2032
|
+
const results = createModelMergerResults(current, desired, definitionContainer, { siblingModels });
|
|
2033
|
+
return mapValues(results, (result, key) => result
|
|
2034
|
+
? applyModelMergerResultInPlace(draftConfig, result, definitionContainer, { siblingModels })
|
|
2035
|
+
: desired[key].name);
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
export { ZodPluginWrapper as A, createInitializedPluginSpec as B, CASE_VALIDATORS as C, ZodRefBuilder as D, DefinitionEntityType as E, FeatureUtils as F, featureNameSchema as G, featureSchema as H, modelMergerDefinitionDiffConfig as I, createModelMergerResult as J, createModelMergerResults as K, applyModelMergerDiff as L, ModelUtils as M, applyModelMergerResultInPlace as N, createAndApplyModelMergerResults as O, DefinitionDiffKeyedArrayField as P, DefinitionDiffReplacementField as Q, DefinitionDiffArrayIncludesField as R, createDefinitionDiffConfig as S, createDefinitionDiff as T, applyDefinitionDiff as U, ZodRefWrapper as Z, createEntityType as a, zRef as b, createPluginSpec as c, modelForeignRelationEntityType as d, modelLocalRelationEntityType as e, modelScalarFieldEntityType as f, get as g, zEnt as h, isEqual as i, modelTransformerEntityType as j, createDefinitionEntityNameResolver as k, modelEntityType as l, mapValues as m, ZodRef as n, modelEnumValueEntityType as o, featureEntityType as p, modelEnumEntityType as q, zRefBuilder as r, set as s, zRefId as t, modelUniqueConstraintEntityType as u, featuresSchema as v, zPluginWrapper as w, omit as x, cloneDeep as y, zodPluginSymbol as z };
|
|
2039
|
+
//# sourceMappingURL=model-merger-CdV-7CWE.js.map
|