@takeshape/schema 11.72.0 → 11.74.1

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 (108) hide show
  1. package/dist/models/runtime-schema.js +1 -0
  2. package/dist/project-schema/latest.d.ts +6 -1
  3. package/dist/project-schema/v3.48.0.d.ts +6 -1
  4. package/dist/project-schema/v3.49.0.d.ts +6 -1
  5. package/dist/project-schema/v3.50.0.d.ts +6 -1
  6. package/dist/project-schema/v3.51.0.d.ts +6 -1
  7. package/dist/project-schema/v3.52.0.d.ts +6 -1
  8. package/dist/project-schema/v3.53.0.d.ts +6 -1
  9. package/dist/project-schema/v3.54.0.d.ts +6 -1
  10. package/dist/schemas/project-schema/experimental.json +20 -0
  11. package/dist/util/expressions.js +2 -2
  12. package/package.json +6 -6
  13. package/dist/__tests__/_examples.test.d.ts +0 -1
  14. package/dist/__tests__/_examples.test.js +0 -77
  15. package/dist/__tests__/agents.test.d.ts +0 -1
  16. package/dist/__tests__/agents.test.js +0 -163
  17. package/dist/__tests__/api-version.test.d.ts +0 -1
  18. package/dist/__tests__/api-version.test.js +0 -24
  19. package/dist/__tests__/builtin-schema.test.d.ts +0 -1
  20. package/dist/__tests__/builtin-schema.test.js +0 -18
  21. package/dist/__tests__/content-schema-transform.test.d.ts +0 -1
  22. package/dist/__tests__/content-schema-transform.test.js +0 -522
  23. package/dist/__tests__/create-input-schema.test.d.ts +0 -1
  24. package/dist/__tests__/create-input-schema.test.js +0 -184
  25. package/dist/__tests__/enum.test.d.ts +0 -1
  26. package/dist/__tests__/enum.test.js +0 -36
  27. package/dist/__tests__/flatten-templates.test.d.ts +0 -1
  28. package/dist/__tests__/flatten-templates.test.js +0 -40
  29. package/dist/__tests__/get-is-leaf.test.d.ts +0 -1
  30. package/dist/__tests__/get-is-leaf.test.js +0 -50
  31. package/dist/__tests__/interfaces.test.d.ts +0 -1
  32. package/dist/__tests__/interfaces.test.js +0 -219
  33. package/dist/__tests__/migration.test.d.ts +0 -1
  34. package/dist/__tests__/migration.test.js +0 -34
  35. package/dist/__tests__/mocks.test.d.ts +0 -1
  36. package/dist/__tests__/mocks.test.js +0 -24
  37. package/dist/__tests__/refs.test.d.ts +0 -1
  38. package/dist/__tests__/refs.test.js +0 -813
  39. package/dist/__tests__/relationships.test.d.ts +0 -1
  40. package/dist/__tests__/relationships.test.js +0 -638
  41. package/dist/__tests__/schema-transform.test.d.ts +0 -1
  42. package/dist/__tests__/schema-transform.test.js +0 -205
  43. package/dist/__tests__/schema-util.test.d.ts +0 -1
  44. package/dist/__tests__/schema-util.test.js +0 -1731
  45. package/dist/__tests__/service-dependencies.test.d.ts +0 -1
  46. package/dist/__tests__/service-dependencies.test.js +0 -360
  47. package/dist/__tests__/unions.test.d.ts +0 -1
  48. package/dist/__tests__/unions.test.js +0 -44
  49. package/dist/__tests__/validate.test.d.ts +0 -1
  50. package/dist/__tests__/validate.test.js +0 -1980
  51. package/dist/__tests__/workflows.test.d.ts +0 -3
  52. package/dist/__tests__/workflows.test.js +0 -149
  53. package/dist/layers/__tests__/layers.test.d.ts +0 -1
  54. package/dist/layers/__tests__/layers.test.js +0 -38
  55. package/dist/migration/to/__tests__/v3.10.0.test.d.ts +0 -1
  56. package/dist/migration/to/__tests__/v3.10.0.test.js +0 -90
  57. package/dist/migration/to/__tests__/v3.12.3.test.d.ts +0 -1
  58. package/dist/migration/to/__tests__/v3.12.3.test.js +0 -103
  59. package/dist/migration/to/__tests__/v3.17.test.d.ts +0 -1
  60. package/dist/migration/to/__tests__/v3.17.test.js +0 -71
  61. package/dist/migration/to/__tests__/v3.34.0.test.d.ts +0 -1
  62. package/dist/migration/to/__tests__/v3.34.0.test.js +0 -240
  63. package/dist/migration/to/__tests__/v3.39.0.test.d.ts +0 -1
  64. package/dist/migration/to/__tests__/v3.39.0.test.js +0 -116
  65. package/dist/migration/to/__tests__/v3.46.0.test.d.ts +0 -1
  66. package/dist/migration/to/__tests__/v3.46.0.test.js +0 -59
  67. package/dist/models/__tests__/fixtures.d.ts +0 -15
  68. package/dist/models/__tests__/fixtures.js +0 -56
  69. package/dist/models/__tests__/query.test.d.ts +0 -1
  70. package/dist/models/__tests__/query.test.js +0 -19
  71. package/dist/models/__tests__/runtime-schema.test.d.ts +0 -1
  72. package/dist/models/__tests__/runtime-schema.test.js +0 -43
  73. package/dist/models/__tests__/shape.test.d.ts +0 -1
  74. package/dist/models/__tests__/shape.test.js +0 -24
  75. package/dist/resolvers/ai/__tests__/rag-query.test.d.ts +0 -1
  76. package/dist/resolvers/ai/__tests__/rag-query.test.js +0 -49
  77. package/dist/services/__tests__/services.test.d.ts +0 -1
  78. package/dist/services/__tests__/services.test.js +0 -113
  79. package/dist/template-shapes/__tests__/index.test.d.ts +0 -1
  80. package/dist/template-shapes/__tests__/index.test.js +0 -40
  81. package/dist/template-shapes/__tests__/names.test.d.ts +0 -1
  82. package/dist/template-shapes/__tests__/names.test.js +0 -19
  83. package/dist/template-shapes/__tests__/templates.test.d.ts +0 -1
  84. package/dist/template-shapes/__tests__/templates.test.js +0 -80
  85. package/dist/template-shapes/__tests__/where.test.d.ts +0 -1
  86. package/dist/template-shapes/__tests__/where.test.js +0 -218
  87. package/dist/types/__tests__/utils.test.d.ts +0 -1
  88. package/dist/types/__tests__/utils.test.js +0 -159
  89. package/dist/util/__tests__/api-indexing.test.d.ts +0 -1
  90. package/dist/util/__tests__/api-indexing.test.js +0 -129
  91. package/dist/util/__tests__/detect-cycles.test.d.ts +0 -1
  92. package/dist/util/__tests__/detect-cycles.test.js +0 -193
  93. package/dist/util/__tests__/expressions.test.d.ts +0 -1
  94. package/dist/util/__tests__/expressions.test.js +0 -172
  95. package/dist/util/__tests__/find-shape-at-path.test.d.ts +0 -1
  96. package/dist/util/__tests__/find-shape-at-path.test.js +0 -41
  97. package/dist/util/__tests__/form-config.test.d.ts +0 -1
  98. package/dist/util/__tests__/form-config.test.js +0 -196
  99. package/dist/util/__tests__/get-return-shape.test.d.ts +0 -1
  100. package/dist/util/__tests__/get-return-shape.test.js +0 -27
  101. package/dist/util/__tests__/has-args.test.d.ts +0 -1
  102. package/dist/util/__tests__/has-args.test.js +0 -46
  103. package/dist/util/__tests__/merge.test.d.ts +0 -1
  104. package/dist/util/__tests__/merge.test.js +0 -1074
  105. package/dist/util/__tests__/patch-schema.test.d.ts +0 -1
  106. package/dist/util/__tests__/patch-schema.test.js +0 -82
  107. package/dist/util/__tests__/shapes.test.d.ts +0 -1
  108. package/dist/util/__tests__/shapes.test.js +0 -30
@@ -1,113 +0,0 @@
1
- import { beforeEach, describe, expect, it, test, vi } from 'vitest';
2
- import { createMockSchema, createMockServiceConfig } from "../../mocks.js";
3
- import { prepareServiceUpdate } from "../services.js";
4
- import { getResolverServices, isMissingAuth } from "../util.js";
5
- beforeEach(vi.clearAllMocks);
6
- describe('prepareServiceUpdate', () => {
7
- const serviceKey = 'mock-service';
8
- const encryptedAuthentication = 'encrypted-token';
9
- const serviceConfig = createMockServiceConfig(serviceKey);
10
- const storedServiceConfig = {
11
- ...serviceConfig,
12
- authentication: encryptedAuthentication
13
- };
14
- const { authentication } = serviceConfig;
15
- const projectSchema = createMockSchema('mock-schema', {
16
- services: {
17
- [serviceKey]: storedServiceConfig
18
- }
19
- });
20
- const encryptFn = vi.fn(() => encryptedAuthentication);
21
- const decryptFn = vi.fn(() => authentication);
22
- it('prepares an update', async () => {
23
- const serviceUpdate = {
24
- title: 'foo',
25
- authenticationType: 'bearer',
26
- authentication: {
27
- token: 'updated'
28
- }
29
- };
30
- const result = prepareServiceUpdate(encryptFn, decryptFn, projectSchema, serviceUpdate, serviceKey);
31
- expect(encryptFn).toHaveBeenCalledWith({
32
- ...authentication,
33
- token: 'updated'
34
- });
35
- expect(result).toEqual({ ...storedServiceConfig, title: 'foo' });
36
- });
37
- it('can proceed with a full object, and nothing stored', async () => {
38
- const result = prepareServiceUpdate(encryptFn, decryptFn, projectSchema, serviceConfig, 'random');
39
- expect(encryptFn).toHaveBeenCalledWith(authentication);
40
- expect(result).toEqual(storedServiceConfig);
41
- });
42
- it('clears the authentication property when a null sentinel is sent', async () => {
43
- const serviceUpdate = {
44
- authenticationType: 'bearer',
45
- authentication: null
46
- };
47
- const result = prepareServiceUpdate(encryptFn, decryptFn, projectSchema, serviceUpdate, serviceKey);
48
- expect(encryptFn).toHaveBeenCalledTimes(0);
49
- expect(result).toEqual({
50
- ...storedServiceConfig,
51
- authentication: undefined
52
- });
53
- });
54
- it('throws a validation error on invalid authentication properties', async () => {
55
- const serviceUpdate = {
56
- title: 'foo',
57
- authenticationType: 'bearer',
58
- authentication: {
59
- bogus: 'bogus-property'
60
- }
61
- };
62
- expect(() => prepareServiceUpdate(encryptFn, decryptFn, projectSchema, serviceUpdate, serviceKey)).toThrowErrorMatchingInlineSnapshot('[SchemaValidationError: ServiceConfig was invalid]');
63
- });
64
- it('throws a validation error when the envelopes authenticationType changes', async () => {
65
- const serviceUpdate = {
66
- title: 'foo',
67
- authenticationType: 'basic'
68
- };
69
- expect(() => prepareServiceUpdate(encryptFn, decryptFn, projectSchema, serviceUpdate, serviceKey)).toThrowErrorMatchingInlineSnapshot('[SchemaValidationError: ServiceConfig was invalid]');
70
- });
71
- });
72
- describe('getResolverServices', () => {
73
- test('works for basic resolvers', () => {
74
- expect(getResolverServices({
75
- name: 'graphql:query',
76
- service: 'foo',
77
- fieldName: 'foo'
78
- })).toEqual(['foo']);
79
- });
80
- test('works for compose resolvers', () => {
81
- expect(getResolverServices({
82
- compose: [
83
- {
84
- name: 'graphql:query',
85
- service: 'a',
86
- fieldName: 'a'
87
- },
88
- {
89
- name: 'graphql:query',
90
- service: 'b',
91
- fieldName: 'b'
92
- },
93
- {
94
- name: 'graphql:query',
95
- service: 'c',
96
- fieldName: 'c'
97
- },
98
- {
99
- name: 'graphql:query',
100
- service: 'a',
101
- fieldName: 'a'
102
- }
103
- ]
104
- })).toEqual(['a', 'b', 'c']);
105
- });
106
- });
107
- test('isMissingAuth', () => {
108
- expect(isMissingAuth({ authenticationType: 'none' })).toBe(false);
109
- expect(isMissingAuth({ authenticationType: 'basic' })).toBe(true);
110
- expect(
111
- // @ts-expect-error for the sake of testing js runtime usage
112
- isMissingAuth({ authenticationType: 'oauth2Bearer', authentication: {} })).toBe(true);
113
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,40 +0,0 @@
1
- import { describe, expect, test } from 'vitest';
2
- import blogSchema from '@/examples/latest/blog-schema.json';
3
- import { isValidTemplate, resolveTemplate } from "../index.js";
4
- describe('resolveTemplate', () => {
5
- test('success', () => {
6
- expect(resolveTemplate(blogSchema, 'TSGetArgs', 'Post')).toEqual({
7
- dependencies: {
8
- PostTSGetArgs: {
9
- id: 'PostTSGetArgs',
10
- name: 'PostTSGetArgs',
11
- schema: {
12
- properties: {
13
- _id: { type: 'string' },
14
- enableLocaleFallback: { default: true, type: 'boolean' },
15
- locale: { type: 'string' }
16
- },
17
- required: ['_id'],
18
- type: 'object'
19
- },
20
- title: 'PostTSGetArgs'
21
- }
22
- },
23
- shapeName: 'PostTSGetArgs'
24
- });
25
- });
26
- test('invalid template', () => {
27
- expect(() => resolveTemplate(blogSchema, 'TSGetRekt', 'Post')).toThrowError('Invalid shape template TSGetRekt');
28
- });
29
- test('invalid shape', () => {
30
- expect(() => resolveTemplate(blogSchema, 'TSGetArgs', 'Nerd')).toThrowError('Unknown shape "Nerd" in template "TSGetArgs"');
31
- });
32
- });
33
- describe('isValidTemplate', () => {
34
- test('yes', () => {
35
- expect(isValidTemplate('TSGetArgs')).toEqual(true);
36
- });
37
- test('no', () => {
38
- expect(isValidTemplate('TSGetBreakfast')).toEqual(false);
39
- });
40
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { getOutputShapeName } from "../names.js";
3
- describe('getOutputShapeName', () => {
4
- it('should remove "Input" suffix from the name', () => {
5
- expect(getOutputShapeName('UserInput')).toBe('User');
6
- });
7
- it('should remove "PartialInput" suffix from the name', () => {
8
- expect(getOutputShapeName('UserPartialInput')).toBe('User');
9
- });
10
- it('should not change the name if it does not have "Input" or "PartialInput" suffix', () => {
11
- expect(getOutputShapeName('User')).toBe('User');
12
- });
13
- it('should not change the name if it has "Input" or "PartialInput" in the middle', () => {
14
- expect(getOutputShapeName('InputUserPartial')).toBe('InputUserPartial');
15
- });
16
- it('should handle empty string', () => {
17
- expect(getOutputShapeName('')).toBe('');
18
- });
19
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,80 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { createMockSchema } from "../../mocks.js";
3
- import { CreateArgs, DeleteArgs, DuplicateArgs, UpdateArgs } from "../templates.js";
4
- describe('getMutationArgs', () => {
5
- const Mock = {
6
- title: 'Mock',
7
- name: 'Mock',
8
- id: 'Mock',
9
- schema: {
10
- type: 'object',
11
- properties: {
12
- title: {
13
- type: 'string',
14
- '@input': {
15
- type: 'number'
16
- }
17
- }
18
- }
19
- }
20
- };
21
- const projectSchema = createMockSchema('<project-id>', {
22
- shapes: { Mock }
23
- });
24
- it('should substitute @input for the original field schema', () => {
25
- const createResult = CreateArgs({ projectSchema }, Mock);
26
- expect(createResult.dependencies.CreateMockInput.schema).toEqual({
27
- type: 'object',
28
- properties: {
29
- title: {
30
- '@output': {
31
- type: 'string'
32
- },
33
- type: 'number'
34
- }
35
- }
36
- });
37
- const updateResult = UpdateArgs({ projectSchema }, Mock);
38
- expect(updateResult.dependencies.UpdateMockInput.schema).toEqual({
39
- type: 'object',
40
- properties: {
41
- _id: {
42
- type: 'string'
43
- },
44
- title: {
45
- '@output': {
46
- type: 'string'
47
- },
48
- type: 'number'
49
- }
50
- },
51
- required: ['_id']
52
- });
53
- const duplicateResult = DuplicateArgs({ projectSchema }, Mock);
54
- expect(duplicateResult.dependencies.DuplicateMockInput.schema).toEqual({
55
- type: 'object',
56
- properties: {
57
- _id: {
58
- type: 'string'
59
- },
60
- title: {
61
- '@output': {
62
- type: 'string'
63
- },
64
- type: 'number'
65
- }
66
- },
67
- required: ['_id']
68
- });
69
- const deleteResult = DeleteArgs({ projectSchema }, Mock);
70
- expect(deleteResult.dependencies.DeleteMockInput.schema).toEqual({
71
- type: 'object',
72
- properties: {
73
- _id: {
74
- type: 'string'
75
- }
76
- },
77
- required: ['_id']
78
- });
79
- });
80
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,218 +0,0 @@
1
- import { DEFAULT_ENTITLEMENTS } from '@takeshape/util';
2
- import { expect, test } from 'vitest';
3
- import massiveSchemaJson from '@/examples/latest/massive-schema.json';
4
- import millSchemaJson from '@/examples/latest/mill-components-schema.json';
5
- import { createMockSchema } from "../../mocks.js";
6
- import { isEqualRelationship } from "../../relationships.js";
7
- import { applyDefaultsToSchema } from "../../schema-util.js";
8
- import { isModelShape } from "../../types/index.js";
9
- import { validateSchema } from "../../validate/validate.js";
10
- import { getWhereShape } from "../where.js";
11
- const massiveSchema = applyDefaultsToSchema(massiveSchemaJson);
12
- const millSchema = applyDefaultsToSchema(millSchemaJson);
13
- async function validateShapes(shapes) {
14
- return (await validateSchema({
15
- entitlements: DEFAULT_ENTITLEMENTS
16
- }, createMockSchema('project-id', { shapes }))).errors;
17
- }
18
- test('getWhereShape - massive', async () => {
19
- const { shapeName, dependencies } = getWhereShape(massiveSchema, Object.values(massiveSchema.shapes).filter(isModelShape));
20
- expect(await validateShapes(dependencies)).toEqual(undefined);
21
- expect(shapeName).toBe('TSWhereInput');
22
- expect(dependencies).toMatchSnapshot();
23
- });
24
- test('getWhereShape - mill', async () => {
25
- const { shapeName, dependencies } = getWhereShape(millSchema, Object.values(millSchema.shapes).filter(isModelShape));
26
- expect(await validateShapes(dependencies)).toEqual(undefined);
27
- expect(shapeName).toBe('TSWhereInput');
28
- expect(dependencies).toMatchSnapshot();
29
- });
30
- test('getWhereShape - recursive', async () => {
31
- const schema = createMockSchema('project-id', {
32
- shapes: {
33
- Node: {
34
- name: 'Node',
35
- title: 'Node',
36
- id: 'node-id',
37
- schema: {
38
- type: 'object',
39
- properties: {
40
- foreign: { '@ref': 'stripe:Customer' },
41
- left: { '@ref': 'local:Node' },
42
- right: { '@ref': 'local:Node' },
43
- value: { type: 'number' }
44
- }
45
- }
46
- },
47
- Stripe_Customer: {
48
- name: 'Stripe_Customer',
49
- title: 'Stripe_Customer',
50
- id: 'Stripe_Customer',
51
- schema: {
52
- type: 'object',
53
- properties: {}
54
- }
55
- }
56
- },
57
- services: {
58
- stripe: {
59
- id: 'stripe',
60
- title: 'Stripe',
61
- namespace: 'Stripe',
62
- provider: 'openapi',
63
- serviceType: 'openapi',
64
- authenticationType: 'none'
65
- }
66
- }
67
- });
68
- const { shapeName, dependencies } = getWhereShape(schema, [schema.shapes.Node]);
69
- expect(await validateShapes(dependencies)).toEqual(undefined);
70
- expect(shapeName).toBe('TSWhereNodeInput');
71
- expect(dependencies).toMatchInlineSnapshot(`
72
- {
73
- "TSWhereNode": {
74
- "id": "TSWhereNode",
75
- "name": "TSWhereNode",
76
- "schema": {
77
- "properties": {
78
- "left": {
79
- "@ref": "local:TSWhereNode",
80
- },
81
- "right": {
82
- "@ref": "local:TSWhereNode",
83
- },
84
- "value": {
85
- "@ref": "local:TSWhereNumber",
86
- },
87
- },
88
- "type": "object",
89
- },
90
- "title": "TSWhereNode",
91
- },
92
- "TSWhereNodeInput": {
93
- "id": "TSWhereNodeInput",
94
- "name": "TSWhereNodeInput",
95
- "schema": {
96
- "properties": {
97
- "AND": {
98
- "items": {
99
- "@ref": "local:TSWhereNodeInput",
100
- },
101
- "type": "array",
102
- },
103
- "NOT": {
104
- "@ref": "local:TSWhereNodeInput",
105
- },
106
- "OR": {
107
- "items": {
108
- "@ref": "local:TSWhereNodeInput",
109
- },
110
- "type": "array",
111
- },
112
- "left": {
113
- "@ref": "local:TSWhereNode",
114
- },
115
- "right": {
116
- "@ref": "local:TSWhereNode",
117
- },
118
- "value": {
119
- "@ref": "local:TSWhereNumber",
120
- },
121
- },
122
- "type": "object",
123
- },
124
- "title": "TSWhereNodeInput",
125
- },
126
- "TSWhereNumber": {
127
- "id": "TSWhereNumber",
128
- "name": "TSWhereNumber",
129
- "schema": {
130
- "properties": {
131
- "eq": {
132
- "description": "Exact match",
133
- "type": "number",
134
- },
135
- "gt": {
136
- "description": "Greater than",
137
- "type": "number",
138
- },
139
- "gte": {
140
- "description": "Greater than or equal",
141
- "type": "number",
142
- },
143
- "in": {
144
- "description": "Array of possible exact match values.",
145
- "items": {
146
- "type": "number",
147
- },
148
- "type": "array",
149
- },
150
- "lt": {
151
- "description": "Less than",
152
- "type": "number",
153
- },
154
- "lte": {
155
- "description": "Less than or equal",
156
- "type": "number",
157
- },
158
- },
159
- "type": "object",
160
- },
161
- "title": "TSWhereNumber",
162
- },
163
- }
164
- `);
165
- });
166
- test('isEqualRelationship - non-relationship', () => {
167
- expect(isEqualRelationship({ type: 'string' }, { type: 'number' })).toBe(true);
168
- });
169
- test('isEqualRelationship - relationship to non-relationship', () => {
170
- const a = {
171
- '@resolver': {
172
- name: 'shapedb:getRelated',
173
- service: 'shapedb'
174
- },
175
- oneOf: [{ '@ref': 'local:A' }, { '@ref': 'local:B' }, { '@ref': 'local:C' }]
176
- };
177
- const b = {
178
- type: 'string'
179
- };
180
- expect(isEqualRelationship(a, b)).toBe(false);
181
- expect(isEqualRelationship(b, a)).toBe(false);
182
- });
183
- test('isEqualRelationship - relationships', () => {
184
- const a = {
185
- '@resolver': {
186
- name: 'shapedb:getRelated',
187
- service: 'shapedb'
188
- },
189
- oneOf: [{ '@ref': 'local:A' }, { '@ref': 'local:B' }, { '@ref': 'local:C' }]
190
- };
191
- const b = {
192
- '@resolver': {
193
- name: 'shapedb:getRelated',
194
- service: 'shapedb'
195
- },
196
- oneOf: [{ '@ref': 'local:C' }, { '@ref': 'local:A' }, { '@ref': 'local:B' }]
197
- };
198
- expect(isEqualRelationship(a, b)).toBe(true);
199
- expect(isEqualRelationship(b, a)).toBe(true);
200
- });
201
- test('isEqualRelationship - relationships', () => {
202
- const a = {
203
- '@resolver': {
204
- name: 'shapedb:getRelated',
205
- service: 'shapedb'
206
- },
207
- oneOf: [{ '@ref': 'local:A' }, { '@ref': 'local:B' }, { '@ref': 'local:C' }]
208
- };
209
- const b = {
210
- '@resolver': {
211
- name: 'shapedb:getRelated',
212
- service: 'shapedb'
213
- },
214
- oneOf: [{ '@ref': 'local:C' }]
215
- };
216
- expect(isEqualRelationship(a, b)).toBe(false);
217
- expect(isEqualRelationship(b, a)).toBe(false);
218
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,159 +0,0 @@
1
- import { describe, expect, it, test } from 'vitest';
2
- import { isAwsLambdaResolver, isBasicResolver, isComposeResolver, isGraphQLServiceConfig, isGraphqlResolver, isParameterOp, isParameterOpMapping, isParameterOpNested, isParameterOpOp, isParameterOpValue, isRestResolver, isReturnShapeArraySchema, isShapedbResolver, isTakeshapeResolver, isUtilResolver } from "../utils.js";
3
- test('isGenericGraphQLServiceConfig', () => {
4
- expect(isGraphQLServiceConfig({})).toBe(false);
5
- const restServiceConfig = {
6
- provider: 'rest',
7
- id: 'service-id',
8
- title: 'REST Service',
9
- serviceType: 'rest',
10
- authenticationType: 'none',
11
- options: {
12
- endpoint: 'https://api.example.com/graphql'
13
- }
14
- };
15
- expect(isGraphQLServiceConfig(restServiceConfig)).toBe(false);
16
- const genericServiceConfig = {
17
- provider: 'rest',
18
- id: 'service-id',
19
- title: 'REST Service',
20
- serviceType: 'rest',
21
- authenticationType: 'none'
22
- };
23
- expect(isGraphQLServiceConfig(genericServiceConfig)).toBe(false);
24
- const graphqlServiceConfig = {
25
- provider: 'graphql',
26
- id: 'service-id',
27
- title: 'GraphQL Service',
28
- serviceType: 'graphql',
29
- authenticationType: 'none',
30
- options: {
31
- endpoint: 'https://api.example.com/graphql'
32
- }
33
- };
34
- expect(isGraphQLServiceConfig(graphqlServiceConfig)).toBe(true);
35
- });
36
- test('isParameterOp type guards', () => {
37
- expect(isParameterOp({ path: 'foo', op: 'set' })).toBe(true);
38
- expect(isParameterOp({ path: 'foo', mapping: 'foo' })).toBe(true);
39
- expect(isParameterOpNested({ path: 'foo', ops: [] })).toBe(true);
40
- expect(isParameterOpMapping({ path: 'foo', mapping: 'foo' })).toBe(true);
41
- expect(isParameterOpValue({ path: 'foo', value: 'foo' })).toBe(true);
42
- expect(isParameterOpOp({ path: 'foo', op: 'set' })).toBe(true);
43
- expect(isParameterOpOp({ path: 'foo', op: 'set', value: 'foo' })).toBe(false);
44
- });
45
- describe('resolver type utils', () => {
46
- it('should validate a valid basic resolver', () => {
47
- const resolverConfig = {
48
- name: 'shapedb:create',
49
- service: 'foo'
50
- };
51
- expect(isBasicResolver(resolverConfig)).toBe(true);
52
- });
53
- it('should reject an incomplete basic resolver', () => {
54
- expect(isBasicResolver({
55
- service: 'foo'
56
- })).toBe(false);
57
- });
58
- it('should validate a valid compose resolver', () => {
59
- const resolverConfig = {
60
- compose: [
61
- {
62
- name: 'shapedb:create',
63
- service: 'foo'
64
- }
65
- ]
66
- };
67
- expect(isComposeResolver(resolverConfig)).toBe(true);
68
- });
69
- it('should reject an incomplete compose resolver', () => {
70
- expect(isComposeResolver({
71
- compose: [
72
- {
73
- name: 'shapedb:create'
74
- },
75
- {}
76
- ]
77
- })).toBe(false);
78
- expect(isComposeResolver({
79
- compose: []
80
- })).toBe(false);
81
- });
82
- it('should validate a valid takeshape resolver name', () => {
83
- const resolverConfig = {
84
- name: 'takeshape:getUser'
85
- };
86
- expect(isTakeshapeResolver(resolverConfig)).toBe(true);
87
- });
88
- it('should validate a valid shapedb resolver name', () => {
89
- const resolverConfig = {
90
- name: 'shapedb:create'
91
- };
92
- expect(isShapedbResolver(resolverConfig)).toBe(true);
93
- });
94
- it('should reject an invalid takeshape resolver name', () => {
95
- const resolverConfig = {
96
- name: 'shapedb:wrong'
97
- };
98
- expect(isTakeshapeResolver(resolverConfig)).toBe(false);
99
- });
100
- it('should validate a valid rest resolver name', () => {
101
- const resolverConfig = {
102
- name: 'rest:post'
103
- };
104
- expect(isRestResolver(resolverConfig)).toBe(true);
105
- });
106
- it('should reject an invalid rest resolver name', () => {
107
- const resolverConfig = {
108
- name: 'rest:wrong'
109
- };
110
- expect(isRestResolver(resolverConfig)).toBe(false);
111
- });
112
- it('should validate a valid graphql resolver name', () => {
113
- const resolverConfig = {
114
- name: 'graphql:query'
115
- };
116
- expect(isGraphqlResolver(resolverConfig)).toBe(true);
117
- });
118
- it('should reject an invalid graphql resolver name', () => {
119
- const resolverConfig = {
120
- name: 'graphql:wrong'
121
- };
122
- expect(isGraphqlResolver(resolverConfig)).toBe(false);
123
- });
124
- it('should validate a valid aws lambda resolver name', () => {
125
- const resolverConfig = {
126
- name: 'awsLambda:invoke'
127
- };
128
- expect(isAwsLambdaResolver(resolverConfig)).toBe(true);
129
- });
130
- it('should reject an invalid aws lambda resolver name', () => {
131
- const resolverConfig = {
132
- name: 'awsLambda:wrong'
133
- };
134
- expect(isAwsLambdaResolver(resolverConfig)).toBe(false);
135
- });
136
- it('should validate a valid util resolver name', () => {
137
- const resolverConfig = {
138
- name: 'util:wrap'
139
- };
140
- expect(isUtilResolver(resolverConfig)).toBe(true);
141
- });
142
- it('should reject an invalid util resolver name', () => {
143
- const resolverConfig = {
144
- name: 'util:wrong'
145
- };
146
- expect(isUtilResolver(resolverConfig)).toBe(false);
147
- });
148
- });
149
- describe('isReturnShapeArraySchema', () => {
150
- test('no', () => {
151
- expect(isReturnShapeArraySchema('Product')).toEqual(false);
152
- });
153
- test('yes', () => {
154
- expect(isReturnShapeArraySchema({
155
- type: 'array',
156
- items: { '@ref': 'shopify:Product' }
157
- })).toEqual(true);
158
- });
159
- });
@@ -1 +0,0 @@
1
- export {};