@hamak/ui-remote-resource 0.5.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/dist/api/actions/entity-action-factory.d.ts +28 -0
- package/dist/api/actions/entity-action-factory.d.ts.map +1 -0
- package/dist/api/actions/entity-action-factory.js +62 -0
- package/dist/api/actions/entity-action-types.d.ts +104 -0
- package/dist/api/actions/entity-action-types.d.ts.map +1 -0
- package/dist/api/actions/entity-action-types.js +16 -0
- package/dist/api/actions/resource-action-factory.d.ts +40 -0
- package/dist/api/actions/resource-action-factory.d.ts.map +1 -0
- package/dist/api/actions/resource-action-factory.js +93 -0
- package/dist/api/actions/resource-action-types.d.ts +105 -0
- package/dist/api/actions/resource-action-types.d.ts.map +1 -0
- package/dist/api/actions/resource-action-types.js +13 -0
- package/dist/api/constants.d.ts +6 -0
- package/dist/api/constants.d.ts.map +1 -0
- package/dist/api/constants.js +5 -0
- package/dist/api/contracts/i-entity-registry.d.ts +19 -0
- package/dist/api/contracts/i-entity-registry.d.ts.map +1 -0
- package/dist/api/contracts/i-entity-registry.js +1 -0
- package/dist/api/contracts/i-resource-registry.d.ts +19 -0
- package/dist/api/contracts/i-resource-registry.d.ts.map +1 -0
- package/dist/api/contracts/i-resource-registry.js +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +15 -0
- package/dist/api/types/action-types.d.ts +34 -0
- package/dist/api/types/action-types.d.ts.map +1 -0
- package/dist/api/types/action-types.js +1 -0
- package/dist/api/types/resource-attributes.d.ts +43 -0
- package/dist/api/types/resource-attributes.d.ts.map +1 -0
- package/dist/api/types/resource-attributes.js +1 -0
- package/dist/api/types/resource-types.d.ts +20 -0
- package/dist/api/types/resource-types.d.ts.map +1 -0
- package/dist/api/types/resource-types.js +1 -0
- package/dist/api/utils/resource-attributes-util.d.ts +183 -0
- package/dist/api/utils/resource-attributes-util.d.ts.map +1 -0
- package/dist/api/utils/resource-attributes-util.js +280 -0
- package/dist/impl/autosave/index.d.ts +5 -0
- package/dist/impl/autosave/index.d.ts.map +1 -0
- package/dist/impl/autosave/index.js +4 -0
- package/dist/impl/autosave/resource-autosave-provider.d.ts +49 -0
- package/dist/impl/autosave/resource-autosave-provider.d.ts.map +1 -0
- package/dist/impl/autosave/resource-autosave-provider.js +112 -0
- package/dist/impl/index.d.ts +20 -0
- package/dist/impl/index.d.ts.map +1 -0
- package/dist/impl/index.js +20 -0
- package/dist/impl/middleware/entity-middleware.d.ts +13 -0
- package/dist/impl/middleware/entity-middleware.d.ts.map +1 -0
- package/dist/impl/middleware/entity-middleware.js +221 -0
- package/dist/impl/middleware/entity-sync-middleware.d.ts +7 -0
- package/dist/impl/middleware/entity-sync-middleware.d.ts.map +1 -0
- package/dist/impl/middleware/entity-sync-middleware.js +32 -0
- package/dist/impl/middleware/resource-middleware.d.ts +13 -0
- package/dist/impl/middleware/resource-middleware.d.ts.map +1 -0
- package/dist/impl/middleware/resource-middleware.js +97 -0
- package/dist/impl/middleware/sync-middleware.d.ts +12 -0
- package/dist/impl/middleware/sync-middleware.d.ts.map +1 -0
- package/dist/impl/middleware/sync-middleware.js +80 -0
- package/dist/impl/plugin/resource-plugin-factory.d.ts +31 -0
- package/dist/impl/plugin/resource-plugin-factory.d.ts.map +1 -0
- package/dist/impl/plugin/resource-plugin-factory.js +131 -0
- package/dist/impl/providers/mock-resource-provider.d.ts +147 -0
- package/dist/impl/providers/mock-resource-provider.d.ts.map +1 -0
- package/dist/impl/providers/mock-resource-provider.js +242 -0
- package/dist/impl/providers/rest-resource-provider.d.ts +51 -0
- package/dist/impl/providers/rest-resource-provider.d.ts.map +1 -0
- package/dist/impl/providers/rest-resource-provider.js +128 -0
- package/dist/impl/registry/entity-registry.d.ts +54 -0
- package/dist/impl/registry/entity-registry.d.ts.map +1 -0
- package/dist/impl/registry/entity-registry.js +51 -0
- package/dist/impl/registry/resource-registry.d.ts +80 -0
- package/dist/impl/registry/resource-registry.d.ts.map +1 -0
- package/dist/impl/registry/resource-registry.js +74 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/spi/config/endpoint-definition.d.ts +46 -0
- package/dist/spi/config/endpoint-definition.d.ts.map +1 -0
- package/dist/spi/config/endpoint-definition.js +1 -0
- package/dist/spi/config/entity-definition.d.ts +50 -0
- package/dist/spi/config/entity-definition.d.ts.map +1 -0
- package/dist/spi/config/entity-definition.js +1 -0
- package/dist/spi/config/plugin-config.d.ts +21 -0
- package/dist/spi/config/plugin-config.d.ts.map +1 -0
- package/dist/spi/config/plugin-config.js +1 -0
- package/dist/spi/index.d.ts +6 -0
- package/dist/spi/index.d.ts.map +1 -0
- package/dist/spi/index.js +7 -0
- package/dist/spi/providers/i-resource-provider.d.ts +42 -0
- package/dist/spi/providers/i-resource-provider.d.ts.map +1 -0
- package/dist/spi/providers/i-resource-provider.js +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* REST API resource provider using Axios
|
|
4
|
+
*/
|
|
5
|
+
export class RestResourceProvider {
|
|
6
|
+
constructor(config = {}) {
|
|
7
|
+
Object.defineProperty(this, "type", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: 'rest'
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "axios", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: void 0
|
|
18
|
+
});
|
|
19
|
+
this.axios =
|
|
20
|
+
config.axiosInstance ||
|
|
21
|
+
axios.create({
|
|
22
|
+
baseURL: config.baseUrl,
|
|
23
|
+
timeout: config.timeout || 30000,
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json',
|
|
26
|
+
...config.headers
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Execute a resource call
|
|
32
|
+
*/
|
|
33
|
+
async call(endpoint, params, operation) {
|
|
34
|
+
switch (operation) {
|
|
35
|
+
case 'fetch':
|
|
36
|
+
return this.executeFetch(endpoint, params);
|
|
37
|
+
case 'create':
|
|
38
|
+
return this.executeCreate(endpoint, params);
|
|
39
|
+
case 'update':
|
|
40
|
+
return this.executeUpdate(endpoint, params);
|
|
41
|
+
case 'delete':
|
|
42
|
+
return this.executeDelete(endpoint, params);
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unknown operation: ${operation}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Execute fetch operation (GET)
|
|
49
|
+
*/
|
|
50
|
+
async executeFetch(endpoint, params) {
|
|
51
|
+
const url = this.buildUrl(endpoint, params.params);
|
|
52
|
+
const response = await this.axios.get(url, {
|
|
53
|
+
params: params.query,
|
|
54
|
+
headers: params.headers
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
data: response.data,
|
|
58
|
+
metadata: {
|
|
59
|
+
status: response.status,
|
|
60
|
+
headers: response.headers
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Execute create operation (POST)
|
|
66
|
+
*/
|
|
67
|
+
async executeCreate(endpoint, params) {
|
|
68
|
+
const response = await this.axios.post(endpoint, params.body, {
|
|
69
|
+
params: params.query,
|
|
70
|
+
headers: params.headers
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
data: response.data,
|
|
74
|
+
metadata: {
|
|
75
|
+
status: response.status,
|
|
76
|
+
headers: response.headers
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Execute update operation (PUT)
|
|
82
|
+
*/
|
|
83
|
+
async executeUpdate(endpoint, params) {
|
|
84
|
+
const url = this.buildUrl(endpoint, params.params);
|
|
85
|
+
const response = await this.axios.put(url, params.body, {
|
|
86
|
+
params: params.query,
|
|
87
|
+
headers: params.headers
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
data: response.data,
|
|
91
|
+
metadata: {
|
|
92
|
+
status: response.status,
|
|
93
|
+
headers: response.headers
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Execute delete operation (DELETE)
|
|
99
|
+
*/
|
|
100
|
+
async executeDelete(endpoint, params) {
|
|
101
|
+
const url = this.buildUrl(endpoint, params.params);
|
|
102
|
+
const response = await this.axios.delete(url, {
|
|
103
|
+
params: params.query,
|
|
104
|
+
headers: params.headers
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
data: response.data,
|
|
108
|
+
metadata: {
|
|
109
|
+
status: response.status,
|
|
110
|
+
headers: response.headers
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Build URL with path parameters
|
|
116
|
+
* Replaces :param placeholders with actual values
|
|
117
|
+
* Example: /users/:id + { id: "123" } → /users/123
|
|
118
|
+
*/
|
|
119
|
+
buildUrl(endpoint, params) {
|
|
120
|
+
if (!params)
|
|
121
|
+
return endpoint;
|
|
122
|
+
let url = endpoint;
|
|
123
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
124
|
+
url = url.replace(`:${key}`, String(value));
|
|
125
|
+
});
|
|
126
|
+
return url;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { EntityDefinition } from '../../spi';
|
|
2
|
+
/**
|
|
3
|
+
* Internal entity registry interface with write operations
|
|
4
|
+
*/
|
|
5
|
+
export interface IEntityRegistryInternal {
|
|
6
|
+
/**
|
|
7
|
+
* Register an entity definition
|
|
8
|
+
*/
|
|
9
|
+
registerEntity(definition: EntityDefinition): void;
|
|
10
|
+
/**
|
|
11
|
+
* Unregister an entity definition
|
|
12
|
+
*/
|
|
13
|
+
unregisterEntity(id: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Get entity definition by ID
|
|
16
|
+
*/
|
|
17
|
+
getEntity(id: string): EntityDefinition | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get all registered entities
|
|
20
|
+
*/
|
|
21
|
+
getAllEntities(): EntityDefinition[];
|
|
22
|
+
/**
|
|
23
|
+
* Check if entity exists
|
|
24
|
+
*/
|
|
25
|
+
hasEntity(id: string): boolean;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Entity registry implementation
|
|
29
|
+
* Manages entity definitions
|
|
30
|
+
*/
|
|
31
|
+
export declare class EntityRegistry implements IEntityRegistryInternal {
|
|
32
|
+
private entities;
|
|
33
|
+
/**
|
|
34
|
+
* Register an entity definition
|
|
35
|
+
*/
|
|
36
|
+
registerEntity(definition: EntityDefinition): void;
|
|
37
|
+
/**
|
|
38
|
+
* Unregister an entity definition
|
|
39
|
+
*/
|
|
40
|
+
unregisterEntity(id: string): void;
|
|
41
|
+
/**
|
|
42
|
+
* Get entity definition by ID
|
|
43
|
+
*/
|
|
44
|
+
getEntity(id: string): EntityDefinition | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Get all registered entities
|
|
47
|
+
*/
|
|
48
|
+
getAllEntities(): EntityDefinition[];
|
|
49
|
+
/**
|
|
50
|
+
* Check if entity exists
|
|
51
|
+
*/
|
|
52
|
+
hasEntity(id: string): boolean;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=entity-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-registry.d.ts","sourceRoot":"","sources":["../../../src/impl/registry/entity-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAEnD;;OAEG;IACH,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAEnC;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAEpD;;OAEG;IACH,cAAc,IAAI,gBAAgB,EAAE,CAAC;IAErC;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;CAChC;AAED;;;GAGG;AACH,qBAAa,cAAe,YAAW,uBAAuB;IAC5D,OAAO,CAAC,QAAQ,CAA4C;IAE5D;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI;IAiBlD;;OAEG;IACH,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIlC;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAInD;;OAEG;IACH,cAAc,IAAI,gBAAgB,EAAE;IAIpC;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;CAG/B"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity registry implementation
|
|
3
|
+
* Manages entity definitions
|
|
4
|
+
*/
|
|
5
|
+
export class EntityRegistry {
|
|
6
|
+
constructor() {
|
|
7
|
+
Object.defineProperty(this, "entities", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: new Map()
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Register an entity definition
|
|
16
|
+
*/
|
|
17
|
+
registerEntity(definition) {
|
|
18
|
+
// Validate key schema
|
|
19
|
+
if (!definition.keySchema.fields || definition.keySchema.fields.length === 0) {
|
|
20
|
+
throw new Error(`Entity "${definition.id}" must have at least one key field in keySchema.fields`);
|
|
21
|
+
}
|
|
22
|
+
if (this.entities.has(definition.id)) {
|
|
23
|
+
console.warn(`Entity "${definition.id}" is already registered. Overwriting.`);
|
|
24
|
+
}
|
|
25
|
+
this.entities.set(definition.id, definition);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Unregister an entity definition
|
|
29
|
+
*/
|
|
30
|
+
unregisterEntity(id) {
|
|
31
|
+
this.entities.delete(id);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get entity definition by ID
|
|
35
|
+
*/
|
|
36
|
+
getEntity(id) {
|
|
37
|
+
return this.entities.get(id);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get all registered entities
|
|
41
|
+
*/
|
|
42
|
+
getAllEntities() {
|
|
43
|
+
return Array.from(this.entities.values());
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if entity exists
|
|
47
|
+
*/
|
|
48
|
+
hasEntity(id) {
|
|
49
|
+
return this.entities.has(id);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { IResourceProvider } from '../../spi';
|
|
2
|
+
import type { ResourceEndpointDefinition } from '../../spi';
|
|
3
|
+
/**
|
|
4
|
+
* Internal registry interface with write operations
|
|
5
|
+
*/
|
|
6
|
+
export interface IResourceRegistryInternal {
|
|
7
|
+
/**
|
|
8
|
+
* Register a resource endpoint
|
|
9
|
+
*/
|
|
10
|
+
registerEndpoint(definition: ResourceEndpointDefinition): void;
|
|
11
|
+
/**
|
|
12
|
+
* Unregister a resource endpoint
|
|
13
|
+
*/
|
|
14
|
+
unregisterEndpoint(id: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Get endpoint definition by ID
|
|
17
|
+
*/
|
|
18
|
+
getEndpoint(id: string): ResourceEndpointDefinition | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Get all registered endpoints
|
|
21
|
+
*/
|
|
22
|
+
getAllEndpoints(): ResourceEndpointDefinition[];
|
|
23
|
+
/**
|
|
24
|
+
* Check if endpoint exists
|
|
25
|
+
*/
|
|
26
|
+
hasEndpoint(id: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Register a resource provider
|
|
29
|
+
*/
|
|
30
|
+
registerProvider(provider: IResourceProvider): void;
|
|
31
|
+
/**
|
|
32
|
+
* Get provider by type
|
|
33
|
+
*/
|
|
34
|
+
getProvider(type: string): IResourceProvider | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Get all registered providers
|
|
37
|
+
*/
|
|
38
|
+
getAllProviders(): IResourceProvider[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resource registry implementation
|
|
42
|
+
* Manages resource endpoint definitions and providers
|
|
43
|
+
*/
|
|
44
|
+
export declare class ResourceRegistry implements IResourceRegistryInternal {
|
|
45
|
+
private endpoints;
|
|
46
|
+
private providers;
|
|
47
|
+
/**
|
|
48
|
+
* Register a resource endpoint
|
|
49
|
+
*/
|
|
50
|
+
registerEndpoint(definition: ResourceEndpointDefinition): void;
|
|
51
|
+
/**
|
|
52
|
+
* Unregister a resource endpoint
|
|
53
|
+
*/
|
|
54
|
+
unregisterEndpoint(id: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get endpoint definition by ID
|
|
57
|
+
*/
|
|
58
|
+
getEndpoint(id: string): ResourceEndpointDefinition | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Get all registered endpoints
|
|
61
|
+
*/
|
|
62
|
+
getAllEndpoints(): ResourceEndpointDefinition[];
|
|
63
|
+
/**
|
|
64
|
+
* Check if endpoint exists
|
|
65
|
+
*/
|
|
66
|
+
hasEndpoint(id: string): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Register a resource provider
|
|
69
|
+
*/
|
|
70
|
+
registerProvider(provider: IResourceProvider): void;
|
|
71
|
+
/**
|
|
72
|
+
* Get provider by type
|
|
73
|
+
*/
|
|
74
|
+
getProvider(type: string): IResourceProvider | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Get all registered providers
|
|
77
|
+
*/
|
|
78
|
+
getAllProviders(): IResourceProvider[];
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=resource-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-registry.d.ts","sourceRoot":"","sources":["../../../src/impl/registry/resource-registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,0BAA0B,GAAG,IAAI,CAAC;IAE/D;;OAEG;IACH,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;IAErC;;OAEG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS,CAAC;IAEhE;;OAEG;IACH,eAAe,IAAI,0BAA0B,EAAE,CAAC;IAEhD;;OAEG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAEjC;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAEpD;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAAC;IAEzD;;OAEG;IACH,eAAe,IAAI,iBAAiB,EAAE,CAAC;CACxC;AAED;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,yBAAyB;IAChE,OAAO,CAAC,SAAS,CAAsD;IACvE,OAAO,CAAC,SAAS,CAA6C;IAE9D;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,0BAA0B,GAAG,IAAI;IAU9D;;OAEG;IACH,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAIpC;;OAEG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS;IAI/D;;OAEG;IACH,eAAe,IAAI,0BAA0B,EAAE;IAI/C;;OAEG;IACH,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAIhC;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAUnD;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS;IAIxD;;OAEG;IACH,eAAe,IAAI,iBAAiB,EAAE;CAGvC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource registry implementation
|
|
3
|
+
* Manages resource endpoint definitions and providers
|
|
4
|
+
*/
|
|
5
|
+
export class ResourceRegistry {
|
|
6
|
+
constructor() {
|
|
7
|
+
Object.defineProperty(this, "endpoints", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: new Map()
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(this, "providers", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: new Map()
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Register a resource endpoint
|
|
22
|
+
*/
|
|
23
|
+
registerEndpoint(definition) {
|
|
24
|
+
if (this.endpoints.has(definition.id)) {
|
|
25
|
+
console.warn(`Resource endpoint "${definition.id}" is already registered. Overwriting.`);
|
|
26
|
+
}
|
|
27
|
+
this.endpoints.set(definition.id, definition);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Unregister a resource endpoint
|
|
31
|
+
*/
|
|
32
|
+
unregisterEndpoint(id) {
|
|
33
|
+
this.endpoints.delete(id);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get endpoint definition by ID
|
|
37
|
+
*/
|
|
38
|
+
getEndpoint(id) {
|
|
39
|
+
return this.endpoints.get(id);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get all registered endpoints
|
|
43
|
+
*/
|
|
44
|
+
getAllEndpoints() {
|
|
45
|
+
return Array.from(this.endpoints.values());
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Check if endpoint exists
|
|
49
|
+
*/
|
|
50
|
+
hasEndpoint(id) {
|
|
51
|
+
return this.endpoints.has(id);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Register a resource provider
|
|
55
|
+
*/
|
|
56
|
+
registerProvider(provider) {
|
|
57
|
+
if (this.providers.has(provider.type)) {
|
|
58
|
+
console.warn(`Resource provider "${provider.type}" is already registered. Overwriting.`);
|
|
59
|
+
}
|
|
60
|
+
this.providers.set(provider.type, provider);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get provider by type
|
|
64
|
+
*/
|
|
65
|
+
getProvider(type) {
|
|
66
|
+
return this.providers.get(type);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get all registered providers
|
|
70
|
+
*/
|
|
71
|
+
getAllProviders() {
|
|
72
|
+
return Array.from(this.providers.values());
|
|
73
|
+
}
|
|
74
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ResourceCallAction } from '../../api';
|
|
2
|
+
import type { ResourceCallParams } from '../providers/i-resource-provider';
|
|
3
|
+
/**
|
|
4
|
+
* Maps entire action to API call parameters
|
|
5
|
+
*/
|
|
6
|
+
export type PayloadMapper = (action: ResourceCallAction) => ResourceCallParams;
|
|
7
|
+
/**
|
|
8
|
+
* Transforms API response before storing
|
|
9
|
+
*/
|
|
10
|
+
export type ResponseTransformer<TData = any> = (data: any, metadata: any | undefined, action: ResourceCallAction) => TData;
|
|
11
|
+
/**
|
|
12
|
+
* Resource endpoint registration configuration
|
|
13
|
+
* Used when configuring the plugin
|
|
14
|
+
*/
|
|
15
|
+
export interface ResourceEndpointDefinition {
|
|
16
|
+
/** Unique endpoint identifier */
|
|
17
|
+
id: string;
|
|
18
|
+
/** Provider type (must match a registered provider) */
|
|
19
|
+
providerType: string;
|
|
20
|
+
/** Base endpoint/URL for the resource */
|
|
21
|
+
endpoint: string;
|
|
22
|
+
/**
|
|
23
|
+
* Default directory where resources are stored when action doesn't specify path
|
|
24
|
+
*/
|
|
25
|
+
defaultFolder?: string | string[];
|
|
26
|
+
/** Optional schema reference for validation */
|
|
27
|
+
schema?: string;
|
|
28
|
+
/** Maps action to provider call params */
|
|
29
|
+
payloadMapper?: PayloadMapper;
|
|
30
|
+
/** Transforms response data before storing */
|
|
31
|
+
responseTransformer?: ResponseTransformer;
|
|
32
|
+
/** Additional endpoint configuration */
|
|
33
|
+
config?: {
|
|
34
|
+
/** Auto-fetch on registration */
|
|
35
|
+
autoFetch?: boolean;
|
|
36
|
+
/** Cache duration in ms */
|
|
37
|
+
cacheDurationMs?: number;
|
|
38
|
+
/** Retry configuration */
|
|
39
|
+
retry?: {
|
|
40
|
+
maxAttempts?: number;
|
|
41
|
+
backoff?: 'linear' | 'exponential';
|
|
42
|
+
};
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=endpoint-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoint-definition.d.ts","sourceRoot":"","sources":["../../../src/spi/config/endpoint-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAE3E;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,kBAAkB,KAAK,kBAAkB,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,KAAK,GAAG,GAAG,IAAI,CAC7C,IAAI,EAAE,GAAG,EACT,QAAQ,EAAE,GAAG,GAAG,SAAS,EACzB,MAAM,EAAE,kBAAkB,KACvB,KAAK,CAAC;AAEX;;;GAGG;AACH,MAAM,WAAW,0BAA0B;IACzC,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IAEX,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IAErB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAElC,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,0CAA0C;IAC1C,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B,8CAA8C;IAC9C,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAE1C,wCAAwC;IACxC,MAAM,CAAC,EAAE;QACP,iCAAiC;QACjC,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,2BAA2B;QAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,0BAA0B;QAC1B,KAAK,CAAC,EAAE;YACN,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,OAAO,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;SACpC,CAAC;QACF,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { EntityKey, ResourceOperation } from '../../api';
|
|
2
|
+
import type { ResourceCallParams } from '../providers/i-resource-provider';
|
|
3
|
+
/**
|
|
4
|
+
* Entity key schema definition
|
|
5
|
+
*/
|
|
6
|
+
export interface EntityKeySchema {
|
|
7
|
+
/** Key field names in order (for composite keys) */
|
|
8
|
+
fields: string[];
|
|
9
|
+
/** Optional separator for path generation (default: "/") */
|
|
10
|
+
separator?: string;
|
|
11
|
+
/** Optional validation */
|
|
12
|
+
validate?: (key: EntityKey) => boolean | string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Maps entity keys to resource call params
|
|
16
|
+
*/
|
|
17
|
+
export type EntityKeyMapper = (keys: EntityKey, operation: ResourceOperation) => ResourceCallParams;
|
|
18
|
+
/**
|
|
19
|
+
* Generates file path from entity keys
|
|
20
|
+
*/
|
|
21
|
+
export type EntityPathGenerator = (keys: EntityKey, entityId: string) => string | string[];
|
|
22
|
+
/**
|
|
23
|
+
* Entity definition configuration
|
|
24
|
+
* Used when configuring the plugin
|
|
25
|
+
*/
|
|
26
|
+
export interface EntityDefinition {
|
|
27
|
+
/** Unique entity identifier (e.g., "user", "product") */
|
|
28
|
+
id: string;
|
|
29
|
+
/** Entity key schema */
|
|
30
|
+
keySchema: EntityKeySchema;
|
|
31
|
+
/** Resource endpoint ID to use for API calls */
|
|
32
|
+
resourceEndpointId: string;
|
|
33
|
+
/** Maps entity keys to resource call params */
|
|
34
|
+
keyMapper: EntityKeyMapper;
|
|
35
|
+
/** Generates file path from entity keys */
|
|
36
|
+
pathGenerator?: EntityPathGenerator;
|
|
37
|
+
/** Default folder for entities */
|
|
38
|
+
defaultFolder?: string | string[];
|
|
39
|
+
/** Optional schema reference for validation */
|
|
40
|
+
schema?: string;
|
|
41
|
+
/** Additional configuration */
|
|
42
|
+
config?: {
|
|
43
|
+
/** Auto-fetch on key change */
|
|
44
|
+
autoFetch?: boolean;
|
|
45
|
+
/** Cache duration in ms */
|
|
46
|
+
cacheDurationMs?: number;
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=entity-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-definition.d.ts","sourceRoot":"","sources":["../../../src/spi/config/entity-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oDAAoD;IACpD,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,SAAS,KAAK,OAAO,GAAG,MAAM,CAAC;CACjD;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,CAC5B,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,iBAAiB,KACzB,kBAAkB,CAAC;AAExB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAChC,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,KACb,MAAM,GAAG,MAAM,EAAE,CAAC;AAEvB;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,yDAAyD;IACzD,EAAE,EAAE,MAAM,CAAC;IAEX,wBAAwB;IACxB,SAAS,EAAE,eAAe,CAAC;IAE3B,gDAAgD;IAChD,kBAAkB,EAAE,MAAM,CAAC;IAE3B,+CAA+C;IAC/C,SAAS,EAAE,eAAe,CAAC;IAE3B,2CAA2C;IAC3C,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,kCAAkC;IAClC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAElC,+CAA+C;IAC/C,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,+BAA+B;IAC/B,MAAM,CAAC,EAAE;QACP,+BAA+B;QAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,2BAA2B;QAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ResourceAction, EntityAction } from '../../api';
|
|
2
|
+
import type { IResourceProvider } from '../providers/i-resource-provider';
|
|
3
|
+
import type { ResourceEndpointDefinition } from './endpoint-definition';
|
|
4
|
+
import type { EntityDefinition } from './entity-definition';
|
|
5
|
+
/**
|
|
6
|
+
* Plugin configuration
|
|
7
|
+
* Used when creating the resource plugin
|
|
8
|
+
*/
|
|
9
|
+
export interface ResourcePluginConfig {
|
|
10
|
+
/** Initial endpoint registrations */
|
|
11
|
+
endpoints?: ResourceEndpointDefinition[];
|
|
12
|
+
/** Initial entity registrations */
|
|
13
|
+
entities?: EntityDefinition[];
|
|
14
|
+
/** Custom providers to register */
|
|
15
|
+
providers?: IResourceProvider[];
|
|
16
|
+
/** Error handler */
|
|
17
|
+
onError?: (error: any, action: ResourceAction | EntityAction) => void;
|
|
18
|
+
/** Success handler */
|
|
19
|
+
onSuccess?: (result: any, action: ResourceAction | EntityAction) => void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=plugin-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-config.d.ts","sourceRoot":"","sources":["../../../src/spi/config/plugin-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,qCAAqC;IACrC,SAAS,CAAC,EAAE,0BAA0B,EAAE,CAAC;IAEzC,mCAAmC;IACnC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAE9B,mCAAmC;IACnC,SAAS,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAEhC,oBAAoB;IACpB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,GAAG,YAAY,KAAK,IAAI,CAAC;IAEtE,sBAAsB;IACtB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,GAAG,YAAY,KAAK,IAAI,CAAC;CAC1E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/spi/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AAGvB,cAAc,iCAAiC,CAAC;AAGhD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from '../api';
|
|
2
|
+
// Providers (for custom implementations)
|
|
3
|
+
export * from './providers/i-resource-provider';
|
|
4
|
+
// Configuration (for plugin setup)
|
|
5
|
+
export * from './config/endpoint-definition';
|
|
6
|
+
export * from './config/entity-definition';
|
|
7
|
+
export * from './config/plugin-config';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ResourceOperation } from '../../api';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters extracted from action and mapped to API call
|
|
4
|
+
*/
|
|
5
|
+
export interface ResourceCallParams {
|
|
6
|
+
/** Resource-specific parameters (e.g., { id: "123", include: "author" }) */
|
|
7
|
+
params?: Record<string, any>;
|
|
8
|
+
/** Request body for create/update operations */
|
|
9
|
+
body?: any;
|
|
10
|
+
/** Additional headers */
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
/** Query parameters */
|
|
13
|
+
query?: Record<string, any>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Result from a resource provider call
|
|
17
|
+
*/
|
|
18
|
+
export interface ResourceCallResult<TData = any> {
|
|
19
|
+
/** Response data */
|
|
20
|
+
data: TData;
|
|
21
|
+
/** Response metadata (headers, status, etc.) */
|
|
22
|
+
metadata?: {
|
|
23
|
+
status?: number;
|
|
24
|
+
headers?: Record<string, string>;
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Generic resource provider interface
|
|
30
|
+
* Implement this to create custom providers (GraphQL, gRPC, etc.)
|
|
31
|
+
*/
|
|
32
|
+
export interface IResourceProvider {
|
|
33
|
+
/**
|
|
34
|
+
* Provider type identifier (e.g., "rest", "graphql", "grpc")
|
|
35
|
+
*/
|
|
36
|
+
readonly type: string;
|
|
37
|
+
/**
|
|
38
|
+
* Execute a resource call
|
|
39
|
+
*/
|
|
40
|
+
call<TData = any>(endpoint: string, params: ResourceCallParams, operation: ResourceOperation): Promise<ResourceCallResult<TData>>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=i-resource-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i-resource-provider.d.ts","sourceRoot":"","sources":["../../../src/spi/providers/i-resource-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,4EAA4E;IAC5E,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,gDAAgD;IAChD,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,uBAAuB;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,KAAK,GAAG,GAAG;IAC7C,oBAAoB;IACpB,IAAI,EAAE,KAAK,CAAC;IACZ,gDAAgD;IAChD,QAAQ,CAAC,EAAE;QACT,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,IAAI,CAAC,KAAK,GAAG,GAAG,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,kBAAkB,EAC1B,SAAS,EAAE,iBAAiB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;CACvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|