@objectstack/plugin-msw 4.0.4 → 4.0.5

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,275 +0,0 @@
1
- // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- import { ObjectStackManifest } from '@objectstack/spec/system';
4
-
5
- /**
6
- * MSW (Mock Service Worker) Plugin Manifest
7
- *
8
- * Browser-based mock server for testing and development.
9
- * Intercepts HTTP requests and provides mock responses using ObjectStack runtime.
10
- */
11
- const MSWPlugin: ObjectStackManifest = {
12
- id: 'com.objectstack.plugin.msw',
13
- name: 'Mock Service Worker Plugin',
14
- version: '1.0.0',
15
- type: 'plugin',
16
- description: 'MSW (Mock Service Worker) integration for testing and development. Provides browser-based API mocking using ObjectStack runtime protocol.',
17
-
18
- configuration: {
19
- title: 'MSW Plugin Configuration',
20
- properties: {
21
- enableBrowser: {
22
- type: 'boolean',
23
- default: true,
24
- description: 'Enable MSW in browser environment',
25
- },
26
- baseUrl: {
27
- type: 'string',
28
- default: '/api/v1',
29
- description: 'Base URL for API endpoints',
30
- },
31
- logRequests: {
32
- type: 'boolean',
33
- default: true,
34
- description: 'Log all intercepted requests',
35
- },
36
- },
37
- },
38
-
39
- // Plugin Capability Declaration
40
- capabilities: {
41
- // Protocols This Plugin Implements
42
- implements: [
43
- {
44
- protocol: {
45
- id: 'com.objectstack.protocol.testing.mock.v1',
46
- label: 'Mock Service Protocol v1',
47
- version: { major: 1, minor: 0, patch: 0 },
48
- description: 'HTTP request mocking for testing',
49
- },
50
- conformance: 'full',
51
- features: [
52
- {
53
- name: 'browser_mocking',
54
- enabled: true,
55
- description: 'Browser-based request interception',
56
- },
57
- {
58
- name: 'api_simulation',
59
- enabled: true,
60
- description: 'Full ObjectStack API simulation',
61
- },
62
- {
63
- name: 'custom_handlers',
64
- enabled: true,
65
- description: 'Custom request handler registration',
66
- },
67
- ],
68
- certified: false,
69
- },
70
- {
71
- protocol: {
72
- id: 'com.objectstack.protocol.api.rest.v1',
73
- label: 'REST API Protocol v1',
74
- version: { major: 1, minor: 0, patch: 0 },
75
- description: 'RESTful API endpoint mocking',
76
- },
77
- conformance: 'full',
78
- features: [
79
- {
80
- name: 'meta_endpoints',
81
- enabled: true,
82
- description: 'Metadata discovery endpoints',
83
- },
84
- {
85
- name: 'data_endpoints',
86
- enabled: true,
87
- description: 'CRUD data operation endpoints',
88
- },
89
- {
90
- name: 'ui_endpoints',
91
- enabled: true,
92
- description: 'UI view metadata endpoints',
93
- },
94
- ],
95
- certified: false,
96
- },
97
- ],
98
-
99
- // Interfaces This Plugin Provides
100
- provides: [
101
- {
102
- id: 'com.objectstack.plugin.msw.interface.mock_server',
103
- name: 'ObjectStackServer',
104
- description: 'Mock server interface for testing',
105
- version: { major: 1, minor: 0, patch: 0 },
106
- stability: 'stable',
107
- methods: [
108
- {
109
- name: 'init',
110
- description: 'Initialize mock server with protocol implementation',
111
- parameters: [
112
- {
113
- name: 'protocol',
114
- type: 'IObjectStackProtocol',
115
- required: true,
116
- description: 'ObjectStack protocol implementation instance',
117
- },
118
- {
119
- name: 'logger',
120
- type: 'Logger',
121
- required: false,
122
- description: 'Optional logger instance',
123
- },
124
- ],
125
- returnType: 'void',
126
- async: false,
127
- },
128
- {
129
- name: 'findData',
130
- description: 'Mock data find operation',
131
- parameters: [
132
- {
133
- name: 'object',
134
- type: 'string',
135
- required: true,
136
- description: 'Object name',
137
- },
138
- {
139
- name: 'params',
140
- type: 'any',
141
- required: false,
142
- description: 'Query parameters',
143
- },
144
- ],
145
- returnType: 'Promise<{ status: number; data: any }>',
146
- async: true,
147
- },
148
- {
149
- name: 'getData',
150
- description: 'Mock data get operation',
151
- parameters: [
152
- {
153
- name: 'object',
154
- type: 'string',
155
- required: true,
156
- description: 'Object name',
157
- },
158
- {
159
- name: 'id',
160
- type: 'string',
161
- required: true,
162
- description: 'Record ID',
163
- },
164
- ],
165
- returnType: 'Promise<{ status: number; data: any }>',
166
- async: true,
167
- },
168
- {
169
- name: 'createData',
170
- description: 'Mock data create operation',
171
- parameters: [
172
- {
173
- name: 'object',
174
- type: 'string',
175
- required: true,
176
- description: 'Object name',
177
- },
178
- {
179
- name: 'data',
180
- type: 'any',
181
- required: true,
182
- description: 'Record data',
183
- },
184
- ],
185
- returnType: 'Promise<{ status: number; data: any }>',
186
- async: true,
187
- },
188
- {
189
- name: 'updateData',
190
- description: 'Mock data update operation',
191
- parameters: [
192
- {
193
- name: 'object',
194
- type: 'string',
195
- required: true,
196
- description: 'Object name',
197
- },
198
- {
199
- name: 'id',
200
- type: 'string',
201
- required: true,
202
- description: 'Record ID',
203
- },
204
- {
205
- name: 'data',
206
- type: 'any',
207
- required: true,
208
- description: 'Updated record data',
209
- },
210
- ],
211
- returnType: 'Promise<{ status: number; data: any }>',
212
- async: true,
213
- },
214
- {
215
- name: 'deleteData',
216
- description: 'Mock data delete operation',
217
- parameters: [
218
- {
219
- name: 'object',
220
- type: 'string',
221
- required: true,
222
- description: 'Object name',
223
- },
224
- {
225
- name: 'id',
226
- type: 'string',
227
- required: true,
228
- description: 'Record ID',
229
- },
230
- ],
231
- returnType: 'Promise<{ status: number; data: any }>',
232
- async: true,
233
- },
234
- ],
235
- },
236
- ],
237
-
238
- // Dependencies on Other Plugins/Services
239
- requires: [
240
- {
241
- pluginId: 'com.objectstack.engine.objectql',
242
- version: '^0.6.0',
243
- optional: false,
244
- reason: 'ObjectQL data engine for mock responses',
245
- requiredCapabilities: [
246
- 'com.objectstack.protocol.storage.v1',
247
- ],
248
- },
249
- ],
250
-
251
- // Extension Points This Plugin Defines
252
- extensionPoints: [
253
- {
254
- id: 'com.objectstack.plugin.msw.extension.custom_handler',
255
- name: 'Custom Request Handlers',
256
- description: 'Register custom MSW request handlers',
257
- type: 'action',
258
- cardinality: 'multiple',
259
- contract: {
260
- input: 'MSWHandler',
261
- description: 'MSW HTTP handler definition',
262
- },
263
- },
264
- ],
265
-
266
- // No extensions contributed to other plugins
267
- extensions: [],
268
- },
269
-
270
- contributes: {
271
- // No specific contributions (runtime plugin)
272
- },
273
- };
274
-
275
- export default MSWPlugin;
package/src/index.ts DELETED
@@ -1,48 +0,0 @@
1
- // Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2
-
3
- /**
4
- * @objectstack/plugin-msw
5
- *
6
- * MSW (Mock Service Worker) Plugin for ObjectStack Runtime
7
- *
8
- * This plugin enables seamless integration with Mock Service Worker for
9
- * testing and development environments. It automatically generates MSW
10
- * handlers for all ObjectStack API endpoints.
11
- *
12
- * @example
13
- * ```typescript
14
- * import { MSWPlugin, ObjectStackServer } from '@objectstack/plugin-msw';
15
- * import { ObjectStackRuntime } from '@objectstack/runtime';
16
- *
17
- * // Use with runtime
18
- * const runtime = new ObjectStackRuntime({
19
- * plugins: [
20
- * new MSWPlugin({
21
- * enableBrowser: true,
22
- * baseUrl: '/api/v1'
23
- * })
24
- * ]
25
- * });
26
- *
27
- * // Or use standalone in browser
28
- * import { setupWorker, http } from 'msw/browser';
29
- *
30
- * ObjectStackServer.init(protocol);
31
- *
32
- * const handlers = [
33
- * http.get('/api/user/:id', async ({ params }) => {
34
- * const result = await ObjectStackServer.getData('user', params.id);
35
- * return HttpResponse.json(result.data, { status: result.status });
36
- * })
37
- * ];
38
- *
39
- * const worker = setupWorker(...handlers);
40
- * await worker.start();
41
- * ```
42
- */
43
-
44
- export { MSWPlugin, ObjectStackServer } from './msw-plugin';
45
- export type { MSWPluginOptions } from './msw-plugin';
46
-
47
- // Re-export MSW types for convenience
48
- export type { HttpHandler, HttpResponse } from 'msw';
@@ -1,41 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { MSWPlugin, ObjectStackServer } from './msw-plugin';
3
-
4
- describe('MSWPlugin', () => {
5
- it('should initialize correctly', () => {
6
- const plugin = new MSWPlugin({ enableBrowser: false });
7
- expect(plugin.name).toBe('com.objectstack.plugin.msw');
8
- expect(plugin.version).toBe('0.9.0');
9
- });
10
-
11
- it('should handle protocol dynamic loading gracefully', async () => {
12
- // Mock context
13
- const context: any = {
14
- logger: { info: vi.fn(), debug: vi.fn(), warn: vi.fn() },
15
- getService: vi.fn().mockReturnValue(null), // No protocol service initially
16
- registerService: vi.fn()
17
- };
18
-
19
- const plugin = new MSWPlugin();
20
- await plugin.init(context);
21
- // It should try to load ObjectStackProtocolImplementation dynamically
22
- // Since we are in test environment, the dynamic import might fail or succeed depending on build
23
- // But we expect it not to crash
24
- });
25
- });
26
-
27
- describe('ObjectStackServer', () => {
28
- it('should throw if used before init', async () => {
29
- await expect(ObjectStackServer.findData('test')).rejects.toThrow('ObjectStackServer not initialized');
30
- });
31
-
32
- it('should delegate to protocol after init', async () => {
33
- const protocolMock: any = {
34
- findData: vi.fn().mockResolvedValue({ records: [] })
35
- };
36
- ObjectStackServer.init(protocolMock);
37
-
38
- await ObjectStackServer.findData('test');
39
- expect(protocolMock.findData).toHaveBeenCalled();
40
- });
41
- });