@hamak/ui-remote-resource-impl 0.4.19
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/dist/es2015/index.js +33 -0
- package/dist/es2015/middleware/entity-middleware.js +209 -0
- package/dist/es2015/middleware/entity-sync-middleware.js +36 -0
- package/dist/es2015/middleware/resource-middleware.js +111 -0
- package/dist/es2015/middleware/sync-middleware.js +85 -0
- package/dist/es2015/plugin/resource-plugin-factory.js +151 -0
- package/dist/es2015/providers/mock-resource-provider.js +215 -0
- package/dist/es2015/providers/rest-resource-provider.js +140 -0
- package/dist/es2015/registry/entity-registry.js +50 -0
- package/dist/es2015/registry/resource-registry.js +68 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/middleware/entity-middleware.d.ts +13 -0
- package/dist/middleware/entity-middleware.d.ts.map +1 -0
- package/dist/middleware/entity-middleware.js +221 -0
- package/dist/middleware/entity-sync-middleware.d.ts +7 -0
- package/dist/middleware/entity-sync-middleware.d.ts.map +1 -0
- package/dist/middleware/entity-sync-middleware.js +31 -0
- package/dist/middleware/resource-middleware.d.ts +13 -0
- package/dist/middleware/resource-middleware.d.ts.map +1 -0
- package/dist/middleware/resource-middleware.js +97 -0
- package/dist/middleware/sync-middleware.d.ts +12 -0
- package/dist/middleware/sync-middleware.d.ts.map +1 -0
- package/dist/middleware/sync-middleware.js +80 -0
- package/dist/plugin/resource-plugin-factory.d.ts +31 -0
- package/dist/plugin/resource-plugin-factory.d.ts.map +1 -0
- package/dist/plugin/resource-plugin-factory.js +131 -0
- package/dist/providers/mock-resource-provider.d.ts +147 -0
- package/dist/providers/mock-resource-provider.d.ts.map +1 -0
- package/dist/providers/mock-resource-provider.js +196 -0
- package/dist/providers/rest-resource-provider.d.ts +51 -0
- package/dist/providers/rest-resource-provider.d.ts.map +1 -0
- package/dist/providers/rest-resource-provider.js +117 -0
- package/dist/registry/entity-registry.d.ts +54 -0
- package/dist/registry/entity-registry.d.ts.map +1 -0
- package/dist/registry/entity-registry.js +46 -0
- package/dist/registry/resource-registry.d.ts +80 -0
- package/dist/registry/resource-registry.d.ts.map +1 -0
- package/dist/registry/resource-registry.js +64 -0
- package/package.json +57 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MockResourceProvider = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* Mock Resource Provider for testing
|
|
15
|
+
*/
|
|
16
|
+
class MockResourceProvider {
|
|
17
|
+
constructor(config = {}) {
|
|
18
|
+
this.type = 'mock';
|
|
19
|
+
this.callHistory = [];
|
|
20
|
+
this.mocks = config.mocks || {};
|
|
21
|
+
this.defaultDelay = config.defaultDelay || 0;
|
|
22
|
+
this.defaultResponse = config.defaultResponse || { message: 'Mock response' };
|
|
23
|
+
this.trackHistory = config.trackHistory !== false; // Default true
|
|
24
|
+
this.globalError = config.globalError;
|
|
25
|
+
this.onAnyCall = config.onAnyCall;
|
|
26
|
+
}
|
|
27
|
+
call(endpoint, params, operation) {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
// Invoke global callback
|
|
31
|
+
(_a = this.onAnyCall) === null || _a === void 0 ? void 0 : _a.call(this, endpoint, params, operation);
|
|
32
|
+
// Find matching mock config
|
|
33
|
+
const mockConfig = this.findMockConfig(endpoint);
|
|
34
|
+
// Determine delay
|
|
35
|
+
const delay = (_b = mockConfig === null || mockConfig === void 0 ? void 0 : mockConfig.delay) !== null && _b !== void 0 ? _b : this.defaultDelay;
|
|
36
|
+
// Simulate delay
|
|
37
|
+
if (delay > 0) {
|
|
38
|
+
yield this.sleep(delay);
|
|
39
|
+
}
|
|
40
|
+
// Record call start
|
|
41
|
+
const historyEntry = {
|
|
42
|
+
timestamp: Date.now(),
|
|
43
|
+
endpoint,
|
|
44
|
+
params,
|
|
45
|
+
operation
|
|
46
|
+
};
|
|
47
|
+
try {
|
|
48
|
+
// Check for global error
|
|
49
|
+
if (this.globalError) {
|
|
50
|
+
throw this.createError(this.globalError);
|
|
51
|
+
}
|
|
52
|
+
// Check for endpoint-specific error
|
|
53
|
+
if (mockConfig === null || mockConfig === void 0 ? void 0 : mockConfig.error) {
|
|
54
|
+
throw this.createError(mockConfig.error);
|
|
55
|
+
}
|
|
56
|
+
// Invoke endpoint callback
|
|
57
|
+
(_c = mockConfig === null || mockConfig === void 0 ? void 0 : mockConfig.onCall) === null || _c === void 0 ? void 0 : _c.call(mockConfig, endpoint, params, operation);
|
|
58
|
+
// Generate response
|
|
59
|
+
const result = yield this.generateResponse(endpoint, params, operation, mockConfig);
|
|
60
|
+
// Record success
|
|
61
|
+
if (this.trackHistory) {
|
|
62
|
+
historyEntry.result = result;
|
|
63
|
+
this.callHistory.push(historyEntry);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
// Record error
|
|
69
|
+
if (this.trackHistory) {
|
|
70
|
+
historyEntry.error = error;
|
|
71
|
+
this.callHistory.push(historyEntry);
|
|
72
|
+
}
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Find mock config for endpoint (supports pattern matching)
|
|
79
|
+
*/
|
|
80
|
+
findMockConfig(endpoint) {
|
|
81
|
+
// Exact match
|
|
82
|
+
if (this.mocks[endpoint]) {
|
|
83
|
+
return this.mocks[endpoint];
|
|
84
|
+
}
|
|
85
|
+
// Pattern matching (e.g., "/api/users/:id" matches "/api/users/123")
|
|
86
|
+
for (const [pattern, config] of Object.entries(this.mocks)) {
|
|
87
|
+
if (this.matchesPattern(endpoint, pattern)) {
|
|
88
|
+
return config;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Simple pattern matching for endpoints
|
|
95
|
+
*/
|
|
96
|
+
matchesPattern(endpoint, pattern) {
|
|
97
|
+
const patternRegex = pattern.replace(/:[^/]+/g, '[^/]+');
|
|
98
|
+
const regex = new RegExp(`^${patternRegex}$`);
|
|
99
|
+
return regex.test(endpoint);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Generate response based on config
|
|
103
|
+
*/
|
|
104
|
+
generateResponse(endpoint, params, operation, mockConfig) {
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
var _a, _b;
|
|
107
|
+
// Use custom response generator if provided
|
|
108
|
+
if (mockConfig === null || mockConfig === void 0 ? void 0 : mockConfig.responseGenerator) {
|
|
109
|
+
const result = yield mockConfig.responseGenerator(endpoint, params, operation);
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
// Use configured data
|
|
113
|
+
const data = (_a = mockConfig === null || mockConfig === void 0 ? void 0 : mockConfig.data) !== null && _a !== void 0 ? _a : this.defaultResponse;
|
|
114
|
+
const metadata = (_b = mockConfig === null || mockConfig === void 0 ? void 0 : mockConfig.metadata) !== null && _b !== void 0 ? _b : {
|
|
115
|
+
status: 200,
|
|
116
|
+
headers: { 'content-type': 'application/json' }
|
|
117
|
+
};
|
|
118
|
+
return { data, metadata };
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create error object
|
|
123
|
+
*/
|
|
124
|
+
createError(errorConfig) {
|
|
125
|
+
const error = new Error(errorConfig.message);
|
|
126
|
+
error.code = errorConfig.code;
|
|
127
|
+
error.details = errorConfig.details;
|
|
128
|
+
return error;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Sleep helper
|
|
132
|
+
*/
|
|
133
|
+
sleep(ms) {
|
|
134
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
135
|
+
}
|
|
136
|
+
// ========== Testing Utilities ==========
|
|
137
|
+
/**
|
|
138
|
+
* Get call history
|
|
139
|
+
*/
|
|
140
|
+
getCallHistory() {
|
|
141
|
+
return [...this.callHistory];
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Get calls for specific endpoint
|
|
145
|
+
*/
|
|
146
|
+
getCallsForEndpoint(endpoint) {
|
|
147
|
+
return this.callHistory.filter((entry) => entry.endpoint === endpoint);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Get calls for specific operation
|
|
151
|
+
*/
|
|
152
|
+
getCallsForOperation(operation) {
|
|
153
|
+
return this.callHistory.filter((entry) => entry.operation === operation);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Clear call history
|
|
157
|
+
*/
|
|
158
|
+
clearHistory() {
|
|
159
|
+
this.callHistory = [];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get last call
|
|
163
|
+
*/
|
|
164
|
+
getLastCall() {
|
|
165
|
+
return this.callHistory[this.callHistory.length - 1];
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Check if endpoint was called
|
|
169
|
+
*/
|
|
170
|
+
wasEndpointCalled(endpoint, operation) {
|
|
171
|
+
return this.callHistory.some((entry) => entry.endpoint === endpoint && (!operation || entry.operation === operation));
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get call count for endpoint
|
|
175
|
+
*/
|
|
176
|
+
getCallCount(endpoint, operation) {
|
|
177
|
+
if (!endpoint) {
|
|
178
|
+
return this.callHistory.length;
|
|
179
|
+
}
|
|
180
|
+
return this.callHistory.filter((entry) => entry.endpoint === endpoint && (!operation || entry.operation === operation)).length;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Add or update mock configuration
|
|
184
|
+
*/
|
|
185
|
+
setMock(endpoint, config) {
|
|
186
|
+
this.mocks[endpoint] = config;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Remove mock configuration
|
|
190
|
+
*/
|
|
191
|
+
removeMock(endpoint) {
|
|
192
|
+
delete this.mocks[endpoint];
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Set global error (all calls will fail)
|
|
196
|
+
*/
|
|
197
|
+
setGlobalError(error) {
|
|
198
|
+
this.globalError = error;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Clear global error
|
|
202
|
+
*/
|
|
203
|
+
clearGlobalError() {
|
|
204
|
+
this.globalError = undefined;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Reset provider to initial state
|
|
208
|
+
*/
|
|
209
|
+
reset() {
|
|
210
|
+
this.clearHistory();
|
|
211
|
+
this.clearGlobalError();
|
|
212
|
+
this.mocks = {};
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.MockResourceProvider = MockResourceProvider;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.RestResourceProvider = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
/**
|
|
18
|
+
* REST API resource provider using Axios
|
|
19
|
+
*/
|
|
20
|
+
class RestResourceProvider {
|
|
21
|
+
constructor(config = {}) {
|
|
22
|
+
this.type = 'rest';
|
|
23
|
+
this.axios =
|
|
24
|
+
config.axiosInstance ||
|
|
25
|
+
axios_1.default.create({
|
|
26
|
+
baseURL: config.baseUrl,
|
|
27
|
+
timeout: config.timeout || 30000,
|
|
28
|
+
headers: Object.assign({ 'Content-Type': 'application/json' }, config.headers)
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Execute a resource call
|
|
33
|
+
*/
|
|
34
|
+
call(endpoint, params, operation) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
switch (operation) {
|
|
37
|
+
case 'fetch':
|
|
38
|
+
return this.executeFetch(endpoint, params);
|
|
39
|
+
case 'create':
|
|
40
|
+
return this.executeCreate(endpoint, params);
|
|
41
|
+
case 'update':
|
|
42
|
+
return this.executeUpdate(endpoint, params);
|
|
43
|
+
case 'delete':
|
|
44
|
+
return this.executeDelete(endpoint, params);
|
|
45
|
+
default:
|
|
46
|
+
throw new Error(`Unknown operation: ${operation}`);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Execute fetch operation (GET)
|
|
52
|
+
*/
|
|
53
|
+
executeFetch(endpoint, params) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const url = this.buildUrl(endpoint, params.params);
|
|
56
|
+
const response = yield this.axios.get(url, {
|
|
57
|
+
params: params.query,
|
|
58
|
+
headers: params.headers
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
data: response.data,
|
|
62
|
+
metadata: {
|
|
63
|
+
status: response.status,
|
|
64
|
+
headers: response.headers
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Execute create operation (POST)
|
|
71
|
+
*/
|
|
72
|
+
executeCreate(endpoint, params) {
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
const response = yield this.axios.post(endpoint, params.body, {
|
|
75
|
+
params: params.query,
|
|
76
|
+
headers: params.headers
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
data: response.data,
|
|
80
|
+
metadata: {
|
|
81
|
+
status: response.status,
|
|
82
|
+
headers: response.headers
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Execute update operation (PUT)
|
|
89
|
+
*/
|
|
90
|
+
executeUpdate(endpoint, params) {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
const url = this.buildUrl(endpoint, params.params);
|
|
93
|
+
const response = yield this.axios.put(url, params.body, {
|
|
94
|
+
params: params.query,
|
|
95
|
+
headers: params.headers
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
data: response.data,
|
|
99
|
+
metadata: {
|
|
100
|
+
status: response.status,
|
|
101
|
+
headers: response.headers
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Execute delete operation (DELETE)
|
|
108
|
+
*/
|
|
109
|
+
executeDelete(endpoint, params) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const url = this.buildUrl(endpoint, params.params);
|
|
112
|
+
const response = yield this.axios.delete(url, {
|
|
113
|
+
params: params.query,
|
|
114
|
+
headers: params.headers
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
data: response.data,
|
|
118
|
+
metadata: {
|
|
119
|
+
status: response.status,
|
|
120
|
+
headers: response.headers
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Build URL with path parameters
|
|
127
|
+
* Replaces :param placeholders with actual values
|
|
128
|
+
* Example: /users/:id + { id: "123" } → /users/123
|
|
129
|
+
*/
|
|
130
|
+
buildUrl(endpoint, params) {
|
|
131
|
+
if (!params)
|
|
132
|
+
return endpoint;
|
|
133
|
+
let url = endpoint;
|
|
134
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
135
|
+
url = url.replace(`:${key}`, String(value));
|
|
136
|
+
});
|
|
137
|
+
return url;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.RestResourceProvider = RestResourceProvider;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Entity registry implementation
|
|
6
|
+
* Manages entity definitions
|
|
7
|
+
*/
|
|
8
|
+
class EntityRegistry {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.entities = new Map();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register an entity definition
|
|
14
|
+
*/
|
|
15
|
+
registerEntity(definition) {
|
|
16
|
+
// Validate key schema
|
|
17
|
+
if (!definition.keySchema.fields || definition.keySchema.fields.length === 0) {
|
|
18
|
+
throw new Error(`Entity "${definition.id}" must have at least one key field in keySchema.fields`);
|
|
19
|
+
}
|
|
20
|
+
if (this.entities.has(definition.id)) {
|
|
21
|
+
console.warn(`Entity "${definition.id}" is already registered. Overwriting.`);
|
|
22
|
+
}
|
|
23
|
+
this.entities.set(definition.id, definition);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Unregister an entity definition
|
|
27
|
+
*/
|
|
28
|
+
unregisterEntity(id) {
|
|
29
|
+
this.entities.delete(id);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get entity definition by ID
|
|
33
|
+
*/
|
|
34
|
+
getEntity(id) {
|
|
35
|
+
return this.entities.get(id);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get all registered entities
|
|
39
|
+
*/
|
|
40
|
+
getAllEntities() {
|
|
41
|
+
return Array.from(this.entities.values());
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check if entity exists
|
|
45
|
+
*/
|
|
46
|
+
hasEntity(id) {
|
|
47
|
+
return this.entities.has(id);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.EntityRegistry = EntityRegistry;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceRegistry = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Resource registry implementation
|
|
6
|
+
* Manages resource endpoint definitions and providers
|
|
7
|
+
*/
|
|
8
|
+
class ResourceRegistry {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.endpoints = new Map();
|
|
11
|
+
this.providers = new Map();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Register a resource endpoint
|
|
15
|
+
*/
|
|
16
|
+
registerEndpoint(definition) {
|
|
17
|
+
if (this.endpoints.has(definition.id)) {
|
|
18
|
+
console.warn(`Resource endpoint "${definition.id}" is already registered. Overwriting.`);
|
|
19
|
+
}
|
|
20
|
+
this.endpoints.set(definition.id, definition);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Unregister a resource endpoint
|
|
24
|
+
*/
|
|
25
|
+
unregisterEndpoint(id) {
|
|
26
|
+
this.endpoints.delete(id);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get endpoint definition by ID
|
|
30
|
+
*/
|
|
31
|
+
getEndpoint(id) {
|
|
32
|
+
return this.endpoints.get(id);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get all registered endpoints
|
|
36
|
+
*/
|
|
37
|
+
getAllEndpoints() {
|
|
38
|
+
return Array.from(this.endpoints.values());
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Check if endpoint exists
|
|
42
|
+
*/
|
|
43
|
+
hasEndpoint(id) {
|
|
44
|
+
return this.endpoints.has(id);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Register a resource provider
|
|
48
|
+
*/
|
|
49
|
+
registerProvider(provider) {
|
|
50
|
+
if (this.providers.has(provider.type)) {
|
|
51
|
+
console.warn(`Resource provider "${provider.type}" is already registered. Overwriting.`);
|
|
52
|
+
}
|
|
53
|
+
this.providers.set(provider.type, provider);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get provider by type
|
|
57
|
+
*/
|
|
58
|
+
getProvider(type) {
|
|
59
|
+
return this.providers.get(type);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get all registered providers
|
|
63
|
+
*/
|
|
64
|
+
getAllProviders() {
|
|
65
|
+
return Array.from(this.providers.values());
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.ResourceRegistry = ResourceRegistry;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { createResourcePlugin } from './plugin/resource-plugin-factory';
|
|
2
|
+
export type { PluginModule } from './plugin/resource-plugin-factory';
|
|
3
|
+
export { RESOURCE_REGISTRY_TOKEN, ENTITY_REGISTRY_TOKEN } from './plugin/resource-plugin-factory';
|
|
4
|
+
export { STORE_MANAGER_TOKEN, MIDDLEWARE_REGISTRY_TOKEN, STORE_EXTENSIONS_TOKEN } from '@hamak/ui-store-api';
|
|
5
|
+
export { RestResourceProvider } from './providers/rest-resource-provider';
|
|
6
|
+
export type { RestProviderConfig } from './providers/rest-resource-provider';
|
|
7
|
+
export { MockResourceProvider } from './providers/mock-resource-provider';
|
|
8
|
+
export type { MockProviderConfig, EndpointMockConfig, MockConfigMap, MockCallHistoryEntry } from './providers/mock-resource-provider';
|
|
9
|
+
export { ResourceRegistry } from './registry/resource-registry';
|
|
10
|
+
export { EntityRegistry } from './registry/entity-registry';
|
|
11
|
+
export { createResourceMiddleware } from './middleware/resource-middleware';
|
|
12
|
+
export { createSyncMiddleware } from './middleware/sync-middleware';
|
|
13
|
+
export { createEntityMiddleware } from './middleware/entity-middleware';
|
|
14
|
+
export { createEntitySyncMiddleware } from './middleware/entity-sync-middleware';
|
|
15
|
+
export type { FileSystemNodeActions } from '@hamak/ui-store-impl';
|
|
16
|
+
export type { ResourceOperation, EntityKey, ErrorObject, RemoteResourceAttributes, EntityAttributes } from '@hamak/ui-remote-resource-api';
|
|
17
|
+
export type { IResourceProvider, ResourceCallParams, ResourceCallResult, ResourceEndpointDefinition, PayloadMapper, ResponseTransformer, EntityDefinition, EntityKeySchema, EntityKeyMapper, EntityPathGenerator, ResourcePluginConfig } from '@hamak/ui-remote-resource-spi';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,YAAY,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACtB,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EACL,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,YAAY,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,YAAY,EACV,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACrB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,qCAAqC,CAAC;AAGjF,YAAY,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAGlE,YAAY,EACV,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,+BAA+B,CAAC;AAGvC,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,0BAA0B,EAC1B,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,+BAA+B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Plugin factory (main export)
|
|
2
|
+
export { createResourcePlugin } from './plugin/resource-plugin-factory';
|
|
3
|
+
export { RESOURCE_REGISTRY_TOKEN, ENTITY_REGISTRY_TOKEN } from './plugin/resource-plugin-factory';
|
|
4
|
+
// Re-export store tokens from ui-store-api for convenience
|
|
5
|
+
export { STORE_MANAGER_TOKEN, MIDDLEWARE_REGISTRY_TOKEN, STORE_EXTENSIONS_TOKEN } from '@hamak/ui-store-api';
|
|
6
|
+
// Built-in providers (exported for convenience and testing)
|
|
7
|
+
export { RestResourceProvider } from './providers/rest-resource-provider';
|
|
8
|
+
export { MockResourceProvider } from './providers/mock-resource-provider';
|
|
9
|
+
// Registry implementations (internal, but exported for testing)
|
|
10
|
+
export { ResourceRegistry } from './registry/resource-registry';
|
|
11
|
+
export { EntityRegistry } from './registry/entity-registry';
|
|
12
|
+
// Middleware factories (internal, but exported for advanced use cases)
|
|
13
|
+
export { createResourceMiddleware } from './middleware/resource-middleware';
|
|
14
|
+
export { createSyncMiddleware } from './middleware/sync-middleware';
|
|
15
|
+
export { createEntityMiddleware } from './middleware/entity-middleware';
|
|
16
|
+
export { createEntitySyncMiddleware } from './middleware/entity-sync-middleware';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Middleware } from 'redux';
|
|
2
|
+
import { type EntityAction } from '@hamak/ui-remote-resource-api';
|
|
3
|
+
export interface EntityMiddlewareConfig {
|
|
4
|
+
entityRegistry: any;
|
|
5
|
+
fsSliceName: string;
|
|
6
|
+
onError?: (error: any, action: EntityAction) => void;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Entity middleware
|
|
10
|
+
* Translates entity actions to resource actions
|
|
11
|
+
*/
|
|
12
|
+
export declare function createEntityMiddleware<S = any>(config: EntityMiddlewareConfig): Middleware<{}, S>;
|
|
13
|
+
//# sourceMappingURL=entity-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/entity-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACxC,OAAO,EAGL,KAAK,YAAY,EAMlB,MAAM,+BAA+B,CAAC;AAGvC,MAAM,WAAW,sBAAsB;IACrC,cAAc,EAAE,GAAG,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;CACtD;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,GAAG,EAC5C,MAAM,EAAE,sBAAsB,GAC7B,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC,CAgCnB"}
|