1- import { RxSchema } from 'rxdb' ;
1+ import { RxCollection } from 'rxdb' ;
22import {
33 OrionPullExecuteOptions ,
44 OrionPushExecuteOptions ,
@@ -22,12 +22,20 @@ export function buildUrl(parts: (number | string)[]): string {
2222 . replace ( / \/ { 2 , } / g, '/' ) ;
2323}
2424
25- export function extractReferences ( schema : RxSchema ) : Record < string , string > {
25+ export function extractReferences (
26+ collection : RxCollection
27+ ) : Record < string , string > {
2628 const result : Record < string , string > = { } ;
27- const entries = Object . entries ( schema . jsonSchema . properties ) ;
29+ const entries = Object . entries ( collection . schema . jsonSchema . properties ) ;
2830
2931 for ( const [ key , value ] of entries ) {
3032 if ( value . type === 'array' && value . ref ) {
33+ if ( ! collection . database . collections [ value . ref ] ) {
34+ throw new Error (
35+ `Invalid ref '${ value . ref } ' for property '${ key } ' not found`
36+ ) ;
37+ }
38+
3139 result [ key ] = value . ref ;
3240 }
3341 }
@@ -93,7 +101,7 @@ export async function executePull({
93101 exclude,
94102 transporter,
95103} : OrionPullExecuteOptions ) : Promise < any [ ] > {
96- const references = extractReferences ( collection . schema ) ;
104+ const references = extractReferences ( collection ) ;
97105 const keys = Object . keys ( references ) . filter ( ( key ) => ! exclude . includes ( key ) ) ;
98106
99107 const request = {
@@ -145,7 +153,7 @@ export async function executePush({
145153 exclude,
146154 transporter,
147155} : OrionPushExecuteOptions ) : Promise < [ ] > {
148- const references = Object . keys ( extractReferences ( collection . schema ) ) ;
156+ const references = Object . keys ( extractReferences ( collection ) ) ;
149157
150158 for ( const row of rows ) {
151159 const request : Request = { url, headers } ;
0 commit comments