ac-storage 0.16.3 → 0.16.5
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/bundle.cjs +45 -3
- package/dist/bundle.cjs.map +1 -1
- package/dist/bundle.mjs +45 -3
- package/dist/bundle.mjs.map +1 -1
- package/package.json +2 -2
package/dist/bundle.cjs
CHANGED
|
@@ -114,6 +114,18 @@ class StructJSONTypeLeaf extends BaseJSONTypeLeaf {
|
|
|
114
114
|
return this;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
class ReplaceJSONTypeLeaf extends BaseJSONTypeLeaf {
|
|
118
|
+
__brand = 'replace';
|
|
119
|
+
constructor(tree) {
|
|
120
|
+
super('replace');
|
|
121
|
+
this.value['replace'] = tree;
|
|
122
|
+
this.value['strict'] = false;
|
|
123
|
+
}
|
|
124
|
+
strict() {
|
|
125
|
+
this.value['strict'] = true;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
117
129
|
|
|
118
130
|
class ArrayJSONTypeLeaf extends BaseJSONTypeLeaf {
|
|
119
131
|
__brand = 'array';
|
|
@@ -160,12 +172,19 @@ function isJSONTypeData(target) {
|
|
|
160
172
|
typeof target === 'object' &&
|
|
161
173
|
target[JSON_TYPE_FLAG] === true);
|
|
162
174
|
}
|
|
175
|
+
function Struct(tree) {
|
|
176
|
+
return new StructJSONTypeLeaf(tree);
|
|
177
|
+
}
|
|
178
|
+
function Replace(tree) {
|
|
179
|
+
return new ReplaceJSONTypeLeaf(tree);
|
|
180
|
+
}
|
|
163
181
|
const JSONType = {
|
|
164
182
|
Union: (...candidates) => new UnionJSONTypeLeaf(...candidates),
|
|
165
183
|
String: () => new StringJSONTypeLeaf(),
|
|
166
184
|
Number: () => new NumberJSONTypeLeaf(),
|
|
167
185
|
Bool: () => new BooleanJSONTypeLeaf(),
|
|
168
|
-
Struct
|
|
186
|
+
Struct,
|
|
187
|
+
Replace,
|
|
169
188
|
Array: (jsonTree) => new ArrayJSONTypeLeaf(jsonTree),
|
|
170
189
|
Any: () => new BaseJSONTypeLeaf('any'),
|
|
171
190
|
};
|
|
@@ -290,8 +309,8 @@ class Flattener {
|
|
|
290
309
|
const { tracePath } = traceResult;
|
|
291
310
|
const reached = tracePath.join(DELIMITER);
|
|
292
311
|
const node = this.navigate.get(reached);
|
|
293
|
-
// 닿을 수 있는 마지막 노드의 타입이 struct, any 라면 허용됨
|
|
294
|
-
if (!node || (node.type !== 'struct' && node.type !== 'any')) {
|
|
312
|
+
// 닿을 수 있는 마지막 노드의 타입이 struct, replace, any 라면 허용됨
|
|
313
|
+
if (!node || (node.type !== 'struct' && node.type !== 'replace' && node.type !== 'any')) {
|
|
295
314
|
throw new JSONAccessorError(`Field '${key}' is not allowed`);
|
|
296
315
|
}
|
|
297
316
|
return [[key, value]];
|
|
@@ -329,6 +348,10 @@ class Flattener {
|
|
|
329
348
|
structData: node,
|
|
330
349
|
});
|
|
331
350
|
}
|
|
351
|
+
else if (node.type === 'replace') {
|
|
352
|
+
// replace 타입은 평탄화 없이 전체 값 반환 → 항상 덮어쓰기
|
|
353
|
+
return [[newKey, value]];
|
|
354
|
+
}
|
|
332
355
|
else if (node.type === 'array') {
|
|
333
356
|
// @TODO : 배열 타입에 대한 세부 처리 필요
|
|
334
357
|
// 현재는 배열 경로까지만 flat이 이루어지므로
|
|
@@ -452,6 +475,10 @@ class CompatibilityChecker {
|
|
|
452
475
|
return true;
|
|
453
476
|
}
|
|
454
477
|
}
|
|
478
|
+
// replace 타입은 실제 값이 struct(객체)로 들어옴
|
|
479
|
+
else if (jsonTypeData.type === 'replace' && targetType === 'struct') {
|
|
480
|
+
return this.isReplaceCompatible(target, jsonTypeData);
|
|
481
|
+
}
|
|
455
482
|
else {
|
|
456
483
|
return false;
|
|
457
484
|
}
|
|
@@ -482,6 +509,21 @@ class CompatibilityChecker {
|
|
|
482
509
|
return false;
|
|
483
510
|
}
|
|
484
511
|
}
|
|
512
|
+
isReplaceCompatible(struct, replaceTypeData) {
|
|
513
|
+
if (!replaceTypeData.strict)
|
|
514
|
+
return true;
|
|
515
|
+
if (!replaceTypeData.replace)
|
|
516
|
+
return true;
|
|
517
|
+
const navigate = r$1.from(replaceTypeData.replace);
|
|
518
|
+
const flattener = new Flattener(navigate, this);
|
|
519
|
+
try {
|
|
520
|
+
flattener.flat({ target: struct, prefix: '' });
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
catch (e) {
|
|
524
|
+
return false;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
485
527
|
getUnionTypeNames(union) {
|
|
486
528
|
return union.candidates.map((c) => {
|
|
487
529
|
if (typeof c === 'object') {
|