@objectstack/plugin-msw 1.0.0 โ 1.0.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 +32 -0
- package/README.md +20 -6
- package/dist/msw-plugin.d.ts +51 -201
- package/dist/msw-plugin.js +97 -457
- package/package.json +7 -6
- package/src/msw-plugin.ts +120 -508
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @objectstack/plugin-msw
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a0a6c85: Infrastructure and development tooling improvements
|
|
8
|
+
|
|
9
|
+
- Add changeset configuration for automated version management
|
|
10
|
+
- Add comprehensive GitHub Actions workflows (CI, CodeQL, linting, releases)
|
|
11
|
+
- Add development configuration files (.cursorrules, .github/prompts)
|
|
12
|
+
- Add documentation files (ARCHITECTURE.md, CONTRIBUTING.md, workflows docs)
|
|
13
|
+
- Update test script configuration in package.json
|
|
14
|
+
- Add @objectstack/cli to devDependencies for better development experience
|
|
15
|
+
|
|
16
|
+
- 109fc5b: Unified patch release to align all package versions.
|
|
17
|
+
- Updated dependencies [a0a6c85]
|
|
18
|
+
- Updated dependencies [109fc5b]
|
|
19
|
+
- @objectstack/spec@1.0.2
|
|
20
|
+
- @objectstack/core@1.0.2
|
|
21
|
+
- @objectstack/types@1.0.2
|
|
22
|
+
- @objectstack/objectql@1.0.2
|
|
23
|
+
- @objectstack/runtime@1.0.2
|
|
24
|
+
|
|
25
|
+
## 1.0.1
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies
|
|
30
|
+
- @objectstack/runtime@1.0.1
|
|
31
|
+
- @objectstack/spec@1.0.1
|
|
32
|
+
- @objectstack/types@1.0.1
|
|
33
|
+
- @objectstack/objectql@1.0.1
|
|
34
|
+
|
|
3
35
|
## 1.0.0
|
|
4
36
|
|
|
5
37
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -21,12 +21,17 @@ See [objectstack.config.ts](./objectstack.config.ts) for the complete capability
|
|
|
21
21
|
|
|
22
22
|
## Features
|
|
23
23
|
|
|
24
|
-
- ๐ฏ **
|
|
25
|
-
- ๐ **
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
24
|
+
- ๐ฏ **Unified Dispatcher**: Uses `@objectstack/runtime`'s `HttpDispatcher` to ensure mocks behave exactly like the real server.
|
|
25
|
+
- ๐ **Full Protocol Support**: Mocks **all** Runtime endpoints:
|
|
26
|
+
- Auth (`/auth`)
|
|
27
|
+
- Metadata (`/metadata`)
|
|
28
|
+
- Data (`/data` - with filtering, batching, relations)
|
|
29
|
+
- Storage (`/storage`)
|
|
30
|
+
- Analytics (`/analytics`)
|
|
31
|
+
- Automation (`/automation`)
|
|
32
|
+
- ๐ **Universal Support**: Works in Browser (Service Worker) and Node.js (Interceptor).
|
|
33
|
+
- ๐จ **Custom Handlers**: Easily inject custom MSW handlers that take precedence.
|
|
34
|
+
- ๐ **TypeScript First**: Fully typed configuration.
|
|
30
35
|
|
|
31
36
|
## Installation
|
|
32
37
|
|
|
@@ -44,12 +49,21 @@ import { ObjectKernel } from '@objectstack/runtime';
|
|
|
44
49
|
|
|
45
50
|
const kernel = new ObjectKernel();
|
|
46
51
|
|
|
52
|
+
// The MSW Plugin will initialize the HttpDispatcher and intercept requests
|
|
47
53
|
kernel.use(new MSWPlugin({
|
|
48
54
|
enableBrowser: true,
|
|
49
55
|
baseUrl: '/api/v1',
|
|
50
56
|
logRequests: true
|
|
51
57
|
}));
|
|
52
58
|
|
|
59
|
+
await kernel.start();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Architecture
|
|
63
|
+
|
|
64
|
+
The plugin uses the `HttpDispatcher` from the Runtime to process requests intercepted by MSW. This means your mock server runs the **actual** ObjectStack business logic (permissions, validation, flow execution) in-memory, providing a high-fidelity simulation of the backend.
|
|
65
|
+
}));
|
|
66
|
+
|
|
53
67
|
await kernel.bootstrap();
|
|
54
68
|
```
|
|
55
69
|
|
package/dist/msw-plugin.d.ts
CHANGED
|
@@ -18,209 +18,9 @@ export interface MSWPluginOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
logRequests?: boolean;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
* ObjectStack Server Mock - Provides mock database functionality
|
|
23
|
-
*/
|
|
24
|
-
export declare class ObjectStackServer {
|
|
25
|
-
private static protocol;
|
|
26
|
-
private static logger;
|
|
27
|
-
static init(protocol: ObjectStackProtocol, logger?: any): void;
|
|
28
|
-
static findData(object: string, params?: any): Promise<{
|
|
29
|
-
status: number;
|
|
30
|
-
data: {
|
|
31
|
-
object: string;
|
|
32
|
-
records: Record<string, any>[];
|
|
33
|
-
total?: number | undefined;
|
|
34
|
-
hasMore?: boolean | undefined;
|
|
35
|
-
};
|
|
36
|
-
}>;
|
|
37
|
-
static getData(object: string, id: string): Promise<{
|
|
38
|
-
status: number;
|
|
39
|
-
data: {
|
|
40
|
-
object: string;
|
|
41
|
-
record: Record<string, any>;
|
|
42
|
-
id: string;
|
|
43
|
-
};
|
|
44
|
-
} | {
|
|
45
|
-
status: number;
|
|
46
|
-
data: {
|
|
47
|
-
error: string;
|
|
48
|
-
};
|
|
49
|
-
}>;
|
|
50
|
-
static createData(object: string, data: any): Promise<{
|
|
51
|
-
status: number;
|
|
52
|
-
data: {
|
|
53
|
-
object: string;
|
|
54
|
-
record: Record<string, any>;
|
|
55
|
-
id: string;
|
|
56
|
-
};
|
|
57
|
-
} | {
|
|
58
|
-
status: number;
|
|
59
|
-
data: {
|
|
60
|
-
error: string;
|
|
61
|
-
};
|
|
62
|
-
}>;
|
|
63
|
-
static updateData(object: string, id: string, data: any): Promise<{
|
|
64
|
-
status: number;
|
|
65
|
-
data: {
|
|
66
|
-
object: string;
|
|
67
|
-
record: Record<string, any>;
|
|
68
|
-
id: string;
|
|
69
|
-
};
|
|
70
|
-
} | {
|
|
71
|
-
status: number;
|
|
72
|
-
data: {
|
|
73
|
-
error: string;
|
|
74
|
-
};
|
|
75
|
-
}>;
|
|
76
|
-
static deleteData(object: string, id: string): Promise<{
|
|
77
|
-
status: number;
|
|
78
|
-
data: {
|
|
79
|
-
object: string;
|
|
80
|
-
id: string;
|
|
81
|
-
success: boolean;
|
|
82
|
-
};
|
|
83
|
-
} | {
|
|
84
|
-
status: number;
|
|
85
|
-
data: {
|
|
86
|
-
error: string;
|
|
87
|
-
};
|
|
88
|
-
}>;
|
|
89
|
-
static analyticsQuery(request: any): Promise<{
|
|
90
|
-
status: number;
|
|
91
|
-
data: {
|
|
92
|
-
data: {
|
|
93
|
-
fields: {
|
|
94
|
-
type: string;
|
|
95
|
-
name: string;
|
|
96
|
-
}[];
|
|
97
|
-
rows: Record<string, any>[];
|
|
98
|
-
sql?: string | undefined;
|
|
99
|
-
};
|
|
100
|
-
success: boolean;
|
|
101
|
-
error?: {
|
|
102
|
-
message: string;
|
|
103
|
-
code: string;
|
|
104
|
-
category?: string | undefined;
|
|
105
|
-
requestId?: string | undefined;
|
|
106
|
-
details?: any;
|
|
107
|
-
} | undefined;
|
|
108
|
-
meta?: {
|
|
109
|
-
timestamp: string;
|
|
110
|
-
duration?: number | undefined;
|
|
111
|
-
requestId?: string | undefined;
|
|
112
|
-
traceId?: string | undefined;
|
|
113
|
-
} | undefined;
|
|
114
|
-
};
|
|
115
|
-
} | {
|
|
116
|
-
status: number;
|
|
117
|
-
data: {
|
|
118
|
-
error: string;
|
|
119
|
-
};
|
|
120
|
-
}>;
|
|
121
|
-
static getAnalyticsMeta(request: any): Promise<{
|
|
122
|
-
status: number;
|
|
123
|
-
data: {
|
|
124
|
-
data: {
|
|
125
|
-
cubes: {
|
|
126
|
-
dimensions: Record<string, {
|
|
127
|
-
type: "string" | "number" | "boolean" | "time" | "geo";
|
|
128
|
-
label: string;
|
|
129
|
-
name: string;
|
|
130
|
-
sql: string;
|
|
131
|
-
description?: string | undefined;
|
|
132
|
-
granularities?: ("second" | "minute" | "hour" | "day" | "week" | "month" | "quarter" | "year")[] | undefined;
|
|
133
|
-
}>;
|
|
134
|
-
name: string;
|
|
135
|
-
sql: string;
|
|
136
|
-
measures: Record<string, {
|
|
137
|
-
type: "string" | "number" | "boolean" | "count" | "sum" | "avg" | "min" | "max" | "count_distinct";
|
|
138
|
-
label: string;
|
|
139
|
-
name: string;
|
|
140
|
-
sql: string;
|
|
141
|
-
description?: string | undefined;
|
|
142
|
-
format?: string | undefined;
|
|
143
|
-
filters?: {
|
|
144
|
-
sql: string;
|
|
145
|
-
}[] | undefined;
|
|
146
|
-
}>;
|
|
147
|
-
public: boolean;
|
|
148
|
-
joins?: Record<string, {
|
|
149
|
-
name: string;
|
|
150
|
-
sql: string;
|
|
151
|
-
relationship: "one_to_one" | "one_to_many" | "many_to_one";
|
|
152
|
-
}> | undefined;
|
|
153
|
-
description?: string | undefined;
|
|
154
|
-
title?: string | undefined;
|
|
155
|
-
refreshKey?: {
|
|
156
|
-
every?: string | undefined;
|
|
157
|
-
sql?: string | undefined;
|
|
158
|
-
} | undefined;
|
|
159
|
-
}[];
|
|
160
|
-
};
|
|
161
|
-
success: boolean;
|
|
162
|
-
error?: {
|
|
163
|
-
message: string;
|
|
164
|
-
code: string;
|
|
165
|
-
category?: string | undefined;
|
|
166
|
-
requestId?: string | undefined;
|
|
167
|
-
details?: any;
|
|
168
|
-
} | undefined;
|
|
169
|
-
meta?: {
|
|
170
|
-
timestamp: string;
|
|
171
|
-
duration?: number | undefined;
|
|
172
|
-
requestId?: string | undefined;
|
|
173
|
-
traceId?: string | undefined;
|
|
174
|
-
} | undefined;
|
|
175
|
-
};
|
|
176
|
-
} | {
|
|
177
|
-
status: number;
|
|
178
|
-
data: {
|
|
179
|
-
error: string;
|
|
180
|
-
};
|
|
181
|
-
}>;
|
|
182
|
-
static triggerAutomation(request: any): Promise<{
|
|
183
|
-
status: number;
|
|
184
|
-
data: {
|
|
185
|
-
success: boolean;
|
|
186
|
-
result?: any;
|
|
187
|
-
jobId?: string | undefined;
|
|
188
|
-
};
|
|
189
|
-
} | {
|
|
190
|
-
status: number;
|
|
191
|
-
data: {
|
|
192
|
-
error: string;
|
|
193
|
-
};
|
|
194
|
-
}>;
|
|
195
|
-
static getUser(id: string): Promise<{
|
|
196
|
-
status: number;
|
|
197
|
-
data: {
|
|
198
|
-
object: string;
|
|
199
|
-
record: Record<string, any>;
|
|
200
|
-
id: string;
|
|
201
|
-
};
|
|
202
|
-
} | {
|
|
203
|
-
status: number;
|
|
204
|
-
data: {
|
|
205
|
-
error: string;
|
|
206
|
-
};
|
|
207
|
-
}>;
|
|
208
|
-
static createUser(data: any): Promise<{
|
|
209
|
-
status: number;
|
|
210
|
-
data: {
|
|
211
|
-
object: string;
|
|
212
|
-
record: Record<string, any>;
|
|
213
|
-
id: string;
|
|
214
|
-
};
|
|
215
|
-
} | {
|
|
216
|
-
status: number;
|
|
217
|
-
data: {
|
|
218
|
-
error: string;
|
|
219
|
-
};
|
|
220
|
-
}>;
|
|
221
|
-
}
|
|
222
21
|
/**
|
|
223
22
|
* MSW Plugin for ObjectStack
|
|
23
|
+
|
|
224
24
|
*
|
|
225
25
|
* This plugin enables Mock Service Worker integration for testing and development.
|
|
226
26
|
* It automatically mocks API endpoints using the ObjectStack runtime protocol.
|
|
@@ -244,6 +44,7 @@ export declare class MSWPlugin implements Plugin {
|
|
|
244
44
|
private worker;
|
|
245
45
|
private handlers;
|
|
246
46
|
private protocol?;
|
|
47
|
+
private dispatcher?;
|
|
247
48
|
constructor(options?: MSWPluginOptions);
|
|
248
49
|
/**
|
|
249
50
|
* Init phase
|
|
@@ -278,3 +79,52 @@ export declare class MSWPlugin implements Plugin {
|
|
|
278
79
|
*/
|
|
279
80
|
getHandlers(): any[];
|
|
280
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Static helper for interacting with ObjectStack protocol in MSW handlers
|
|
84
|
+
*/
|
|
85
|
+
export declare class ObjectStackServer {
|
|
86
|
+
private static protocol;
|
|
87
|
+
static init(protocol: ObjectStackProtocol): void;
|
|
88
|
+
private static getProtocol;
|
|
89
|
+
static findData(objectName: string, query?: any): Promise<{
|
|
90
|
+
data: {
|
|
91
|
+
object: string;
|
|
92
|
+
records: Record<string, any>[];
|
|
93
|
+
total?: number | undefined;
|
|
94
|
+
hasMore?: boolean | undefined;
|
|
95
|
+
};
|
|
96
|
+
status: number;
|
|
97
|
+
}>;
|
|
98
|
+
static getData(objectName: string, id: string): Promise<{
|
|
99
|
+
data: {
|
|
100
|
+
object: string;
|
|
101
|
+
record: Record<string, any>;
|
|
102
|
+
id: string;
|
|
103
|
+
};
|
|
104
|
+
status: number;
|
|
105
|
+
}>;
|
|
106
|
+
static createData(objectName: string, data: any): Promise<{
|
|
107
|
+
data: {
|
|
108
|
+
object: string;
|
|
109
|
+
record: Record<string, any>;
|
|
110
|
+
id: string;
|
|
111
|
+
};
|
|
112
|
+
status: number;
|
|
113
|
+
}>;
|
|
114
|
+
static updateData(objectName: string, id: string, data: any): Promise<{
|
|
115
|
+
data: {
|
|
116
|
+
object: string;
|
|
117
|
+
record: Record<string, any>;
|
|
118
|
+
id: string;
|
|
119
|
+
};
|
|
120
|
+
status: number;
|
|
121
|
+
}>;
|
|
122
|
+
static deleteData(objectName: string, id: string): Promise<{
|
|
123
|
+
data: {
|
|
124
|
+
object: string;
|
|
125
|
+
id: string;
|
|
126
|
+
success: boolean;
|
|
127
|
+
};
|
|
128
|
+
status: number;
|
|
129
|
+
}>;
|
|
130
|
+
}
|