Skip to content

Commit

Permalink
support recursive references in schema (#32)
Browse files Browse the repository at this point in the history
* support recursive references in schema

* not using result
  • Loading branch information
mafintosh authored Jan 14, 2025
1 parent e17430a commit dfed89e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ class Collection extends DBType {
this.valueEncoding = this._deriveValueSchema().fqn
}

_deriveValueSchema (schema = this.schema, prefix = '', primaryKeySet = new Set(this.key)) {
_deriveValueSchema (schema = this.schema, prefix = '', primaryKeySet = new Set(this.key), parents = new Set()) {
const fields = []
const type = '/hyperdb#' + this.id

if (!schema.isStruct) return { external: false, fqn: schema.name }
if (!schema.isStruct || parents.has(schema)) return { external: false, fqn: schema.name }

parents.add(schema)

let external = false

Expand All @@ -108,7 +110,7 @@ class Collection extends DBType {

if (primaryKeySet.has(name)) {
external = cpy.external = true
} else if (this._deriveValueSchema(f.type, name, primaryKeySet).external) {
} else if (this._deriveValueSchema(f.type, name, primaryKeySet, new Set([...parents])).external) {
external = true
}

Expand Down

0 comments on commit dfed89e

Please sign in to comment.