oc-server 0.0.1 → 0.0.2-beta.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/Server.d.ts +4 -4
- package/dist/Server.js +9 -5
- package/dist/index.d.ts +2 -0
- package/dist/index.js +17 -1
- package/dist/serverClient.js +28 -5
- package/dist/types.d.ts +2 -1
- package/package.json +6 -2
- package/README.md +0 -3
- package/src/index.ts +0 -1
- package/tsconfig.json +0 -13
package/dist/Server.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { Context } from './types';
|
|
2
|
-
type
|
|
3
|
-
export type Action<I, O, E> = (params: I, ctx:
|
|
1
|
+
import { Context, DataProvider } from './types';
|
|
2
|
+
type ContextWithoutParamsActions<E> = Omit<Context<any, E>, 'params' | 'action'>;
|
|
3
|
+
export type Action<I, O, E> = (params: I, ctx: ContextWithoutParamsActions<E>) => Promise<O> | O;
|
|
4
4
|
type AnyAction = Action<any, any, any>;
|
|
5
5
|
export declare class Server<E, A extends Record<string, AnyAction> = {}, InitialInput = any, InitialOutput = any> {
|
|
6
6
|
private initial;
|
|
7
7
|
actions: A;
|
|
8
8
|
constructor(initial: Action<InitialInput, InitialOutput, E>);
|
|
9
9
|
action<ActionName extends string, I, O>(name: ActionName, action: Action<I, O, E>): Server<E, A & Record<ActionName, Action<I, O, E>>, InitialInput, InitialOutput>;
|
|
10
|
-
getData():
|
|
10
|
+
getData(): DataProvider<any, any, any>;
|
|
11
11
|
}
|
|
12
12
|
export interface Register {
|
|
13
13
|
}
|
package/dist/Server.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Server = void 0;
|
|
4
|
-
const actionKey = '__oc--action__';
|
|
5
4
|
class Server {
|
|
6
5
|
initial;
|
|
7
6
|
actions = {};
|
|
@@ -13,11 +12,16 @@ class Server {
|
|
|
13
12
|
return this;
|
|
14
13
|
}
|
|
15
14
|
getData() {
|
|
16
|
-
return async (context, cb) => {
|
|
17
|
-
|
|
18
|
-
const action = this.actions[actionName] ?? this.initial;
|
|
15
|
+
return async ({ action: actionName, params, ...context }, cb) => {
|
|
16
|
+
let res;
|
|
19
17
|
try {
|
|
20
|
-
|
|
18
|
+
if (actionName && this.actions[actionName]) {
|
|
19
|
+
const data = params?.data ?? params;
|
|
20
|
+
res = await this.actions[actionName](data, context);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
res = await this.initial(params, context);
|
|
24
|
+
}
|
|
21
25
|
cb(null, res);
|
|
22
26
|
}
|
|
23
27
|
catch (err) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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
|
+
__exportStar(require("./Server"), exports);
|
|
18
|
+
__exportStar(require("./serverClient"), exports);
|
package/dist/serverClient.js
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serverClient = void 0;
|
|
4
|
-
|
|
4
|
+
function getAction(options) {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
window.oc.getData({
|
|
7
|
+
action: options.action,
|
|
8
|
+
name: options.componentName,
|
|
9
|
+
version: options.componentVersion,
|
|
10
|
+
baseUrl: options.baseUrl,
|
|
11
|
+
parameters: options.parameters,
|
|
12
|
+
}, (err, data) => {
|
|
13
|
+
if (err) {
|
|
14
|
+
return reject(err);
|
|
15
|
+
}
|
|
16
|
+
const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = data.component.props;
|
|
17
|
+
resolve(rest);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
5
21
|
exports.serverClient = new Proxy({}, {
|
|
6
22
|
get(_target, prop) {
|
|
7
23
|
return (data) => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
24
|
+
const componentName = '';
|
|
25
|
+
const componentVersion = '';
|
|
26
|
+
const baseUrl = window.oc?.renderedComponents?.[componentName]?.baseUrl ?? '/';
|
|
27
|
+
return getAction({
|
|
28
|
+
action: prop,
|
|
29
|
+
baseUrl,
|
|
30
|
+
componentName,
|
|
31
|
+
componentVersion,
|
|
32
|
+
parameters: {
|
|
33
|
+
data,
|
|
34
|
+
},
|
|
12
35
|
});
|
|
13
36
|
};
|
|
14
37
|
},
|
package/dist/types.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export interface Template {
|
|
|
20
20
|
externals: External[];
|
|
21
21
|
}
|
|
22
22
|
export interface Context<T = any, E = Env> {
|
|
23
|
+
action?: string;
|
|
23
24
|
acceptLanguage: AcceptLanguage[];
|
|
24
25
|
baseUrl: string;
|
|
25
26
|
env: E;
|
|
@@ -33,5 +34,5 @@ export interface Context<T = any, E = Env> {
|
|
|
33
34
|
templates: Template[];
|
|
34
35
|
}
|
|
35
36
|
type Callback<D, E = Error> = (error: E | null, data?: D) => void;
|
|
36
|
-
export type DataProvider<Parameters, Return, Environment = Env> = (context: Context<Parameters, Environment>, callback: Callback<Return>) => void;
|
|
37
|
+
export type DataProvider<Parameters = any, Return = any, Environment = Env> = (context: Context<Parameters, Environment>, callback: Callback<Return>) => void;
|
|
37
38
|
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oc-server",
|
|
3
|
-
"version": "0.0.1",
|
|
3
|
+
"version": "0.0.2-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"prepare": "npm run build"
|
|
9
|
+
"prepare": "npm run build",
|
|
10
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
10
11
|
},
|
|
11
12
|
"keywords": [
|
|
12
13
|
"oc",
|
|
@@ -16,5 +17,8 @@
|
|
|
16
17
|
"name": "Ricardo Devis Agullo",
|
|
17
18
|
"email": "mkredz@gmail.com"
|
|
18
19
|
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/**"
|
|
22
|
+
],
|
|
19
23
|
"license": "MIT"
|
|
20
24
|
}
|
package/README.md
DELETED
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
throw new Error('Not implemented yet!');
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"forceConsistentCasingInFileNames": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"skipLibCheck": true
|
|
11
|
-
},
|
|
12
|
-
"include": ["./src"]
|
|
13
|
-
}
|