@jskit-ai/http-runtime 0.1.82 → 0.1.84

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,7 +1,7 @@
1
1
  export default Object.freeze({
2
2
  "packageVersion": 1,
3
3
  "packageId": "@jskit-ai/http-runtime",
4
- "version": "0.1.82",
4
+ "version": "0.1.84",
5
5
  "kind": "runtime",
6
6
  "dependsOn": [],
7
7
  "capabilities": {
@@ -67,7 +67,7 @@ export default Object.freeze({
67
67
  "mutations": {
68
68
  "dependencies": {
69
69
  "runtime": {
70
- "@jskit-ai/kernel": "0.1.83"
70
+ "@jskit-ai/kernel": "0.1.85"
71
71
  },
72
72
  "dev": {}
73
73
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/http-runtime",
3
- "version": "0.1.82",
3
+ "version": "0.1.84",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test"
@@ -18,7 +18,7 @@
18
18
  "./shared/validators/operationValidation": "./src/shared/validators/operationValidation.js"
19
19
  },
20
20
  "dependencies": {
21
- "@jskit-ai/kernel": "0.1.83",
21
+ "@jskit-ai/kernel": "0.1.85",
22
22
  "json-rest-schema": "1.x.x"
23
23
  }
24
24
  }
@@ -247,6 +247,7 @@ function normalizeRelationshipSchemaEntries(entries = []) {
247
247
  relationshipName,
248
248
  relationshipType,
249
249
  attributeKey,
250
+ many: source.many === true,
250
251
  required: source.required === true,
251
252
  nullable: source.nullable === true
252
253
  }));
@@ -256,6 +257,7 @@ function normalizeRelationshipSchemaEntries(entries = []) {
256
257
  }
257
258
 
258
259
  function createJsonApiRelationshipDataSchema(relationshipType = "", {
260
+ many = false,
259
261
  nullable = false
260
262
  } = {}) {
261
263
  const normalizedRelationshipType = normalizeText(relationshipType);
@@ -270,14 +272,20 @@ function createJsonApiRelationshipDataSchema(relationshipType = "", {
270
272
  }
271
273
  }
272
274
  : JSON_API_RESOURCE_IDENTIFIER_SCHEMA;
275
+ const linkageSchema = many
276
+ ? {
277
+ type: "array",
278
+ items: resourceIdentifierSchema
279
+ }
280
+ : resourceIdentifierSchema;
273
281
 
274
282
  return {
275
283
  anyOf: nullable
276
284
  ? [
277
- resourceIdentifierSchema,
285
+ linkageSchema,
278
286
  { type: "null" }
279
287
  ]
280
- : [resourceIdentifierSchema]
288
+ : [linkageSchema]
281
289
  };
282
290
  }
283
291
 
@@ -299,6 +307,7 @@ function createJsonApiRelationshipsTransportSchema(entries = [], {
299
307
  required: ["data"],
300
308
  properties: {
301
309
  data: createJsonApiRelationshipDataSchema(entry.relationshipType, {
310
+ many: entry.many,
302
311
  nullable: entry.nullable
303
312
  })
304
313
  }
@@ -372,6 +372,50 @@ test("createJsonApiResourceRouteContract models explicit relationship-backed out
372
372
  assert.ok(Object.hasOwn(contract.responses["200"].transportSchema.properties, "included"));
373
373
  });
374
374
 
375
+ test("createJsonApiResourceRouteContract models to-many relationship output fields", () => {
376
+ const contract = createJsonApiResourceRouteContract({
377
+ responseType: "contacts",
378
+ output: {
379
+ schema: createSchema({
380
+ id: {
381
+ type: "string",
382
+ required: true,
383
+ minLength: 1
384
+ },
385
+ name: {
386
+ type: "string",
387
+ required: true,
388
+ minLength: 1
389
+ },
390
+ pets: {
391
+ type: "array",
392
+ required: false
393
+ }
394
+ }),
395
+ mode: "replace"
396
+ },
397
+ outputKind: "record",
398
+ outputRelationshipEntries: [
399
+ {
400
+ attributeKey: "pets",
401
+ relationshipName: "pets",
402
+ relationshipType: "pets",
403
+ many: true
404
+ }
405
+ ]
406
+ });
407
+
408
+ const resourceSchema = contract.responses["200"].transportSchema.definitions.contactsSuccessResource;
409
+ const attributesSchemaRef = resourceSchema.properties.attributes.allOf[0].$ref;
410
+ const attributesSchemaName = attributesSchemaRef.replace("#/definitions/", "");
411
+ const attributesSchema = contract.responses["200"].transportSchema.definitions[attributesSchemaName];
412
+ const relationshipDataSchema = resourceSchema.properties.relationships.properties.pets.properties.data;
413
+
414
+ assert.equal(Object.hasOwn(attributesSchema.properties, "pets"), false);
415
+ assert.equal(relationshipDataSchema.anyOf[0].type, "array");
416
+ assert.equal(relationshipDataSchema.anyOf[0].items.properties.type.const, "pets");
417
+ });
418
+
375
419
  test("createJsonApiResourceRouteTransport wraps tagged meta results for meta routes", () => {
376
420
  const contract = createJsonApiResourceRouteContract({
377
421
  requestType: "password-changes",