@osdk/faux 0.2.0-beta.3 → 0.2.0-beta.5

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.
@@ -1 +1 @@
1
- {"version":3,"file":"FauxFoundry.js","names":["crypto","OntologyNotFoundError","createFauxFoundryHandlers","OpenApiCallError","FauxAttachmentStore","FauxDataStore","FauxOntology","FauxFoundry","ontologiesByRid","Map","ontologiesByApiName","dataStoresByOntologyApiName","handlers","attachments","constructor","baseUrl","defaultOntology","apiName","displayName","description","rid","randomUUID","logger","createOntology","defaultOntologyRid","getDefaultOntology","getOntology","getDefaultDataStore","getDataStore","metadata","ret","registerOntology","ontology","set","getOntologyFullMetadata","ontologyApiNameOrRid","get","setDataStore","fauxDataStore","dataStore","getEveryOntology","Object","values"],"sources":["FauxFoundry.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Logger } from \"@osdk/api\";\nimport type { Ontology, OntologyV2 } from \"@osdk/foundry.ontologies\";\nimport type { RequestHandler } from \"msw\";\nimport * as crypto from \"node:crypto\";\nimport { OntologyNotFoundError } from \"../errors.js\";\nimport { createFauxFoundryHandlers } from \"../handlers/createFauxFoundryHandlers.js\";\nimport { OpenApiCallError } from \"../handlers/util/handleOpenApiCall.js\";\nimport { FauxAttachmentStore } from \"./FauxAttachmentStore.js\";\nimport { FauxDataStore } from \"./FauxDataStore.js\";\nimport { FauxOntology } from \"./FauxOntology.js\";\n\nexport class FauxFoundry {\n #ontologiesByRid = new Map<string, FauxOntology>();\n #ontologiesByApiName = new Map<string, FauxOntology>();\n\n #dataStoresByOntologyApiName = new Map<string, FauxDataStore>();\n\n #handlers: RequestHandler[];\n\n readonly attachments: FauxAttachmentStore = new FauxAttachmentStore();\n readonly baseUrl: string;\n readonly defaultOntologyRid: any;\n readonly logger: Logger | undefined;\n\n constructor(\n baseUrl: string,\n defaultOntology: Ontology = {\n apiName: \"default-ontology\",\n displayName: \"Ontology\",\n description: \"The default ontology\",\n rid: `ri.ontology.main.ontology.${crypto.randomUUID()}`,\n },\n { logger }: { logger?: Logger } = {},\n ) {\n this.baseUrl = baseUrl;\n this.#handlers = createFauxFoundryHandlers(baseUrl, this);\n this.createOntology(defaultOntology);\n this.defaultOntologyRid = defaultOntology.rid;\n this.logger = logger;\n }\n\n get handlers(): RequestHandler[] {\n return this.#handlers;\n }\n\n getDefaultOntology(): FauxOntology {\n return this.getOntology(this.defaultOntologyRid);\n }\n\n getDefaultDataStore(): FauxDataStore {\n return this.getDataStore(this.defaultOntologyRid);\n }\n\n createOntology(metadata: OntologyV2): FauxOntology {\n const ret = new FauxOntology(metadata);\n this.registerOntology(ret);\n\n return ret;\n }\n\n registerOntology(ontology: FauxOntology): void {\n this.#ontologiesByApiName.set(\n ontology.getOntologyFullMetadata().ontology.apiName,\n ontology,\n );\n\n this.#ontologiesByRid.set(\n ontology.getOntologyFullMetadata().ontology.rid,\n ontology,\n );\n }\n\n getOntology(ontologyApiNameOrRid: string): FauxOntology {\n const ontology = this.#ontologiesByApiName.get(ontologyApiNameOrRid)\n ?? this.#ontologiesByRid.get(ontologyApiNameOrRid);\n if (!ontology) {\n throw new OpenApiCallError(\n 404,\n OntologyNotFoundError(ontologyApiNameOrRid),\n );\n }\n return ontology;\n }\n\n setDataStore(\n ontologyApiNameOrRid: string,\n fauxDataStore: FauxDataStore,\n ): void {\n const ontology = this.getOntology(ontologyApiNameOrRid); // will throw\n this.#dataStoresByOntologyApiName.set(\n ontology.apiName,\n fauxDataStore,\n );\n }\n\n getDataStore(ontologyApiNameOrRid: string): FauxDataStore {\n const ontology = this.getOntology(ontologyApiNameOrRid); // will throw\n const dataStore = this.#dataStoresByOntologyApiName.get(ontology.apiName);\n if (!dataStore) {\n const ret = new FauxDataStore(ontology, this.attachments);\n this.setDataStore(ontologyApiNameOrRid, ret);\n return ret;\n }\n return dataStore;\n }\n\n getEveryOntology(): FauxOntology[] {\n return Object.values(this.#ontologiesByApiName);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,OAAO,KAAKA,MAAM,MAAM,aAAa;AACrC,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SAASC,yBAAyB,QAAQ,0CAA0C;AACpF,SAASC,gBAAgB,QAAQ,uCAAuC;AACxE,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,YAAY,QAAQ,mBAAmB;AAEhD,OAAO,MAAMC,WAAW,CAAC;EACvB,CAACC,eAAe,GAAG,IAAIC,GAAG,CAAuB,CAAC;EAClD,CAACC,mBAAmB,GAAG,IAAID,GAAG,CAAuB,CAAC;EAEtD,CAACE,2BAA2B,GAAG,IAAIF,GAAG,CAAwB,CAAC;EAE/D,CAACG,QAAQ;EAEAC,WAAW,GAAwB,IAAIT,mBAAmB,CAAC,CAAC;EAKrEU,WAAWA,CACTC,OAAe,EACfC,eAAyB,GAAG;IAC1BC,OAAO,EAAE,kBAAkB;IAC3BC,WAAW,EAAE,UAAU;IACvBC,WAAW,EAAE,sBAAsB;IACnCC,GAAG,EAAE,6BAA6BpB,MAAM,CAACqB,UAAU,CAAC,CAAC;EACvD,CAAC,EACD;IAAEC;EAA4B,CAAC,GAAG,CAAC,CAAC,EACpC;IACA,IAAI,CAACP,OAAO,GAAGA,OAAO;IACtB,IAAI,CAAC,CAACH,QAAQ,GAAGV,yBAAyB,CAACa,OAAO,EAAE,IAAI,CAAC;IACzD,I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A,CACVF,oBAA4B,EAC5BG,aAA4B,EACtB;IACN,MAAMN,QAAQ,GAAG,IAAI,CAACN,WAAW,CAACS,oBAAoB,CAAC,CAAC,CAAC;IACzD,IAAI,CAAC,CAACxB,2BAA2B,CAACsB,GAAG,CACnCD,QAAQ,CAACf,OAAO,EAChBqB,aACF,CAAC;EACH;EAEAV,YAAYA,CAACO,oBAA4B,EAAiB;IACxD,MAAMH,QAAQ,GAAG,IAAI,CAACN,WAAW,CAACS,oBAAoB,CAAC,CAAC,CAAC;IACzD,MAAMI,SAAS,GAAG,IAAI,CAAC,CAAC5B,2BAA2B,CAACyB,GAAG,CAACJ,QAAQ,CAACf,OAAO,CAAC;IACzE,IAAI,CAACsB,SAAS,EAAE;MACd,MAAMT,GAAG,GAAG,IAAIzB,aAAa,CAAC2B,QAAQ,EAAE,IAAI,CAACnB,WAAW,CAAC;MACzD,IAAI,CAACwB,YAAY,CAACF,oBAAoB,EAAEL,GAAG,CAAC;MAC5C,OAAOA,GAAG;IACZ;IACA,OAAOS,SAAS;EAClB;EAEAC,gBAAgBA,CAAA,EAAmB;IACjC,OAAOC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC,CAAChC,mBAAmB,CAAC;EACjD;AACF","ignoreList":[]}
1
+ {"version":3,"file":"FauxFoundry.js","names":["crypto","OntologyNotFoundError","createFauxFoundryHandlers","OpenApiCallError","FauxAttachmentStore","FauxDataStore","FauxOntology","FauxFoundry","ontologiesByRid","Map","ontologiesByApiName","dataStoresByOntologyApiName","handlers","attachments","constructor","baseUrl","defaultOntology","apiName","displayName","description","rid","randomUUID","logger","strict","createOntology","defaultOntologyRid","getDefaultOntology","getOntology","getDefaultDataStore","getDataStore","metadata","ret","registerOntology","ontology","set","getOntologyFullMetadata","ontologyApiNameOrRid","get","setDataStore","fauxDataStore","dataStore","getEveryOntology","Object","values"],"sources":["FauxFoundry.ts"],"sourcesContent":["/*\n * Copyright 2023 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Logger } from \"@osdk/api\";\nimport type { Ontology, OntologyV2 } from \"@osdk/foundry.ontologies\";\nimport type { RequestHandler } from \"msw\";\nimport * as crypto from \"node:crypto\";\nimport { OntologyNotFoundError } from \"../errors.js\";\nimport { createFauxFoundryHandlers } from \"../handlers/createFauxFoundryHandlers.js\";\nimport { OpenApiCallError } from \"../handlers/util/handleOpenApiCall.js\";\nimport { FauxAttachmentStore } from \"./FauxAttachmentStore.js\";\nimport { FauxDataStore } from \"./FauxDataStore.js\";\nimport { FauxOntology } from \"./FauxOntology.js\";\n\nexport class FauxFoundry {\n #ontologiesByRid = new Map<string, FauxOntology>();\n #ontologiesByApiName = new Map<string, FauxOntology>();\n\n #dataStoresByOntologyApiName = new Map<string, FauxDataStore>();\n\n #handlers: RequestHandler[];\n\n readonly attachments: FauxAttachmentStore = new FauxAttachmentStore();\n readonly baseUrl: string;\n readonly defaultOntologyRid: any;\n readonly logger: Logger | undefined;\n strict: boolean;\n\n constructor(\n baseUrl: string,\n defaultOntology: Ontology = {\n apiName: \"default-ontology\",\n displayName: \"Ontology\",\n description: \"The default ontology\",\n rid: `ri.ontology.main.ontology.${crypto.randomUUID()}`,\n },\n { logger, strict }: { logger?: Logger; strict?: boolean } = {},\n ) {\n this.strict = strict ?? true;\n this.baseUrl = baseUrl;\n this.#handlers = createFauxFoundryHandlers(baseUrl, this);\n this.createOntology(defaultOntology);\n this.defaultOntologyRid = defaultOntology.rid;\n this.logger = logger;\n }\n\n get handlers(): RequestHandler[] {\n return this.#handlers;\n }\n\n getDefaultOntology(): FauxOntology {\n return this.getOntology(this.defaultOntologyRid);\n }\n\n getDefaultDataStore(): FauxDataStore {\n return this.getDataStore(this.defaultOntologyRid);\n }\n\n createOntology(metadata: OntologyV2): FauxOntology {\n const ret = new FauxOntology(metadata);\n this.registerOntology(ret);\n\n return ret;\n }\n\n registerOntology(ontology: FauxOntology): void {\n this.#ontologiesByApiName.set(\n ontology.getOntologyFullMetadata().ontology.apiName,\n ontology,\n );\n\n this.#ontologiesByRid.set(\n ontology.getOntologyFullMetadata().ontology.rid,\n ontology,\n );\n }\n\n getOntology(ontologyApiNameOrRid: string): FauxOntology {\n const ontology = this.#ontologiesByApiName.get(ontologyApiNameOrRid)\n ?? this.#ontologiesByRid.get(ontologyApiNameOrRid);\n if (!ontology) {\n throw new OpenApiCallError(\n 404,\n OntologyNotFoundError(ontologyApiNameOrRid),\n );\n }\n return ontology;\n }\n\n setDataStore(\n ontologyApiNameOrRid: string,\n fauxDataStore: FauxDataStore,\n ): void {\n const ontology = this.getOntology(ontologyApiNameOrRid); // will throw\n this.#dataStoresByOntologyApiName.set(\n ontology.apiName,\n fauxDataStore,\n );\n }\n\n getDataStore(ontologyApiNameOrRid: string): FauxDataStore {\n const ontology = this.getOntology(ontologyApiNameOrRid); // will throw\n const dataStore = this.#dataStoresByOntologyApiName.get(ontology.apiName);\n if (!dataStore) {\n const ret = new FauxDataStore(ontology, this.attachments, this.strict);\n this.setDataStore(ontologyApiNameOrRid, ret);\n return ret;\n }\n return dataStore;\n }\n\n getEveryOntology(): FauxOntology[] {\n return Object.values(this.#ontologiesByApiName);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,OAAO,KAAKA,MAAM,MAAM,aAAa;AACrC,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SAASC,yBAAyB,QAAQ,0CAA0C;AACpF,SAASC,gBAAgB,QAAQ,uCAAuC;AACxE,SAASC,mBAAmB,QAAQ,0BAA0B;AAC9D,S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G,GAAG,IAAI1B,aAAa,CAAC4B,QAAQ,EAAE,IAAI,CAACpB,WAAW,EAAE,IAAI,CAACU,MAAM,CAAC;MACtE,IAAI,CAACe,YAAY,CAACF,oBAAoB,EAAEL,GAAG,CAAC;MAC5C,OAAOA,GAAG;IACZ;IACA,OAAOS,SAAS;EAClB;EAEAC,gBAAgBA,CAAA,EAAmB;IACjC,OAAOC,MAAM,CAACC,MAAM,CAAC,IAAI,CAAC,CAACjC,mBAAmB,CAAC;EACjD;AACF","ignoreList":[]}
@@ -1135,9 +1135,11 @@ var FauxDataStore = class {
1135
1135
  #media = new mnemonist.DefaultMap((_objectType) => new mnemonist.DefaultMap((_propName) => {
1136
1136
  return /* @__PURE__ */ new Map();
1137
1137
  }));
1138
- constructor(fauxOntology, attachments) {
1138
+ #strict;
1139
+ constructor(fauxOntology, attachments, strict) {
1139
1140
  this.#fauxOntology = fauxOntology;
1140
1141
  this.#attachments = attachments;
1142
+ this.#strict = strict;
1141
1143
  }
1142
1144
  /**
1143
1145
  * Removes all data that is associated with a namespace/ontology.
@@ -1243,20 +1245,101 @@ var FauxDataStore = class {
1243
1245
  };
1244
1246
  }
1245
1247
  replaceObjectOrThrow(x) {
1246
- this.#assertObjectExists(x.__apiName, x.__primaryKey);
1248
+ const objectType = this.ontology.getObjectTypeFullMetadataOrThrow(x.__apiName);
1249
+ const oldObject = this.getObjectOrThrow(x.__apiName, x.__primaryKey);
1250
+ const linksToUpdate = [];
1251
+ const linksToRemove = [];
1252
+ for (const linkDef of objectType.linkTypes) {
1253
+ if (linkDef.cardinality === "ONE") {
1254
+ !(this.#strict && linkDef.foreignKeyPropertyApiName) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, `Error examining ${objectType.objectType.apiName}.${linkDef.apiName}: ONE side of links should have a foreign key. `) : invariant4__default.default(false) : void 0;
1255
+ const fkName = linkDef.foreignKeyPropertyApiName;
1256
+ const fkValue = x[fkName];
1257
+ const oldFkValue = oldObject[fkName];
1258
+ if (oldObject[fkName] !== x[fkName]) {
1259
+ const dstSide = this.ontology.getOtherLinkTypeSideV2OrThrow(objectType.objectType.apiName, linkDef.apiName);
1260
+ const dstLocator = objectLocator({
1261
+ __apiName: dstSide.objectTypeApiName,
1262
+ __primaryKey: fkValue
1263
+ });
1264
+ const target = this.getObject(dstSide.objectTypeApiName, fkValue);
1265
+ if (fkValue != null && !target) {
1266
+ console.log(`WARNING! Setting a FK value to a non-existent object: ${dstLocator}`);
1267
+ }
1268
+ if (fkValue != null) {
1269
+ linksToUpdate.push({
1270
+ dstSide,
1271
+ dstLocator,
1272
+ srcSide: linkDef,
1273
+ srcLocator: objectLocator(x)
1274
+ });
1275
+ } else {
1276
+ linksToRemove.push({
1277
+ srcLocator: objectLocator(x),
1278
+ srcSide: linkDef,
1279
+ dstLocator: objectLocator({
1280
+ __apiName: dstSide.objectTypeApiName,
1281
+ __primaryKey: oldFkValue
1282
+ }),
1283
+ dstSide
1284
+ });
1285
+ }
1286
+ }
1287
+ }
1288
+ }
1247
1289
  this.#objects.get(x.__apiName).set(String(x.__primaryKey), x);
1290
+ for (const {
1291
+ srcSide,
1292
+ srcLocator,
1293
+ dstSide,
1294
+ dstLocator
1295
+ } of linksToUpdate) {
1296
+ this.#updateSingleLinkSide(srcSide, srcLocator, dstSide, dstLocator);
1297
+ this.#updateSingleLinkSide(dstSide, dstLocator, srcSide, srcLocator);
1298
+ }
1299
+ for (const {
1300
+ srcSide,
1301
+ srcLocator,
1302
+ dstSide,
1303
+ dstLocator
1304
+ } of linksToRemove) {
1305
+ this.#removeSingleSideOfLink(srcLocator, srcSide, dstLocator);
1306
+ this.#removeSingleSideOfLink(dstLocator, dstSide, srcLocator);
1307
+ }
1248
1308
  }
1249
1309
  /** Throws if the object does not already exist */
1250
1310
  unregisterObjectOrThrow(objectType, primaryKey) {
1251
1311
  this.#assertObjectExists(objectType, primaryKey);
1252
1312
  this.#objects.get(objectType).delete(String(primaryKey));
1253
1313
  }
1254
- registerLink(src, srcLinkName, dst, destLinkName) {
1314
+ registerLink(tmpSrc, srcLinkName, tmpDst, destLinkName) {
1315
+ const src = this.getObjectOrThrow(tmpSrc.__apiName, tmpSrc.__primaryKey);
1316
+ const dst = this.getObjectOrThrow(tmpDst.__apiName, tmpDst.__primaryKey);
1255
1317
  const srcLocator = objectLocator(src);
1256
1318
  const dstLocator = objectLocator(dst);
1257
1319
  const [srcSide, dstSide] = this.#fauxOntology.getBothLinkTypeSides(src.__apiName, srcLinkName, dst.__apiName);
1258
1320
  !(srcSide.linkTypeRid === dstSide.linkTypeRid) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, `Expected both sides of the link to have the same rid, but got ${srcSide.linkTypeRid} and ${dstSide.linkTypeRid}`) : invariant4__default.default(false) : void 0;
1259
1321
  !(dstSide.apiName === destLinkName) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, `Link name mismatch on dst side. Expected ${destLinkName} but found ${dstSide.apiName}`) : invariant4__default.default(false) : void 0;
1322
+ if (this.#strict) {
1323
+ const oneSide = srcSide.cardinality === "ONE" ? {
1324
+ object: src,
1325
+ link: srcSide
1326
+ } : dstSide.cardinality === "ONE" ? {
1327
+ object: dst,
1328
+ link: dstSide
1329
+ } : void 0;
1330
+ const manySide = oneSide ? srcSide.cardinality === "MANY" ? {
1331
+ object: src} : {
1332
+ object: dst} : void 0;
1333
+ if (oneSide && manySide) {
1334
+ !oneSide.link.foreignKeyPropertyApiName ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, `Expected to find a foreignKeyPropertyApiName on the one side: ${oneSide.object.__apiName}.${oneSide.link.apiName}`) : invariant4__default.default(false) : void 0;
1335
+ const newObj = {
1336
+ ...oneSide.object,
1337
+ [oneSide.link.foreignKeyPropertyApiName]: manySide.object.__primaryKey
1338
+ };
1339
+ this.replaceObjectOrThrow(newObj);
1340
+ return;
1341
+ }
1342
+ }
1260
1343
  this.#updateSingleLinkSide(srcSide, srcLocator, dstSide, dstLocator);
1261
1344
  this.#updateSingleLinkSide(dstSide, dstLocator, srcSide, srcLocator);
1262
1345
  }
@@ -1265,6 +1348,21 @@ var FauxDataStore = class {
1265
1348
  const dstLocator = objectLocator(dst);
1266
1349
  const [srcSide, dstSide] = this.#fauxOntology.getBothLinkTypeSides(src.__apiName, srcLinkName, dst.__apiName);
1267
1350
  !(dstSide.apiName === dstLinkName) ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, `Link name mismatch on dst side. Expected ${dstLinkName} but found ${dstSide.apiName}`) : invariant4__default.default(false) : void 0;
1351
+ if (this.#strict) {
1352
+ const {
1353
+ oneSide,
1354
+ manySide
1355
+ } = extractOneManySide(srcSide, src, dstSide, dst);
1356
+ if (oneSide && manySide) {
1357
+ !oneSide.link.foreignKeyPropertyApiName ? process.env.NODE_ENV !== "production" ? invariant4__default.default(false, `Expected to find a foreignKeyPropertyApiName on the one side: ${oneSide.object.__apiName}.${oneSide.link.apiName}`) : invariant4__default.default(false) : void 0;
1358
+ const newObj = {
1359
+ ...oneSide.object,
1360
+ [oneSide.link.foreignKeyPropertyApiName]: void 0
1361
+ };
1362
+ this.replaceObjectOrThrow(newObj);
1363
+ return;
1364
+ }
1365
+ }
1268
1366
  this.#removeSingleSideOfLink(srcLocator, srcSide, dstLocator);
1269
1367
  this.#removeSingleSideOfLink(dstLocator, dstSide, srcLocator);
1270
1368
  }
@@ -1524,6 +1622,26 @@ var FauxDataStore = class {
1524
1622
  };
1525
1623
  }
1526
1624
  };
1625
+ function extractOneManySide(srcSide, src, dstSide, dst) {
1626
+ const oneSide = srcSide.cardinality === "ONE" ? {
1627
+ object: src,
1628
+ link: srcSide
1629
+ } : dstSide.cardinality === "ONE" ? {
1630
+ object: dst,
1631
+ link: dstSide
1632
+ } : void 0;
1633
+ const manySide = oneSide ? srcSide.cardinality === "MANY" ? {
1634
+ object: src,
1635
+ link: srcSide
1636
+ } : {
1637
+ object: dst,
1638
+ link: dstSide
1639
+ } : void 0;
1640
+ return {
1641
+ oneSide,
1642
+ manySide
1643
+ };
1644
+ }
1527
1645
 
1528
1646
  // src/mock/OntologiesV2/index.ts
1529
1647
  var OntologiesV2_exports2 = {};
@@ -2921,8 +3039,10 @@ var FauxFoundry = class {
2921
3039
  description: "The default ontology",
2922
3040
  rid: `ri.ontology.main.ontology.${crypto__namespace.randomUUID()}`
2923
3041
  }, {
2924
- logger
3042
+ logger,
3043
+ strict
2925
3044
  } = {}) {
3045
+ this.strict = strict ?? true;
2926
3046
  this.baseUrl = baseUrl;
2927
3047
  this.#handlers = createFauxFoundryHandlers(baseUrl, this);
2928
3048
  this.createOntology(defaultOntology);
@@ -2962,7 +3082,7 @@ var FauxFoundry = class {
2962
3082
  const ontology = this.getOntology(ontologyApiNameOrRid);
2963
3083
  const dataStore = this.#dataStoresByOntologyApiName.get(ontology.apiName);
2964
3084
  if (!dataStore) {
2965
- const ret = new FauxDataStore(ontology, this.attachments);
3085
+ const ret = new FauxDataStore(ontology, this.attachments, this.strict);
2966
3086
  this.setDataStore(ontologyApiNameOrRid, ret);
2967
3087
  return ret;
2968
3088
  }