@hamak/ui-remote-resource-spi 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.
@@ -0,0 +1,46 @@
1
+ import type { ResourceCallAction } from '@hamak/ui-remote-resource-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/config/endpoint-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,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 '@hamak/ui-remote-resource-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/config/entity-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClF,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 '@hamak/ui-remote-resource-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/config/plugin-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClF,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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Providers (for custom implementations)
18
+ __exportStar(require("./providers/i-resource-provider"), exports);
19
+ // Configuration (for plugin setup)
20
+ __exportStar(require("./config/endpoint-definition"), exports);
21
+ __exportStar(require("./config/entity-definition"), exports);
22
+ __exportStar(require("./config/plugin-config"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './providers/i-resource-provider';
2
+ export * from './config/endpoint-definition';
3
+ export * from './config/entity-definition';
4
+ export * from './config/plugin-config';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,iCAAiC,CAAC;AAGhD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ // Providers (for custom implementations)
2
+ export * from './providers/i-resource-provider';
3
+ // Configuration (for plugin setup)
4
+ export * from './config/endpoint-definition';
5
+ export * from './config/entity-definition';
6
+ export * from './config/plugin-config';
@@ -0,0 +1,42 @@
1
+ import type { ResourceOperation } from '@hamak/ui-remote-resource-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/providers/i-resource-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAEvE;;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 {};
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@hamak/ui-remote-resource-spi",
3
+ "version": "0.4.19",
4
+ "private": false,
5
+ "type": "module",
6
+ "description": "Remote Resource SPI - Service Provider Interface for plugin configuration",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "sideEffects": false,
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/amah/app-framework.git",
16
+ "directory": "packages/ui-remote-resource/ui-remote-resource-spi"
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.json && tsc -p tsconfig.es2015.json",
23
+ "clean": "rm -rf dist",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest"
26
+ },
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.js",
31
+ "require": "./dist/es2015/index.js",
32
+ "default": "./dist/index.js"
33
+ },
34
+ "./es2015": {
35
+ "require": "./dist/es2015/index.js",
36
+ "default": "./dist/es2015/index.js"
37
+ }
38
+ },
39
+ "dependencies": {
40
+ "@hamak/ui-remote-resource-api": "*"
41
+ },
42
+ "peerDependencies": {
43
+ "@hamak/shared-utils": "*"
44
+ },
45
+ "devDependencies": {
46
+ "@hamak/shared-utils": "*",
47
+ "typescript": "~5.4.0",
48
+ "vitest": "^2.0.0"
49
+ }
50
+ }