@jskit-ai/http-runtime 0.1.243 → 0.1.244

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.
Files changed (35) hide show
  1. package/package.json +6 -35
  2. package/src/client/index.js +2 -3
  3. package/src/shared/clientRuntime/client.js +1 -57
  4. package/src/shared/clientRuntime/errors.js +39 -2
  5. package/src/shared/clientRuntime/jsonApiResourceTransport.js +27 -39
  6. package/src/shared/index.js +2 -21
  7. package/src/shared/validators/errorResponses.js +1 -13
  8. package/src/shared/validators/jsonApiQueryTransport.js +1 -5
  9. package/src/shared/validators/jsonApiRouteTransport.js +43 -54
  10. package/src/shared/validators/jsonApiTransport.js +1 -5
  11. package/src/shared/validators/operationValidation.js +5 -92
  12. package/test/client.test.js +29 -0
  13. package/test/entrypoints.boundary.test.js +15 -14
  14. package/test/errorResponses.test.js +0 -11
  15. package/test/jsonApiRouteTransport.test.js +12 -7
  16. package/test/operationValidation.test.js +13 -61
  17. package/test/transientRetryHttpClient.test.js +11 -0
  18. package/test/validationErrors.test.js +20 -9
  19. package/src/client/providers/HttpClientRuntimeClientProvider.js +0 -20
  20. package/src/client/providers/HttpValidatorsClientProvider.js +0 -16
  21. package/src/server/providers/HttpClientProvider.js +0 -16
  22. package/src/server/providers/HttpValidatorsProvider.js +0 -16
  23. package/src/shared/clientRuntime/index.js +0 -4
  24. package/src/shared/validators/command.js +0 -24
  25. package/src/shared/validators/httpValidatorsApi.js +0 -129
  26. package/src/shared/validators/jsonApiResponses.js +0 -3
  27. package/src/shared/validators/operationMessages.js +0 -318
  28. package/src/shared/validators/paginationQuery.js +0 -27
  29. package/src/shared/validators/resource.js +0 -41
  30. package/test/command.test.js +0 -66
  31. package/test/operationMessages.test.js +0 -197
  32. package/test/paginationQuery.test.js +0 -28
  33. package/test/providerRuntime.httpClient.test.js +0 -22
  34. package/test/providerRuntime.validators.test.js +0 -22
  35. package/test/resource.test.js +0 -128
@@ -1,22 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
-
4
- import { createCapabilityRuntime, defineProvider } from "@jskit-ai/kernel/shared/capabilities";
5
- import { HttpValidatorsProvider } from "../src/server/providers/HttpValidatorsProvider.js";
6
-
7
- test("HttpValidatorsProvider provides the shared validator API", async () => {
8
- let validators;
9
- const consumer = defineProvider({
10
- id: "test.http-validators.consumer",
11
- requires: { value: "validators.http" },
12
- setup({ value }) {
13
- validators = value;
14
- return {};
15
- }
16
- });
17
- const runtime = createCapabilityRuntime({ providers: [HttpValidatorsProvider, consumer] });
18
- await runtime.start();
19
- assert.equal(typeof validators.enumSchema, "function");
20
- assert.equal(typeof validators.createResource, "function");
21
- await runtime.shutdown();
22
- });
@@ -1,128 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { createSchema } from "json-rest-schema";
4
- import {
5
- createCursorPagedListResponseSchema,
6
- createResource
7
- } from "../src/shared/validators/resource.js";
8
-
9
- test("createCursorPagedListResponseSchema builds items + nextCursor schema", () => {
10
- const itemSchema = {
11
- schema: createSchema({
12
- id: { type: "integer", required: true, min: 1 }
13
- })
14
- };
15
- const listSchema = createCursorPagedListResponseSchema(itemSchema);
16
- const transportSchema = listSchema.schema.toJsonSchema({ mode: listSchema.mode });
17
-
18
- assert.equal(listSchema.mode, "replace");
19
- assert.equal(transportSchema.type, "object");
20
- assert.equal(transportSchema.additionalProperties, false);
21
- assert.equal(transportSchema.properties.items.type, "array");
22
- assert.equal(transportSchema.properties.nextCursor.anyOf.length, 2);
23
- });
24
-
25
- test("createResource requires record/create/replace/patch schemas", () => {
26
- assert.throws(
27
- () => createResource({}),
28
- /record is required/
29
- );
30
-
31
- assert.throws(
32
- () =>
33
- createResource({
34
- record: createSchema({}),
35
- create: { schema: createSchema({}) },
36
- replace: { schema: createSchema({}) },
37
- patch: { schema: createSchema({}) }
38
- }),
39
- /record must be a schema definition object/
40
- );
41
- });
42
-
43
- test("createResource builds default list schema from record/listItem", () => {
44
- const recordSchema = {
45
- schema: createSchema({
46
- id: { type: "integer", required: true, min: 1 },
47
- name: { type: "string", required: true, minLength: 1 }
48
- })
49
- };
50
- const writeSchema = {
51
- schema: createSchema({
52
- name: { type: "string", required: true, minLength: 1 },
53
- color: { type: "string", required: true, minLength: 1 }
54
- })
55
- };
56
- const patchSchema = {
57
- schema: createSchema({
58
- name: { type: "string", minLength: 1 },
59
- color: { type: "string", minLength: 1 }
60
- })
61
- };
62
- const resource = createResource({
63
- record: recordSchema,
64
- create: writeSchema,
65
- replace: writeSchema,
66
- patch: patchSchema
67
- });
68
- const listTransportSchema = resource.list.schema.toJsonSchema({ mode: resource.list.mode });
69
-
70
- assert.equal(resource.record.mode, "replace");
71
- assert.equal(resource.create.mode, "create");
72
- assert.equal(resource.patch.mode, "patch");
73
- assert.equal(resource.list.mode, "replace");
74
- assert.equal(listTransportSchema.properties.items.items["x-json-rest-schema"]?.castType, "object");
75
- assert.equal(Array.isArray(listTransportSchema.properties.items.items.allOf), true);
76
- assert.match(listTransportSchema.properties.items.items.allOf[0].$ref, /^#\/definitions\//);
77
- });
78
-
79
- test("createResource accepts explicit list schema override", () => {
80
- const recordSchema = {
81
- schema: createSchema({
82
- id: { type: "integer", required: true, min: 1 }
83
- })
84
- };
85
- const writeSchema = {
86
- schema: createSchema({
87
- id: { type: "integer", required: true, min: 1 }
88
- })
89
- };
90
- const patchSchema = {
91
- schema: createSchema({
92
- id: { type: "integer", min: 1 }
93
- })
94
- };
95
- const explicitListSchema = {
96
- schema: createSchema({
97
- rows: {
98
- type: "array",
99
- required: true,
100
- items: recordSchema.schema
101
- },
102
- meta: {
103
- type: "object",
104
- required: true,
105
- schema: createSchema({
106
- page: { type: "integer", required: true, min: 1 },
107
- pageSize: { type: "integer", required: true, min: 1 }
108
- })
109
- }
110
- }),
111
- mode: "replace"
112
- };
113
-
114
- const resource = createResource({
115
- record: recordSchema,
116
- create: writeSchema,
117
- replace: writeSchema,
118
- patch: patchSchema,
119
- list: explicitListSchema
120
- });
121
- const listTransportSchema = resource.list.schema.toJsonSchema({ mode: resource.list.mode });
122
-
123
- assert.equal(resource.list.mode, "replace");
124
- assert.equal(listTransportSchema.properties.rows.type, "array");
125
- assert.equal(listTransportSchema.properties.meta["x-json-rest-schema"]?.castType, "object");
126
- assert.equal(Array.isArray(listTransportSchema.properties.meta.allOf), true);
127
- assert.match(listTransportSchema.properties.meta.allOf[0].$ref, /^#\/definitions\//);
128
- });