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.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';
@@ -166,6 +178,7 @@ const JSONType = {
166
178
  Number: () => new NumberJSONTypeLeaf(),
167
179
  Bool: () => new BooleanJSONTypeLeaf(),
168
180
  Struct: (tree) => new StructJSONTypeLeaf(tree),
181
+ Replace: (tree) => new ReplaceJSONTypeLeaf(tree),
169
182
  Array: (jsonTree) => new ArrayJSONTypeLeaf(jsonTree),
170
183
  Any: () => new BaseJSONTypeLeaf('any'),
171
184
  };
@@ -290,8 +303,8 @@ class Flattener {
290
303
  const { tracePath } = traceResult;
291
304
  const reached = tracePath.join(DELIMITER);
292
305
  const node = this.navigate.get(reached);
293
- // 닿을 수 있는 마지막 노드의 타입이 struct, any 라면 허용됨
294
- if (!node || (node.type !== 'struct' && node.type !== 'any')) {
306
+ // 닿을 수 있는 마지막 노드의 타입이 struct, replace, any 라면 허용됨
307
+ if (!node || (node.type !== 'struct' && node.type !== 'replace' && node.type !== 'any')) {
295
308
  throw new JSONAccessorError(`Field '${key}' is not allowed`);
296
309
  }
297
310
  return [[key, value]];
@@ -329,6 +342,10 @@ class Flattener {
329
342
  structData: node,
330
343
  });
331
344
  }
345
+ else if (node.type === 'replace') {
346
+ // replace 타입은 평탄화 없이 전체 값 반환 → 항상 덮어쓰기
347
+ return [[newKey, value]];
348
+ }
332
349
  else if (node.type === 'array') {
333
350
  // @TODO : 배열 타입에 대한 세부 처리 필요
334
351
  // 현재는 배열 경로까지만 flat이 이루어지므로
@@ -452,6 +469,10 @@ class CompatibilityChecker {
452
469
  return true;
453
470
  }
454
471
  }
472
+ // replace 타입은 실제 값이 struct(객체)로 들어옴
473
+ else if (jsonTypeData.type === 'replace' && targetType === 'struct') {
474
+ return this.isReplaceCompatible(target, jsonTypeData);
475
+ }
455
476
  else {
456
477
  return false;
457
478
  }
@@ -482,6 +503,21 @@ class CompatibilityChecker {
482
503
  return false;
483
504
  }
484
505
  }
506
+ isReplaceCompatible(struct, replaceTypeData) {
507
+ if (!replaceTypeData.strict)
508
+ return true;
509
+ if (!replaceTypeData.replace)
510
+ return true;
511
+ const navigate = r$1.from(replaceTypeData.replace);
512
+ const flattener = new Flattener(navigate, this);
513
+ try {
514
+ flattener.flat({ target: struct, prefix: '' });
515
+ return true;
516
+ }
517
+ catch (e) {
518
+ return false;
519
+ }
520
+ }
485
521
  getUnionTypeNames(union) {
486
522
  return union.candidates.map((c) => {
487
523
  if (typeof c === 'object') {