ac-storage 0.16.3 → 0.16.4

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.mjs CHANGED
@@ -91,6 +91,18 @@ class StructJSONTypeLeaf extends BaseJSONTypeLeaf {
91
91
  return this;
92
92
  }
93
93
  }
94
+ class ReplaceJSONTypeLeaf extends BaseJSONTypeLeaf {
95
+ __brand = 'replace';
96
+ constructor(tree) {
97
+ super('replace');
98
+ this.value['replace'] = tree;
99
+ this.value['strict'] = false;
100
+ }
101
+ strict() {
102
+ this.value['strict'] = true;
103
+ return this;
104
+ }
105
+ }
94
106
 
95
107
  class ArrayJSONTypeLeaf extends BaseJSONTypeLeaf {
96
108
  __brand = 'array';
@@ -143,6 +155,7 @@ const JSONType = {
143
155
  Number: () => new NumberJSONTypeLeaf(),
144
156
  Bool: () => new BooleanJSONTypeLeaf(),
145
157
  Struct: (tree) => new StructJSONTypeLeaf(tree),
158
+ Replace: (tree) => new ReplaceJSONTypeLeaf(tree),
146
159
  Array: (jsonTree) => new ArrayJSONTypeLeaf(jsonTree),
147
160
  Any: () => new BaseJSONTypeLeaf('any'),
148
161
  };
@@ -267,8 +280,8 @@ class Flattener {
267
280
  const { tracePath } = traceResult;
268
281
  const reached = tracePath.join(DELIMITER);
269
282
  const node = this.navigate.get(reached);
270
- // 닿을 수 있는 마지막 노드의 타입이 struct, any 라면 허용됨
271
- if (!node || (node.type !== 'struct' && node.type !== 'any')) {
283
+ // 닿을 수 있는 마지막 노드의 타입이 struct, replace, any 라면 허용됨
284
+ if (!node || (node.type !== 'struct' && node.type !== 'replace' && node.type !== 'any')) {
272
285
  throw new JSONAccessorError(`Field '${key}' is not allowed`);
273
286
  }
274
287
  return [[key, value]];
@@ -306,6 +319,10 @@ class Flattener {
306
319
  structData: node,
307
320
  });
308
321
  }
322
+ else if (node.type === 'replace') {
323
+ // replace 타입은 평탄화 없이 전체 값 반환 → 항상 덮어쓰기
324
+ return [[newKey, value]];
325
+ }
309
326
  else if (node.type === 'array') {
310
327
  // @TODO : 배열 타입에 대한 세부 처리 필요
311
328
  // 현재는 배열 경로까지만 flat이 이루어지므로
@@ -429,6 +446,10 @@ class CompatibilityChecker {
429
446
  return true;
430
447
  }
431
448
  }
449
+ // replace 타입은 실제 값이 struct(객체)로 들어옴
450
+ else if (jsonTypeData.type === 'replace' && targetType === 'struct') {
451
+ return this.isReplaceCompatible(target, jsonTypeData);
452
+ }
432
453
  else {
433
454
  return false;
434
455
  }
@@ -459,6 +480,21 @@ class CompatibilityChecker {
459
480
  return false;
460
481
  }
461
482
  }
483
+ isReplaceCompatible(struct, replaceTypeData) {
484
+ if (!replaceTypeData.strict)
485
+ return true;
486
+ if (!replaceTypeData.replace)
487
+ return true;
488
+ const navigate = r$1.from(replaceTypeData.replace);
489
+ const flattener = new Flattener(navigate, this);
490
+ try {
491
+ flattener.flat({ target: struct, prefix: '' });
492
+ return true;
493
+ }
494
+ catch (e) {
495
+ return false;
496
+ }
497
+ }
462
498
  getUnionTypeNames(union) {
463
499
  return union.candidates.map((c) => {
464
500
  if (typeof c === 'object') {