@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.
- package/PROMPT.md +21 -0
- package/README.md +13 -0
- package/SCHEMA.md +13 -0
- package/dist/SchemaValidationError.cjs +41 -0
- package/dist/SchemaValidationError.d.ts +20 -0
- package/dist/SchemaValidationError.js +7 -0
- package/dist/SchemaValidationError.spec.cjs +65 -0
- package/dist/SchemaValidationError.spec.d.ts +1 -0
- package/dist/SchemaValidationError.spec.js +59 -0
- package/dist/after.cjs +36 -0
- package/dist/after.d.ts +30 -0
- package/dist/after.js +2 -0
- package/dist/after.spec.cjs +54 -0
- package/dist/after.spec.d.ts +1 -0
- package/dist/after.spec.js +48 -0
- package/dist/and.cjs +36 -0
- package/dist/and.d.ts +26 -0
- package/dist/and.js +2 -0
- package/dist/and.spec.cjs +57 -0
- package/dist/and.spec.d.ts +1 -0
- package/dist/and.spec.js +51 -0
- package/dist/api.cjs +317 -0
- package/dist/api.d.ts +107 -0
- package/dist/api.js +277 -0
- package/dist/api.spec.cjs +512 -0
- package/dist/api.spec.d.ts +1 -0
- package/dist/api.spec.js +506 -0
- package/dist/array.cjs +74 -0
- package/dist/array.d.ts +25 -0
- package/dist/array.js +40 -0
- package/dist/array.spec.cjs +167 -0
- package/dist/array.spec.d.ts +1 -0
- package/dist/array.spec.js +161 -0
- package/dist/before.cjs +36 -0
- package/dist/before.d.ts +30 -0
- package/dist/before.js +2 -0
- package/dist/before.spec.cjs +54 -0
- package/dist/before.spec.d.ts +1 -0
- package/dist/before.spec.js +48 -0
- package/dist/binary.cjs +53 -0
- package/dist/binary.d.ts +24 -0
- package/dist/binary.js +19 -0
- package/dist/binary.spec.cjs +107 -0
- package/dist/binary.spec.d.ts +1 -0
- package/dist/binary.spec.js +101 -0
- package/dist/boolean.cjs +53 -0
- package/dist/boolean.d.ts +24 -0
- package/dist/boolean.js +19 -0
- package/dist/boolean.spec.cjs +96 -0
- package/dist/boolean.spec.d.ts +1 -0
- package/dist/boolean.spec.js +90 -0
- package/dist/context.cjs +125 -0
- package/dist/context.d.ts +101 -0
- package/dist/context.js +76 -0
- package/dist/context.spec.cjs +244 -0
- package/dist/context.spec.d.ts +1 -0
- package/dist/context.spec.js +238 -0
- package/dist/date.cjs +53 -0
- package/dist/date.d.ts +24 -0
- package/dist/date.js +19 -0
- package/dist/date.spec.cjs +97 -0
- package/dist/date.spec.d.ts +1 -0
- package/dist/date.spec.js +91 -0
- package/dist/doc.cjs +54 -0
- package/dist/doc.d.ts +25 -0
- package/dist/doc.js +17 -0
- package/dist/doc.spec.cjs +99 -0
- package/dist/doc.spec.d.ts +1 -0
- package/dist/doc.spec.js +93 -0
- package/dist/enumeration.cjs +74 -0
- package/dist/enumeration.d.ts +50 -0
- package/dist/enumeration.js +40 -0
- package/dist/enumeration.spec.cjs +110 -0
- package/dist/enumeration.spec.d.ts +1 -0
- package/dist/enumeration.spec.js +104 -0
- package/dist/hydrate.cjs +18 -0
- package/dist/hydrate.d.ts +1 -0
- package/dist/hydrate.js +0 -0
- package/dist/index.cjs +145 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +24 -0
- package/dist/index.spec.cjs +43 -0
- package/dist/index.spec.d.ts +1 -0
- package/dist/index.spec.js +37 -0
- package/dist/literal.cjs +55 -0
- package/dist/literal.d.ts +25 -0
- package/dist/literal.js +21 -0
- package/dist/literal.spec.cjs +93 -0
- package/dist/literal.spec.d.ts +1 -0
- package/dist/literal.spec.js +87 -0
- package/dist/number.cjs +89 -0
- package/dist/number.d.ts +84 -0
- package/dist/number.js +55 -0
- package/dist/number.spec.cjs +155 -0
- package/dist/number.spec.d.ts +1 -0
- package/dist/number.spec.js +149 -0
- package/dist/object.cjs +66 -0
- package/dist/object.d.ts +37 -0
- package/dist/object.js +32 -0
- package/dist/object.spec.cjs +171 -0
- package/dist/object.spec.d.ts +1 -0
- package/dist/object.spec.js +165 -0
- package/dist/operation.cjs +182 -0
- package/dist/operation.d.ts +197 -0
- package/dist/operation.js +133 -0
- package/dist/operation.spec.cjs +454 -0
- package/dist/operation.spec.d.ts +1 -0
- package/dist/operation.spec.js +448 -0
- package/dist/or.cjs +85 -0
- package/dist/or.d.ts +37 -0
- package/dist/or.js +51 -0
- package/dist/or.spec.cjs +204 -0
- package/dist/or.spec.d.ts +1 -0
- package/dist/or.spec.js +198 -0
- package/dist/schema.cjs +285 -0
- package/dist/schema.d.ts +132 -0
- package/dist/schema.js +233 -0
- package/dist/schema.spec.cjs +587 -0
- package/dist/schema.spec.d.ts +1 -0
- package/dist/schema.spec.js +581 -0
- package/dist/schemaFactory.cjs +125 -0
- package/dist/schemaFactory.d.ts +97 -0
- package/dist/schemaFactory.js +88 -0
- package/dist/schemaFactory.spec.cjs +197 -0
- package/dist/schemaFactory.spec.d.ts +1 -0
- package/dist/schemaFactory.spec.js +191 -0
- package/dist/schemaModule.cjs +280 -0
- package/dist/schemaModule.d.ts +97 -0
- package/dist/schemaModule.js +243 -0
- package/dist/schemaModule.spec.cjs +355 -0
- package/dist/schemaModule.spec.d.ts +1 -0
- package/dist/schemaModule.spec.js +349 -0
- package/dist/string.cjs +93 -0
- package/dist/string.d.ts +85 -0
- package/dist/string.js +59 -0
- package/dist/string.spec.cjs +158 -0
- package/dist/string.spec.d.ts +1 -0
- package/dist/string.spec.js +152 -0
- package/dist/testing/mocks/assertions.mock.cjs +48 -0
- package/dist/testing/mocks/assertions.mock.d.ts +5 -0
- package/dist/testing/mocks/assertions.mock.js +14 -0
- package/dist/testing/mocks/index.cjs +52 -0
- package/dist/testing/mocks/index.d.ts +4 -0
- package/dist/testing/mocks/index.js +3 -0
- package/dist/testing/mocks/schema.mock.cjs +120 -0
- package/dist/testing/mocks/schema.mock.d.ts +37 -0
- package/dist/testing/mocks/schema.mock.js +74 -0
- package/dist/tuple.cjs +58 -0
- package/dist/tuple.d.ts +33 -0
- package/dist/tuple.js +24 -0
- package/dist/tuple.spec.cjs +162 -0
- package/dist/tuple.spec.d.ts +1 -0
- package/dist/tuple.spec.js +156 -0
- package/dist/typeGuards.cjs +60 -0
- package/dist/typeGuards.d.ts +93 -0
- package/dist/typeGuards.js +8 -0
- package/dist/typeGuards.spec.cjs +101 -0
- package/dist/typeGuards.spec.d.ts +1 -0
- package/dist/typeGuards.spec.js +95 -0
- package/dist/types.cjs +18 -0
- package/dist/types.d.ts +289 -0
- package/dist/types.js +0 -0
- package/dist/union.cjs +74 -0
- package/dist/union.d.ts +33 -0
- package/dist/union.js +40 -0
- package/dist/union.spec.cjs +159 -0
- package/dist/union.spec.d.ts +1 -0
- package/dist/union.spec.js +153 -0
- package/package.json +47 -0
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_exports__ = {};
|
|
3
|
+
const external_vitest_namespaceObject = require("vitest");
|
|
4
|
+
const external_operation_cjs_namespaceObject = require("./operation.cjs");
|
|
5
|
+
const external_schemaModule_cjs_namespaceObject = require("./schemaModule.cjs");
|
|
6
|
+
const index_cjs_namespaceObject = require("./testing/mocks/index.cjs");
|
|
7
|
+
const createRuntimeContextMock = ()=>{
|
|
8
|
+
const runtimeContext = {};
|
|
9
|
+
runtimeContext.emitEvent = external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
10
|
+
ok: true
|
|
11
|
+
}));
|
|
12
|
+
runtimeContext.emitReceive = external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
13
|
+
ok: true
|
|
14
|
+
}));
|
|
15
|
+
runtimeContext.emitSend = external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
16
|
+
ok: true
|
|
17
|
+
}));
|
|
18
|
+
runtimeContext.emitError = external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
19
|
+
ok: true
|
|
20
|
+
}));
|
|
21
|
+
runtimeContext.state = {
|
|
22
|
+
get: external_vitest_namespaceObject.vi.fn(()=>void 0),
|
|
23
|
+
set: external_vitest_namespaceObject.vi.fn(()=>void 0)
|
|
24
|
+
};
|
|
25
|
+
runtimeContext.room = external_vitest_namespaceObject.vi.fn(()=>runtimeContext);
|
|
26
|
+
return runtimeContext;
|
|
27
|
+
};
|
|
28
|
+
const createEnvelope = (overrides = {})=>({
|
|
29
|
+
id: 'evt-1',
|
|
30
|
+
event: 'unknown',
|
|
31
|
+
status: 'receiving',
|
|
32
|
+
payload: new Uint8Array([
|
|
33
|
+
1
|
|
34
|
+
]),
|
|
35
|
+
...overrides
|
|
36
|
+
});
|
|
37
|
+
const createRegistryMock = (state)=>({
|
|
38
|
+
onReceive: external_vitest_namespaceObject.vi.fn((hook)=>{
|
|
39
|
+
state.onReceive = hook;
|
|
40
|
+
return {
|
|
41
|
+
unsub: ()=>void 0
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
44
|
+
onSend: external_vitest_namespaceObject.vi.fn(()=>({
|
|
45
|
+
unsub: ()=>void 0
|
|
46
|
+
})),
|
|
47
|
+
onError: external_vitest_namespaceObject.vi.fn(()=>({
|
|
48
|
+
unsub: ()=>void 0
|
|
49
|
+
})),
|
|
50
|
+
emitReceive: external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
51
|
+
ok: true
|
|
52
|
+
})),
|
|
53
|
+
emitSend: external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
54
|
+
ok: true
|
|
55
|
+
})),
|
|
56
|
+
emitError: external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
57
|
+
ok: true
|
|
58
|
+
})),
|
|
59
|
+
state: {
|
|
60
|
+
get: external_vitest_namespaceObject.vi.fn(()=>void 0),
|
|
61
|
+
set: external_vitest_namespaceObject.vi.fn(()=>void 0)
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
(0, external_vitest_namespaceObject.describe)('schemaModule utilities', ()=>{
|
|
65
|
+
let runtimeContext;
|
|
66
|
+
(0, external_vitest_namespaceObject.beforeAll)(()=>{
|
|
67
|
+
runtimeContext = createRuntimeContextMock();
|
|
68
|
+
});
|
|
69
|
+
(0, external_vitest_namespaceObject.beforeEach)(()=>{
|
|
70
|
+
runtimeContext = createRuntimeContextMock();
|
|
71
|
+
});
|
|
72
|
+
(0, external_vitest_namespaceObject.afterEach)(()=>{
|
|
73
|
+
external_vitest_namespaceObject.vi.clearAllMocks();
|
|
74
|
+
});
|
|
75
|
+
(0, external_vitest_namespaceObject.afterAll)(()=>{
|
|
76
|
+
external_vitest_namespaceObject.vi.restoreAllMocks();
|
|
77
|
+
});
|
|
78
|
+
(0, external_vitest_namespaceObject.describe)('createSchemaModuleInput()', ()=>{
|
|
79
|
+
(0, external_vitest_namespaceObject.describe)('happy', ()=>{
|
|
80
|
+
(0, external_vitest_namespaceObject.it)('should keep schema module parts when valid module-like input is provided', ()=>{
|
|
81
|
+
const operations = {
|
|
82
|
+
ping: (0, external_operation_cjs_namespaceObject.operation)({
|
|
83
|
+
input: (0, index_cjs_namespaceObject.createBaseSchemaMock)(),
|
|
84
|
+
exec: async ()=>'ok'
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
const fieldOperations = {};
|
|
88
|
+
const subscriptions = {};
|
|
89
|
+
const ast = ()=>({
|
|
90
|
+
type: 'api'
|
|
91
|
+
});
|
|
92
|
+
const result = (0, external_schemaModule_cjs_namespaceObject.createSchemaModuleInput)({
|
|
93
|
+
operations,
|
|
94
|
+
fieldOperations,
|
|
95
|
+
subscriptions,
|
|
96
|
+
ast
|
|
97
|
+
});
|
|
98
|
+
(0, external_vitest_namespaceObject.expect)(result.operations).toBe(operations);
|
|
99
|
+
(0, external_vitest_namespaceObject.expect)(result.fieldOperations).toBe(fieldOperations);
|
|
100
|
+
(0, external_vitest_namespaceObject.expect)(result.subscriptions).toBe(subscriptions);
|
|
101
|
+
(0, external_vitest_namespaceObject.expect)(result.ast).toBe(ast);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
(0, external_vitest_namespaceObject.describe)('sad', ()=>{
|
|
105
|
+
(0, external_vitest_namespaceObject.it)('should keep empty records when empty module-like input is provided', ()=>{
|
|
106
|
+
const result = (0, external_schemaModule_cjs_namespaceObject.createSchemaModuleInput)({
|
|
107
|
+
operations: {},
|
|
108
|
+
fieldOperations: {},
|
|
109
|
+
subscriptions: {},
|
|
110
|
+
ast: ()=>({
|
|
111
|
+
type: 'api'
|
|
112
|
+
})
|
|
113
|
+
});
|
|
114
|
+
(0, external_vitest_namespaceObject.expect)(result.operations).toEqual({});
|
|
115
|
+
(0, external_vitest_namespaceObject.expect)(result.fieldOperations).toEqual({});
|
|
116
|
+
(0, external_vitest_namespaceObject.expect)(result.subscriptions).toEqual({});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
(0, external_vitest_namespaceObject.describe)('schemaModule()', ()=>{
|
|
121
|
+
(0, external_vitest_namespaceObject.describe)('happy', ()=>{
|
|
122
|
+
(0, external_vitest_namespaceObject.it)('should register onReceive hook when runtime module register is called', ()=>{
|
|
123
|
+
const module = (0, external_schemaModule_cjs_namespaceObject.schemaModule)((0, external_schemaModule_cjs_namespaceObject.createSchemaModuleInput)({
|
|
124
|
+
operations: {},
|
|
125
|
+
fieldOperations: {},
|
|
126
|
+
subscriptions: {},
|
|
127
|
+
ast: ()=>({
|
|
128
|
+
type: 'api'
|
|
129
|
+
})
|
|
130
|
+
}));
|
|
131
|
+
const state = {};
|
|
132
|
+
const registry = createRegistryMock(state);
|
|
133
|
+
module.register(registry);
|
|
134
|
+
(0, external_vitest_namespaceObject.expect)(module.name).toBe('schema');
|
|
135
|
+
(0, external_vitest_namespaceObject.expect)(registry.onReceive).toHaveBeenCalledTimes(1);
|
|
136
|
+
(0, external_vitest_namespaceObject.expect)(typeof state.onReceive).toBe('function');
|
|
137
|
+
});
|
|
138
|
+
(0, external_vitest_namespaceObject.it)('should emit explain payload when explain option is enabled and explain event is received', async ()=>{
|
|
139
|
+
const encode = external_vitest_namespaceObject.vi.fn(()=>new Uint8Array([
|
|
140
|
+
9
|
|
141
|
+
]));
|
|
142
|
+
const module = (0, external_schemaModule_cjs_namespaceObject.schemaModule)((0, external_schemaModule_cjs_namespaceObject.createSchemaModuleInput)({
|
|
143
|
+
operations: {},
|
|
144
|
+
fieldOperations: {},
|
|
145
|
+
subscriptions: {},
|
|
146
|
+
ast: ()=>({
|
|
147
|
+
type: 'api',
|
|
148
|
+
name: 'RootApi'
|
|
149
|
+
})
|
|
150
|
+
}), {
|
|
151
|
+
explain: true,
|
|
152
|
+
now: ()=>1700000000000,
|
|
153
|
+
encoder: encode
|
|
154
|
+
});
|
|
155
|
+
const state = {};
|
|
156
|
+
const registry = createRegistryMock(state);
|
|
157
|
+
module.register(registry);
|
|
158
|
+
const next = external_vitest_namespaceObject.vi.fn(async ()=>createEnvelope());
|
|
159
|
+
await state.onReceive?.(createEnvelope({
|
|
160
|
+
event: '$explain',
|
|
161
|
+
metadata: {
|
|
162
|
+
ifNoneMatch: 'different-checksum'
|
|
163
|
+
}
|
|
164
|
+
}), runtimeContext, next);
|
|
165
|
+
(0, external_vitest_namespaceObject.expect)(next).not.toHaveBeenCalled();
|
|
166
|
+
(0, external_vitest_namespaceObject.expect)(runtimeContext.emitEvent).toHaveBeenCalledTimes(1);
|
|
167
|
+
(0, external_vitest_namespaceObject.expect)(encode).toHaveBeenCalledTimes(1);
|
|
168
|
+
});
|
|
169
|
+
(0, external_vitest_namespaceObject.it)('should execute operation and emit operation response when operation event matches schema operation', async ()=>{
|
|
170
|
+
const decodedInput = {
|
|
171
|
+
id: 'u-1'
|
|
172
|
+
};
|
|
173
|
+
const decodedOutput = {
|
|
174
|
+
result: 'ok'
|
|
175
|
+
};
|
|
176
|
+
const decode = external_vitest_namespaceObject.vi.fn(()=>decodedInput);
|
|
177
|
+
const encode = external_vitest_namespaceObject.vi.fn(()=>new Uint8Array([
|
|
178
|
+
7
|
|
179
|
+
]));
|
|
180
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
181
|
+
outputValue: decodedInput
|
|
182
|
+
});
|
|
183
|
+
const outputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
184
|
+
outputValue: decodedOutput
|
|
185
|
+
});
|
|
186
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>decodedOutput);
|
|
187
|
+
const module = (0, external_schemaModule_cjs_namespaceObject.schemaModule)((0, external_schemaModule_cjs_namespaceObject.createSchemaModuleInput)({
|
|
188
|
+
operations: {
|
|
189
|
+
ping: (0, external_operation_cjs_namespaceObject.operation)({
|
|
190
|
+
input: inputSchema,
|
|
191
|
+
output: outputSchema,
|
|
192
|
+
exec
|
|
193
|
+
})
|
|
194
|
+
},
|
|
195
|
+
fieldOperations: {},
|
|
196
|
+
subscriptions: {},
|
|
197
|
+
ast: ()=>({
|
|
198
|
+
type: 'api'
|
|
199
|
+
})
|
|
200
|
+
}), {
|
|
201
|
+
decoder: decode,
|
|
202
|
+
encoder: encode
|
|
203
|
+
});
|
|
204
|
+
const state = {};
|
|
205
|
+
const registry = createRegistryMock(state);
|
|
206
|
+
module.register(registry);
|
|
207
|
+
const next = external_vitest_namespaceObject.vi.fn(async ()=>createEnvelope());
|
|
208
|
+
const envelope = createEnvelope({
|
|
209
|
+
event: 'ping'
|
|
210
|
+
});
|
|
211
|
+
const result = await state.onReceive?.(envelope, runtimeContext, next);
|
|
212
|
+
(0, external_vitest_namespaceObject.expect)(exec).toHaveBeenCalledTimes(1);
|
|
213
|
+
(0, external_vitest_namespaceObject.expect)(runtimeContext.emitEvent).toHaveBeenCalledWith({
|
|
214
|
+
event: 'ping',
|
|
215
|
+
payload: new Uint8Array([
|
|
216
|
+
7
|
|
217
|
+
]),
|
|
218
|
+
metadata: void 0,
|
|
219
|
+
context: void 0
|
|
220
|
+
});
|
|
221
|
+
(0, external_vitest_namespaceObject.expect)(result).toBe(envelope);
|
|
222
|
+
});
|
|
223
|
+
(0, external_vitest_namespaceObject.it)('should execute field operation when field event syntax is received', async ()=>{
|
|
224
|
+
const decode = external_vitest_namespaceObject.vi.fn(()=>({
|
|
225
|
+
dependsOn: {
|
|
226
|
+
id: 'u-1'
|
|
227
|
+
},
|
|
228
|
+
input: {
|
|
229
|
+
locale: 'en'
|
|
230
|
+
}
|
|
231
|
+
}));
|
|
232
|
+
const encode = external_vitest_namespaceObject.vi.fn(()=>new Uint8Array([
|
|
233
|
+
5
|
|
234
|
+
]));
|
|
235
|
+
const dependsOnSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
236
|
+
outputValue: {
|
|
237
|
+
id: 'u-1'
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
const inputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
241
|
+
outputValue: {
|
|
242
|
+
locale: 'en'
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
const outputSchema = (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
246
|
+
outputValue: {
|
|
247
|
+
value: 'Alice'
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
const exec = external_vitest_namespaceObject.vi.fn(async ()=>({
|
|
251
|
+
value: 'Alice'
|
|
252
|
+
}));
|
|
253
|
+
const module = (0, external_schemaModule_cjs_namespaceObject.schemaModule)((0, external_schemaModule_cjs_namespaceObject.createSchemaModuleInput)({
|
|
254
|
+
operations: {},
|
|
255
|
+
fieldOperations: {
|
|
256
|
+
'User.displayName': (0, external_operation_cjs_namespaceObject.fieldOperation)({
|
|
257
|
+
dependsOn: dependsOnSchema,
|
|
258
|
+
input: inputSchema,
|
|
259
|
+
output: outputSchema,
|
|
260
|
+
exec
|
|
261
|
+
})
|
|
262
|
+
},
|
|
263
|
+
subscriptions: {},
|
|
264
|
+
ast: ()=>({
|
|
265
|
+
type: 'api'
|
|
266
|
+
})
|
|
267
|
+
}), {
|
|
268
|
+
decoder: decode,
|
|
269
|
+
encoder: encode
|
|
270
|
+
});
|
|
271
|
+
const state = {};
|
|
272
|
+
const registry = createRegistryMock(state);
|
|
273
|
+
module.register(registry);
|
|
274
|
+
const next = external_vitest_namespaceObject.vi.fn(async ()=>createEnvelope());
|
|
275
|
+
await state.onReceive?.(createEnvelope({
|
|
276
|
+
event: '$User.displayName'
|
|
277
|
+
}), runtimeContext, next);
|
|
278
|
+
(0, external_vitest_namespaceObject.expect)(exec).toHaveBeenCalledTimes(1);
|
|
279
|
+
(0, external_vitest_namespaceObject.expect)(runtimeContext.emitEvent).toHaveBeenCalledWith({
|
|
280
|
+
event: '$User.displayName',
|
|
281
|
+
payload: new Uint8Array([
|
|
282
|
+
5
|
|
283
|
+
]),
|
|
284
|
+
metadata: void 0,
|
|
285
|
+
context: void 0
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
(0, external_vitest_namespaceObject.describe)('sad', ()=>{
|
|
290
|
+
(0, external_vitest_namespaceObject.it)('should delegate to next when no matching operation or field operation exists', async ()=>{
|
|
291
|
+
const module = (0, external_schemaModule_cjs_namespaceObject.schemaModule)((0, external_schemaModule_cjs_namespaceObject.createSchemaModuleInput)({
|
|
292
|
+
operations: {},
|
|
293
|
+
fieldOperations: {},
|
|
294
|
+
subscriptions: {},
|
|
295
|
+
ast: ()=>({
|
|
296
|
+
type: 'api'
|
|
297
|
+
})
|
|
298
|
+
}));
|
|
299
|
+
const state = {};
|
|
300
|
+
const registry = createRegistryMock(state);
|
|
301
|
+
module.register(registry);
|
|
302
|
+
const nextResult = createEnvelope({
|
|
303
|
+
event: 'fallback'
|
|
304
|
+
});
|
|
305
|
+
const next = external_vitest_namespaceObject.vi.fn(async ()=>nextResult);
|
|
306
|
+
const result = await state.onReceive?.(createEnvelope({
|
|
307
|
+
event: 'missing.event'
|
|
308
|
+
}), runtimeContext, next);
|
|
309
|
+
(0, external_vitest_namespaceObject.expect)(next).toHaveBeenCalledTimes(1);
|
|
310
|
+
(0, external_vitest_namespaceObject.expect)(result).toBe(nextResult);
|
|
311
|
+
});
|
|
312
|
+
(0, external_vitest_namespaceObject.it)('should emit runtime error when operation execution throws', async ()=>{
|
|
313
|
+
const decode = external_vitest_namespaceObject.vi.fn(()=>({
|
|
314
|
+
id: 'u-1'
|
|
315
|
+
}));
|
|
316
|
+
const execError = new Error('operation failed');
|
|
317
|
+
const module = (0, external_schemaModule_cjs_namespaceObject.schemaModule)((0, external_schemaModule_cjs_namespaceObject.createSchemaModuleInput)({
|
|
318
|
+
operations: {
|
|
319
|
+
ping: (0, external_operation_cjs_namespaceObject.operation)({
|
|
320
|
+
input: (0, index_cjs_namespaceObject.createBaseSchemaMock)({
|
|
321
|
+
outputValue: {
|
|
322
|
+
id: 'u-1'
|
|
323
|
+
}
|
|
324
|
+
}),
|
|
325
|
+
exec: async ()=>{
|
|
326
|
+
throw execError;
|
|
327
|
+
}
|
|
328
|
+
})
|
|
329
|
+
},
|
|
330
|
+
fieldOperations: {},
|
|
331
|
+
subscriptions: {},
|
|
332
|
+
ast: ()=>({
|
|
333
|
+
type: 'api'
|
|
334
|
+
})
|
|
335
|
+
}), {
|
|
336
|
+
decoder: decode
|
|
337
|
+
});
|
|
338
|
+
const state = {};
|
|
339
|
+
const registry = createRegistryMock(state);
|
|
340
|
+
module.register(registry);
|
|
341
|
+
const next = external_vitest_namespaceObject.vi.fn(async ()=>createEnvelope());
|
|
342
|
+
const envelope = createEnvelope({
|
|
343
|
+
event: 'ping'
|
|
344
|
+
});
|
|
345
|
+
const result = await state.onReceive?.(envelope, runtimeContext, next);
|
|
346
|
+
(0, external_vitest_namespaceObject.expect)(runtimeContext.emitError).toHaveBeenCalledTimes(1);
|
|
347
|
+
(0, external_vitest_namespaceObject.expect)(result).toBe(envelope);
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
353
|
+
Object.defineProperty(exports, '__esModule', {
|
|
354
|
+
value: true
|
|
355
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|