Skip to content

Commit

Permalink
fix dep chain
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianMairinger committed Jan 23, 2024
1 parent d513f25 commit f3495c2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 53 deletions.
39 changes: 1 addition & 38 deletions app/src/dataBaseAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PrimaryStoreAdapter, isAdapterSym } from "./fullyConnectedAdapter"
import cloneKeys from "circ-clone"
import { toPointer, resolvePointer } from "./lib"
import { MultiMap } from "more-maps"

import { parseEscapedRecursion } from "./lib"


type UnifiedDataAndBase = {
Expand Down Expand Up @@ -192,40 +192,3 @@ function getParents(db: InternalDataBase<{}>) {



export function parseEscapedRecursion(rootStore: object, diff: object, mergeIntoDiff = true) {
let known = new Set()

const mergeInto = mergeIntoDiff ? diff : rootStore
rec(diff, mergeInto)
return mergeInto


function rec(diff: any, mergeInto: object = {}) {
if (diff instanceof Object) {
if (known.has(mergeInto)) return mergeInto
known.add(mergeInto)

for (const key in diff) {
const val = diff[key]
if (key === "$ref" && typeof val === "string") {
if (val.startsWith("##")) diff[key] = val.slice(1)
else if (val.startsWith("#")) {
const path = resolvePointer(val)

let c = rootStore
for (const entry of path) {
c = c[entry]
}
return c
}
}
else {
const ret = rec(val, mergeInto[key])
if (Object.hasOwn(mergeInto, key) || !(key in Object.prototype)) mergeInto[key] = ret
}
}
return mergeInto
}
else return diff
}
}
15 changes: 2 additions & 13 deletions app/src/fsReflection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from "path"
import { promises as fs } from "fs"
import { stringify, parse } from "circ-json" // move data storage to be binary based
import { ResablePromise } from "more-proms";
import { parseEscapedRecursion } from "./dataBaseAdapter";
import { parseDataDiff } from "./lib";
import clone, { mergeKeysDeep } from "circ-clone"


Expand Down Expand Up @@ -93,18 +93,7 @@ export async function fsToAdapter(fsPath: string) {
}


export function parseDataDiff(full: any, diff: any) {
let data: any
if (typeof diff === "object" && diff !== null) {
if (typeof full !== "object" || full === null) data = diff
else {
data = parseEscapedRecursion(full, diff, false)

}
}
else data = diff
return data
}




Expand Down
53 changes: 52 additions & 1 deletion app/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,55 @@ export const resolvePointer = (pointer) => {
ar.push(part)
}
return ar
}
}

export function parseDataDiff(full: any, diff: any) {
let data: any
if (typeof diff === "object" && diff !== null) {
if (typeof full !== "object" || full === null) data = diff
else {
data = parseEscapedRecursion(full, diff, false)

}
}
else data = diff
return data
}

export function parseEscapedRecursion(rootStore: object, diff: object, mergeIntoDiff = true) {
let known = new Set()

const mergeInto = mergeIntoDiff ? diff : rootStore
rec(diff, mergeInto)
return mergeInto


function rec(diff: any, mergeInto: object = {}) {
if (diff instanceof Object) {
if (known.has(mergeInto)) return mergeInto
known.add(mergeInto)

for (const key in diff) {
const val = diff[key]
if (key === "$ref" && typeof val === "string") {
if (val.startsWith("##")) diff[key] = val.slice(1)
else if (val.startsWith("#")) {
const path = resolvePointer(val)

let c = rootStore
for (const entry of path) {
c = c[entry]
}
return c
}
}
else {
const ret = rec(val, mergeInto[key])
if (Object.hasOwn(mergeInto, key) || !(key in Object.prototype)) mergeInto[key] = ret
}
}
return mergeInto
}
else return diff
}
}
2 changes: 1 addition & 1 deletion app/src/localStorageReflection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseDataDiff } from "./fsReflection";
import { parseDataDiff } from "./lib";
import { PrimaryTransmissionAdapter, SecondaryStoreAdapter, isAdapterSym } from "./fullyConnectedAdapter"
import { makeJosmReflection } from "./josmReflection";
import { stringify, parse } from "circ-json" // move this to binary
Expand Down

0 comments on commit f3495c2

Please sign in to comment.