MCPcopy
hub / github.com/drizzle-team/drizzle-orm / mapArraysDiff

Function mapArraysDiff

drizzle-kit/src/jsonDiffer.js:56–88  ·  view source on GitHub ↗
(source, diff)

Source from the content-addressed store, hash-verified

54};
55
56const mapArraysDiff = (source, diff) => {
57 const sequence = [];
58 let sourceIndex = 0;
59 for (let i = 0; i < diff.length; i++) {
60 const it = diff[i];
61 if (it.length === 1) {
62 sequence.push({ type: 'same', value: source[sourceIndex] });
63 sourceIndex += 1;
64 } else {
65 if (it[0] === '-') {
66 sequence.push({ type: 'removed', value: it[1] });
67 } else {
68 sequence.push({ type: 'added', value: it[1], before: '' });
69 }
70 }
71 }
72 const result = sequence.reverse().reduce(
73 (acc, it) => {
74 if (it.type === 'same') {
75 acc.prev = it.value;
76 }
77
78 if (it.type === 'added' && acc.prev) {
79 it.before = acc.prev;
80 }
81 acc.result.push(it);
82 return acc;
83 },
84 { result: [] },
85 );
86
87 return result.result.reverse();
88};
89
90export function diffSchemasOrTables(left, right) {
91 left = JSON.parse(JSON.stringify(left));

Callers 1

applyJsonDiffFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected