@livon/schema 0.27.0-rc.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 (169) hide show
  1. package/PROMPT.md +21 -0
  2. package/README.md +13 -0
  3. package/SCHEMA.md +13 -0
  4. package/dist/SchemaValidationError.cjs +41 -0
  5. package/dist/SchemaValidationError.d.ts +20 -0
  6. package/dist/SchemaValidationError.js +7 -0
  7. package/dist/SchemaValidationError.spec.cjs +65 -0
  8. package/dist/SchemaValidationError.spec.d.ts +1 -0
  9. package/dist/SchemaValidationError.spec.js +59 -0
  10. package/dist/after.cjs +36 -0
  11. package/dist/after.d.ts +30 -0
  12. package/dist/after.js +2 -0
  13. package/dist/after.spec.cjs +54 -0
  14. package/dist/after.spec.d.ts +1 -0
  15. package/dist/after.spec.js +48 -0
  16. package/dist/and.cjs +36 -0
  17. package/dist/and.d.ts +26 -0
  18. package/dist/and.js +2 -0
  19. package/dist/and.spec.cjs +57 -0
  20. package/dist/and.spec.d.ts +1 -0
  21. package/dist/and.spec.js +51 -0
  22. package/dist/api.cjs +317 -0
  23. package/dist/api.d.ts +107 -0
  24. package/dist/api.js +277 -0
  25. package/dist/api.spec.cjs +512 -0
  26. package/dist/api.spec.d.ts +1 -0
  27. package/dist/api.spec.js +506 -0
  28. package/dist/array.cjs +74 -0
  29. package/dist/array.d.ts +25 -0
  30. package/dist/array.js +40 -0
  31. package/dist/array.spec.cjs +167 -0
  32. package/dist/array.spec.d.ts +1 -0
  33. package/dist/array.spec.js +161 -0
  34. package/dist/before.cjs +36 -0
  35. package/dist/before.d.ts +30 -0
  36. package/dist/before.js +2 -0
  37. package/dist/before.spec.cjs +54 -0
  38. package/dist/before.spec.d.ts +1 -0
  39. package/dist/before.spec.js +48 -0
  40. package/dist/binary.cjs +53 -0
  41. package/dist/binary.d.ts +24 -0
  42. package/dist/binary.js +19 -0
  43. package/dist/binary.spec.cjs +107 -0
  44. package/dist/binary.spec.d.ts +1 -0
  45. package/dist/binary.spec.js +101 -0
  46. package/dist/boolean.cjs +53 -0
  47. package/dist/boolean.d.ts +24 -0
  48. package/dist/boolean.js +19 -0
  49. package/dist/boolean.spec.cjs +96 -0
  50. package/dist/boolean.spec.d.ts +1 -0
  51. package/dist/boolean.spec.js +90 -0
  52. package/dist/context.cjs +125 -0
  53. package/dist/context.d.ts +101 -0
  54. package/dist/context.js +76 -0
  55. package/dist/context.spec.cjs +244 -0
  56. package/dist/context.spec.d.ts +1 -0
  57. package/dist/context.spec.js +238 -0
  58. package/dist/date.cjs +53 -0
  59. package/dist/date.d.ts +24 -0
  60. package/dist/date.js +19 -0
  61. package/dist/date.spec.cjs +97 -0
  62. package/dist/date.spec.d.ts +1 -0
  63. package/dist/date.spec.js +91 -0
  64. package/dist/doc.cjs +54 -0
  65. package/dist/doc.d.ts +25 -0
  66. package/dist/doc.js +17 -0
  67. package/dist/doc.spec.cjs +99 -0
  68. package/dist/doc.spec.d.ts +1 -0
  69. package/dist/doc.spec.js +93 -0
  70. package/dist/enumeration.cjs +74 -0
  71. package/dist/enumeration.d.ts +50 -0
  72. package/dist/enumeration.js +40 -0
  73. package/dist/enumeration.spec.cjs +110 -0
  74. package/dist/enumeration.spec.d.ts +1 -0
  75. package/dist/enumeration.spec.js +104 -0
  76. package/dist/hydrate.cjs +18 -0
  77. package/dist/hydrate.d.ts +1 -0
  78. package/dist/hydrate.js +0 -0
  79. package/dist/index.cjs +145 -0
  80. package/dist/index.d.ts +34 -0
  81. package/dist/index.js +24 -0
  82. package/dist/index.spec.cjs +43 -0
  83. package/dist/index.spec.d.ts +1 -0
  84. package/dist/index.spec.js +37 -0
  85. package/dist/literal.cjs +55 -0
  86. package/dist/literal.d.ts +25 -0
  87. package/dist/literal.js +21 -0
  88. package/dist/literal.spec.cjs +93 -0
  89. package/dist/literal.spec.d.ts +1 -0
  90. package/dist/literal.spec.js +87 -0
  91. package/dist/number.cjs +89 -0
  92. package/dist/number.d.ts +84 -0
  93. package/dist/number.js +55 -0
  94. package/dist/number.spec.cjs +155 -0
  95. package/dist/number.spec.d.ts +1 -0
  96. package/dist/number.spec.js +149 -0
  97. package/dist/object.cjs +66 -0
  98. package/dist/object.d.ts +37 -0
  99. package/dist/object.js +32 -0
  100. package/dist/object.spec.cjs +171 -0
  101. package/dist/object.spec.d.ts +1 -0
  102. package/dist/object.spec.js +165 -0
  103. package/dist/operation.cjs +182 -0
  104. package/dist/operation.d.ts +197 -0
  105. package/dist/operation.js +133 -0
  106. package/dist/operation.spec.cjs +454 -0
  107. package/dist/operation.spec.d.ts +1 -0
  108. package/dist/operation.spec.js +448 -0
  109. package/dist/or.cjs +85 -0
  110. package/dist/or.d.ts +37 -0
  111. package/dist/or.js +51 -0
  112. package/dist/or.spec.cjs +204 -0
  113. package/dist/or.spec.d.ts +1 -0
  114. package/dist/or.spec.js +198 -0
  115. package/dist/schema.cjs +285 -0
  116. package/dist/schema.d.ts +132 -0
  117. package/dist/schema.js +233 -0
  118. package/dist/schema.spec.cjs +587 -0
  119. package/dist/schema.spec.d.ts +1 -0
  120. package/dist/schema.spec.js +581 -0
  121. package/dist/schemaFactory.cjs +125 -0
  122. package/dist/schemaFactory.d.ts +97 -0
  123. package/dist/schemaFactory.js +88 -0
  124. package/dist/schemaFactory.spec.cjs +197 -0
  125. package/dist/schemaFactory.spec.d.ts +1 -0
  126. package/dist/schemaFactory.spec.js +191 -0
  127. package/dist/schemaModule.cjs +280 -0
  128. package/dist/schemaModule.d.ts +97 -0
  129. package/dist/schemaModule.js +243 -0
  130. package/dist/schemaModule.spec.cjs +355 -0
  131. package/dist/schemaModule.spec.d.ts +1 -0
  132. package/dist/schemaModule.spec.js +349 -0
  133. package/dist/string.cjs +93 -0
  134. package/dist/string.d.ts +85 -0
  135. package/dist/string.js +59 -0
  136. package/dist/string.spec.cjs +158 -0
  137. package/dist/string.spec.d.ts +1 -0
  138. package/dist/string.spec.js +152 -0
  139. package/dist/testing/mocks/assertions.mock.cjs +48 -0
  140. package/dist/testing/mocks/assertions.mock.d.ts +5 -0
  141. package/dist/testing/mocks/assertions.mock.js +14 -0
  142. package/dist/testing/mocks/index.cjs +52 -0
  143. package/dist/testing/mocks/index.d.ts +4 -0
  144. package/dist/testing/mocks/index.js +3 -0
  145. package/dist/testing/mocks/schema.mock.cjs +120 -0
  146. package/dist/testing/mocks/schema.mock.d.ts +37 -0
  147. package/dist/testing/mocks/schema.mock.js +74 -0
  148. package/dist/tuple.cjs +58 -0
  149. package/dist/tuple.d.ts +33 -0
  150. package/dist/tuple.js +24 -0
  151. package/dist/tuple.spec.cjs +162 -0
  152. package/dist/tuple.spec.d.ts +1 -0
  153. package/dist/tuple.spec.js +156 -0
  154. package/dist/typeGuards.cjs +60 -0
  155. package/dist/typeGuards.d.ts +93 -0
  156. package/dist/typeGuards.js +8 -0
  157. package/dist/typeGuards.spec.cjs +101 -0
  158. package/dist/typeGuards.spec.d.ts +1 -0
  159. package/dist/typeGuards.spec.js +95 -0
  160. package/dist/types.cjs +18 -0
  161. package/dist/types.d.ts +289 -0
  162. package/dist/types.js +0 -0
  163. package/dist/union.cjs +74 -0
  164. package/dist/union.d.ts +33 -0
  165. package/dist/union.js +40 -0
  166. package/dist/union.spec.cjs +159 -0
  167. package/dist/union.spec.d.ts +1 -0
  168. package/dist/union.spec.js +153 -0
  169. package/package.json +47 -0
@@ -0,0 +1,512 @@
1
+ "use strict";
2
+ var __webpack_exports__ = {};
3
+ const external_vitest_namespaceObject = require("vitest");
4
+ const external_api_cjs_namespaceObject = require("./api.cjs");
5
+ const external_operation_cjs_namespaceObject = require("./operation.cjs");
6
+ const index_cjs_namespaceObject = require("./testing/mocks/index.cjs");
7
+ (0, external_vitest_namespaceObject.describe)('api utilities', ()=>{
8
+ (0, external_vitest_namespaceObject.beforeAll)(()=>{
9
+ external_vitest_namespaceObject.vi.useRealTimers();
10
+ });
11
+ (0, external_vitest_namespaceObject.beforeEach)(()=>{
12
+ external_vitest_namespaceObject.vi.clearAllMocks();
13
+ });
14
+ (0, external_vitest_namespaceObject.afterEach)(()=>{
15
+ external_vitest_namespaceObject.vi.clearAllMocks();
16
+ });
17
+ (0, external_vitest_namespaceObject.afterAll)(()=>{
18
+ external_vitest_namespaceObject.vi.restoreAllMocks();
19
+ });
20
+ (0, external_vitest_namespaceObject.describe)("subscription()", ()=>{
21
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
22
+ (0, external_vitest_namespaceObject.it)('should include optional fields when optional values are provided', ()=>{
23
+ const payload = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
24
+ name: 'Payload',
25
+ type: 'payload'
26
+ });
27
+ const input = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
28
+ name: 'Input',
29
+ type: 'input'
30
+ });
31
+ const output = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
32
+ name: 'Output',
33
+ type: 'output'
34
+ });
35
+ const filter = external_vitest_namespaceObject.vi.fn(()=>true);
36
+ const exec = external_vitest_namespaceObject.vi.fn(()=>({
37
+ event: 'created'
38
+ }));
39
+ const result = (0, external_api_cjs_namespaceObject.subscription)({
40
+ name: 'userCreated',
41
+ input,
42
+ payload,
43
+ output,
44
+ filter,
45
+ exec,
46
+ doc: {
47
+ summary: "subscription doc"
48
+ }
49
+ });
50
+ (0, external_vitest_namespaceObject.expect)(result.type).toBe("subscription");
51
+ (0, external_vitest_namespaceObject.expect)(result.name).toBe('userCreated');
52
+ (0, external_vitest_namespaceObject.expect)(result.input).toBe(input);
53
+ (0, external_vitest_namespaceObject.expect)(result.payload).toBe(payload);
54
+ (0, external_vitest_namespaceObject.expect)(result.output).toBe(output);
55
+ (0, external_vitest_namespaceObject.expect)(result.filter).toBe(filter);
56
+ (0, external_vitest_namespaceObject.expect)(result.exec).toBe(exec);
57
+ (0, external_vitest_namespaceObject.expect)(result.doc).toEqual({
58
+ summary: "subscription doc"
59
+ });
60
+ });
61
+ });
62
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
63
+ (0, external_vitest_namespaceObject.it)('should only include mandatory payload when optional values are omitted', ()=>{
64
+ const payload = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
65
+ name: 'Payload',
66
+ type: 'payload'
67
+ });
68
+ const result = (0, external_api_cjs_namespaceObject.subscription)({
69
+ payload
70
+ });
71
+ (0, external_vitest_namespaceObject.expect)(result.type).toBe("subscription");
72
+ (0, external_vitest_namespaceObject.expect)(result.payload).toBe(payload);
73
+ (0, external_vitest_namespaceObject.expect)(result.input).toBeUndefined();
74
+ (0, external_vitest_namespaceObject.expect)(result.output).toBeUndefined();
75
+ (0, external_vitest_namespaceObject.expect)(result.filter).toBeUndefined();
76
+ (0, external_vitest_namespaceObject.expect)(result.exec).toBeUndefined();
77
+ });
78
+ });
79
+ });
80
+ (0, external_vitest_namespaceObject.describe)('api()', ()=>{
81
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
82
+ (0, external_vitest_namespaceObject.it)('should merge explicit and inline operations when both are provided', ()=>{
83
+ const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
84
+ name: 'Input',
85
+ type: 'input',
86
+ outputValue: 'x'
87
+ });
88
+ const explicitOperation = (0, external_operation_cjs_namespaceObject.operation)({
89
+ input: inputSchema,
90
+ exec: async ()=>'explicit'
91
+ });
92
+ const inlineOperation = (0, external_operation_cjs_namespaceObject.operation)({
93
+ input: inputSchema,
94
+ exec: async ()=>'inline'
95
+ });
96
+ const result = (0, external_api_cjs_namespaceObject.api)({
97
+ operations: {
98
+ explicit: explicitOperation
99
+ },
100
+ inline: inlineOperation
101
+ });
102
+ const operations = result.operations;
103
+ (0, external_vitest_namespaceObject.expect)(operations.explicit?.name).toBe('explicit');
104
+ (0, external_vitest_namespaceObject.expect)(operations.explicit?.exec).toBe(explicitOperation.exec);
105
+ (0, external_vitest_namespaceObject.expect)(operations.inline?.name).toBe('inline');
106
+ (0, external_vitest_namespaceObject.expect)(operations.inline?.exec).toBe(inlineOperation.exec);
107
+ });
108
+ (0, external_vitest_namespaceObject.it)("should assign missing names to operations field operations and subscriptions", ()=>{
109
+ const entity = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
110
+ name: 'User',
111
+ type: 'object',
112
+ astNode: {
113
+ type: 'object',
114
+ name: 'User'
115
+ },
116
+ outputValue: {
117
+ id: 'u-1'
118
+ }
119
+ });
120
+ const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
121
+ name: 'Input',
122
+ type: 'input',
123
+ outputValue: 'x'
124
+ });
125
+ const payloadSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
126
+ name: 'Payload',
127
+ type: 'payload'
128
+ });
129
+ const op = (0, external_operation_cjs_namespaceObject.operation)({
130
+ input: inputSchema,
131
+ exec: async ()=>'ok'
132
+ });
133
+ const fieldOp = (0, external_operation_cjs_namespaceObject.fieldOperation)({
134
+ dependsOn: entity,
135
+ exec: async ()=>'field'
136
+ });
137
+ const sub = (0, external_api_cjs_namespaceObject.subscription)({
138
+ payload: payloadSchema
139
+ });
140
+ const result = (0, external_api_cjs_namespaceObject.api)({
141
+ type: entity,
142
+ operations: {
143
+ createUser: op
144
+ },
145
+ fieldOperations: {
146
+ displayName: fieldOp
147
+ },
148
+ subscriptions: {
149
+ userCreated: sub
150
+ }
151
+ });
152
+ (0, external_vitest_namespaceObject.expect)(result.operations.createUser.name).toBe('createUser');
153
+ (0, external_vitest_namespaceObject.expect)(result.fieldOperations.displayName.name).toBe('displayName');
154
+ (0, external_vitest_namespaceObject.expect)(result.subscriptions.userCreated?.name).toBe('userCreated');
155
+ });
156
+ (0, external_vitest_namespaceObject.it)("should build ast with operation subscription and field nodes when ast is requested", ()=>{
157
+ const entity = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
158
+ name: 'User',
159
+ type: 'object',
160
+ astNode: {
161
+ type: 'object',
162
+ name: 'User'
163
+ },
164
+ outputValue: {
165
+ id: 'u-1'
166
+ }
167
+ });
168
+ const operationInput = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
169
+ name: 'OperationInput',
170
+ type: 'operation-input',
171
+ astNode: {
172
+ type: 'object',
173
+ name: 'OperationInput'
174
+ },
175
+ outputValue: {
176
+ name: 'Alice'
177
+ }
178
+ });
179
+ const operationOutput = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
180
+ name: 'OperationOutput',
181
+ type: 'operation-output',
182
+ astNode: {
183
+ type: 'object',
184
+ name: 'OperationOutput'
185
+ },
186
+ outputValue: {
187
+ id: 'u-1'
188
+ }
189
+ });
190
+ const subscriptionPayload = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
191
+ name: "SubscriptionPayload",
192
+ type: "subscription-payload",
193
+ astNode: {
194
+ type: 'object',
195
+ name: "SubscriptionPayload"
196
+ }
197
+ });
198
+ const fieldInput = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
199
+ name: 'FieldInput',
200
+ type: 'field-input',
201
+ astNode: {
202
+ type: 'object',
203
+ name: 'FieldInput'
204
+ },
205
+ outputValue: {
206
+ locale: 'en'
207
+ }
208
+ });
209
+ const fieldOutput = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
210
+ name: 'FieldOutput',
211
+ type: 'field-output',
212
+ astNode: {
213
+ type: 'object',
214
+ name: 'FieldOutput'
215
+ },
216
+ outputValue: {
217
+ value: 'Alice'
218
+ }
219
+ });
220
+ const createUser = (0, external_operation_cjs_namespaceObject.operation)({
221
+ input: operationInput,
222
+ output: operationOutput,
223
+ exec: async ()=>({
224
+ id: 'u-1'
225
+ }),
226
+ publish: {
227
+ userCreated: ()=>({
228
+ id: 'u-1'
229
+ })
230
+ },
231
+ ack: {
232
+ required: true,
233
+ mode: 'handled'
234
+ },
235
+ doc: {
236
+ summary: 'create user'
237
+ }
238
+ });
239
+ const displayName = (0, external_operation_cjs_namespaceObject.fieldOperation)({
240
+ dependsOn: entity,
241
+ input: fieldInput,
242
+ output: fieldOutput,
243
+ exec: async ()=>({
244
+ value: 'Alice'
245
+ }),
246
+ doc: {
247
+ summary: 'field doc'
248
+ }
249
+ });
250
+ const userCreated = (0, external_api_cjs_namespaceObject.subscription)({
251
+ payload: subscriptionPayload,
252
+ doc: {
253
+ summary: 'sub doc'
254
+ }
255
+ });
256
+ const result = (0, external_api_cjs_namespaceObject.api)({
257
+ doc: {
258
+ summary: 'api doc'
259
+ },
260
+ type: entity,
261
+ operations: {
262
+ createUser
263
+ },
264
+ fieldOperations: {
265
+ displayName
266
+ },
267
+ subscriptions: {
268
+ userCreated
269
+ }
270
+ });
271
+ const ast = result.ast();
272
+ const operationNode = ast.children?.find((node)=>'operation' === node.type);
273
+ const subscriptionNode = ast.children?.find((node)=>"subscription" === node.type);
274
+ const fieldNode = ast.children?.find((node)=>'field' === node.type);
275
+ (0, external_vitest_namespaceObject.expect)(ast.type).toBe('api');
276
+ (0, external_vitest_namespaceObject.expect)(ast.doc).toEqual({
277
+ summary: 'api doc'
278
+ });
279
+ (0, external_vitest_namespaceObject.expect)(operationNode).toMatchObject({
280
+ name: 'createUser',
281
+ constraints: {
282
+ publish: [
283
+ 'userCreated'
284
+ ],
285
+ ack: {
286
+ required: true,
287
+ mode: 'handled'
288
+ },
289
+ request: 'OperationInput',
290
+ response: 'OperationOutput'
291
+ }
292
+ });
293
+ (0, external_vitest_namespaceObject.expect)(subscriptionNode).toMatchObject({
294
+ name: 'userCreated',
295
+ constraints: {
296
+ payload: "SubscriptionPayload",
297
+ output: "SubscriptionPayload"
298
+ }
299
+ });
300
+ (0, external_vitest_namespaceObject.expect)(fieldNode).toMatchObject({
301
+ name: 'User.displayName',
302
+ constraints: {
303
+ owner: 'User',
304
+ field: 'displayName',
305
+ request: 'FieldInput',
306
+ response: 'FieldOutput',
307
+ dependsOn: 'User'
308
+ }
309
+ });
310
+ });
311
+ });
312
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
313
+ (0, external_vitest_namespaceObject.it)('should throw when field operations are provided without entity type', ()=>{
314
+ const fieldOp = (0, external_operation_cjs_namespaceObject.fieldOperation)({
315
+ dependsOn: (0, index_cjs_namespaceObject.createBaseSchemaMock)({
316
+ outputValue: {
317
+ id: 'u-1'
318
+ }
319
+ }),
320
+ exec: async ()=>'field'
321
+ });
322
+ (0, external_vitest_namespaceObject.expect)(()=>(0, external_api_cjs_namespaceObject.api)({
323
+ fieldOperations: {
324
+ displayName: fieldOp
325
+ }
326
+ })).toThrowError('api.type is required when fieldOperations are provided.');
327
+ });
328
+ (0, external_vitest_namespaceObject.it)("should throw when operation publishes topic without matching subscription", ()=>{
329
+ const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
330
+ outputValue: 'x'
331
+ });
332
+ const publishingOperation = (0, external_operation_cjs_namespaceObject.operation)({
333
+ input: inputSchema,
334
+ exec: async ()=>'ok',
335
+ publish: {
336
+ missingTopic: ()=>({
337
+ payload: true
338
+ })
339
+ }
340
+ });
341
+ (0, external_vitest_namespaceObject.expect)(()=>(0, external_api_cjs_namespaceObject.api)({
342
+ operations: {
343
+ createUser: publishingOperation
344
+ }
345
+ })).toThrowError('api: operation "createUser" publishes "missingTopic" but no subscription with that name exists.');
346
+ });
347
+ });
348
+ });
349
+ (0, external_vitest_namespaceObject.describe)('composeApi()', ()=>{
350
+ (0, external_vitest_namespaceObject.describe)('happy', ()=>{
351
+ (0, external_vitest_namespaceObject.it)("should compose operations field operations and subscriptions from multiple apis", ()=>{
352
+ const userSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
353
+ name: 'User',
354
+ type: 'object',
355
+ astNode: {
356
+ type: 'object',
357
+ name: 'User'
358
+ },
359
+ outputValue: {
360
+ id: 'u-1'
361
+ }
362
+ });
363
+ const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
364
+ outputValue: 'x'
365
+ });
366
+ const payloadSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
367
+ name: 'Payload',
368
+ type: 'payload'
369
+ });
370
+ const usersApi = (0, external_api_cjs_namespaceObject.api)({
371
+ type: userSchema,
372
+ operations: {
373
+ createUser: (0, external_operation_cjs_namespaceObject.operation)({
374
+ input: inputSchema,
375
+ exec: async ()=>'ok'
376
+ })
377
+ },
378
+ fieldOperations: {
379
+ displayName: (0, external_operation_cjs_namespaceObject.fieldOperation)({
380
+ dependsOn: userSchema,
381
+ exec: async ()=>'name'
382
+ })
383
+ },
384
+ subscriptions: {
385
+ userCreated: (0, external_api_cjs_namespaceObject.subscription)({
386
+ payload: payloadSchema
387
+ })
388
+ }
389
+ });
390
+ const systemApi = (0, external_api_cjs_namespaceObject.api)({
391
+ operations: {
392
+ health: (0, external_operation_cjs_namespaceObject.operation)({
393
+ input: inputSchema,
394
+ exec: async ()=>'ok'
395
+ })
396
+ }
397
+ });
398
+ const composed = (0, external_api_cjs_namespaceObject.composeApi)({
399
+ users: usersApi,
400
+ system: systemApi
401
+ });
402
+ const ast = composed.ast();
403
+ (0, external_vitest_namespaceObject.expect)(composed.type).toBe('api-composed');
404
+ (0, external_vitest_namespaceObject.expect)(Object.keys(composed.operations)).toEqual([
405
+ 'createUser',
406
+ 'health'
407
+ ]);
408
+ (0, external_vitest_namespaceObject.expect)(Object.keys(composed.fieldOperations)).toEqual([
409
+ 'User.displayName'
410
+ ]);
411
+ (0, external_vitest_namespaceObject.expect)(Object.keys(composed.subscriptions)).toEqual([
412
+ 'userCreated'
413
+ ]);
414
+ (0, external_vitest_namespaceObject.expect)(ast.type).toBe('api-composed');
415
+ (0, external_vitest_namespaceObject.expect)(ast.children?.map((node)=>node.name)).toEqual([
416
+ 'users',
417
+ 'system'
418
+ ]);
419
+ });
420
+ });
421
+ (0, external_vitest_namespaceObject.describe)('sad', ()=>{
422
+ (0, external_vitest_namespaceObject.it)('should throw when two apis contain duplicate operation names', ()=>{
423
+ const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
424
+ outputValue: 'x'
425
+ });
426
+ const left = (0, external_api_cjs_namespaceObject.api)({
427
+ operations: {
428
+ ping: (0, external_operation_cjs_namespaceObject.operation)({
429
+ input: inputSchema,
430
+ exec: async ()=>'left'
431
+ })
432
+ }
433
+ });
434
+ const right = (0, external_api_cjs_namespaceObject.api)({
435
+ operations: {
436
+ ping: (0, external_operation_cjs_namespaceObject.operation)({
437
+ input: inputSchema,
438
+ exec: async ()=>'right'
439
+ })
440
+ }
441
+ });
442
+ (0, external_vitest_namespaceObject.expect)(()=>(0, external_api_cjs_namespaceObject.composeApi)({
443
+ left,
444
+ right
445
+ })).toThrowError('composeApi: duplicate operation name "ping"');
446
+ });
447
+ (0, external_vitest_namespaceObject.it)('should throw when two apis contain duplicate field operation names', ()=>{
448
+ const owner = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
449
+ name: 'User',
450
+ type: 'object',
451
+ astNode: {
452
+ type: 'object',
453
+ name: 'User'
454
+ },
455
+ outputValue: {
456
+ id: 'u-1'
457
+ }
458
+ });
459
+ const left = (0, external_api_cjs_namespaceObject.api)({
460
+ type: owner,
461
+ fieldOperations: {
462
+ displayName: (0, external_operation_cjs_namespaceObject.fieldOperation)({
463
+ dependsOn: owner,
464
+ exec: async ()=>'left'
465
+ })
466
+ }
467
+ });
468
+ const right = (0, external_api_cjs_namespaceObject.api)({
469
+ type: owner,
470
+ fieldOperations: {
471
+ displayName: (0, external_operation_cjs_namespaceObject.fieldOperation)({
472
+ dependsOn: owner,
473
+ exec: async ()=>'right'
474
+ })
475
+ }
476
+ });
477
+ (0, external_vitest_namespaceObject.expect)(()=>(0, external_api_cjs_namespaceObject.composeApi)({
478
+ left,
479
+ right
480
+ })).toThrowError('composeApi: duplicate field operation name "User.displayName"');
481
+ });
482
+ (0, external_vitest_namespaceObject.it)("should throw when two apis contain duplicate subscription names", ()=>{
483
+ const payload = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
484
+ name: 'Payload',
485
+ type: 'payload'
486
+ });
487
+ const left = (0, external_api_cjs_namespaceObject.api)({
488
+ subscriptions: {
489
+ userCreated: (0, external_api_cjs_namespaceObject.subscription)({
490
+ payload
491
+ })
492
+ }
493
+ });
494
+ const right = (0, external_api_cjs_namespaceObject.api)({
495
+ subscriptions: {
496
+ userCreated: (0, external_api_cjs_namespaceObject.subscription)({
497
+ payload
498
+ })
499
+ }
500
+ });
501
+ (0, external_vitest_namespaceObject.expect)(()=>(0, external_api_cjs_namespaceObject.composeApi)({
502
+ left,
503
+ right
504
+ })).toThrowError('composeApi: duplicate subscription name "userCreated"');
505
+ });
506
+ });
507
+ });
508
+ });
509
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
510
+ Object.defineProperty(exports, '__esModule', {
511
+ value: true
512
+ });
@@ -0,0 +1 @@
1
+ export {};