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