@drayman/core 1.6.0 → 1.9.0

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.
@@ -97,7 +97,7 @@ const serializeComponentInstanceOptions = (options) => {
97
97
  return serialized;
98
98
  };
99
99
  const renderedComps = {};
100
- const initializeComponentInstance = async ({ componentInstanceId, browserCommands = [], extensionsPath, extensionsOptions, componentRootDir, componentName, componentOptions, componentNamePrefix = '' }) => {
100
+ const initializeComponentInstance = async ({ componentInstanceId, browserCommands = [], serverCommands = [], extensionsPath, extensionsOptions, componentRootDir, componentName, componentOptions, componentNamePrefix = '' }) => {
101
101
  ComponentInstance.id = componentInstanceId;
102
102
  if (extensionsPath) {
103
103
  extensions = await require(path_1.default.join(process.cwd(), extensionsPath))(extensionsOptions);
@@ -127,6 +127,31 @@ const initializeComponentInstance = async ({ componentInstanceId, browserCommand
127
127
  sendMessage({ type: 'browserCommand', payload: { data: newData, callbackId, command, elements } });
128
128
  });
129
129
  }
130
+ const Server = {};
131
+ for (const command of serverCommands) {
132
+ Server[command] = async (data = {}) => new Promise((resolve, reject) => {
133
+ const newData = {};
134
+ for (const key of Object.keys(data || {})) {
135
+ if (typeof data[key] === 'function') {
136
+ const callbackId = shortid_1.default.generate();
137
+ newData[key] = callbackId;
138
+ browserCallbacks[callbackId] = {
139
+ callback: async (response) => await data[key](response),
140
+ once: false,
141
+ };
142
+ }
143
+ else {
144
+ newData[key] = data[key];
145
+ }
146
+ }
147
+ const callbackId = shortid_1.default.generate();
148
+ browserCallbacks[callbackId] = {
149
+ callback: (response) => resolve(response),
150
+ once: true,
151
+ };
152
+ sendMessage({ type: 'serverCommand', payload: { data: newData, callbackId, command, } });
153
+ });
154
+ }
130
155
  props = componentOptions || {};
131
156
  const componentNames = fs_1.default
132
157
  .readdirSync(componentRootDir)
@@ -163,6 +188,7 @@ const initializeComponentInstance = async ({ componentInstanceId, browserCommand
163
188
  EventHub,
164
189
  Components,
165
190
  Browser,
191
+ Server,
166
192
  ComponentInstance,
167
193
  ...extensions.importable,
168
194
  });
@@ -234,6 +260,7 @@ const initializeComponentInstance = async ({ componentInstanceId, browserCommand
234
260
  EventHub,
235
261
  Components,
236
262
  Browser,
263
+ Server,
237
264
  ComponentInstance,
238
265
  ...extensions.importable,
239
266
  });
package/dist/index.d.ts CHANGED
@@ -27,7 +27,7 @@ export declare const saveComponent: ({ script, outputFile }: {
27
27
  script: any;
28
28
  outputFile: any;
29
29
  }) => Promise<void>;
30
- export declare const onInitializeComponentInstance: ({ namespaceId, extensionsPath, extensionsOptions, componentNamePrefix, componentName, componentRootDir, componentInstanceId, componentOptions, connectionId, emit, onComponentInstanceConsole, browserCommands, }: {
30
+ export declare const onInitializeComponentInstance: ({ namespaceId, extensionsPath, extensionsOptions, componentNamePrefix, componentName, componentRootDir, componentInstanceId, componentOptions, connectionId, emit, onComponentInstanceConsole, browserCommands, serverCommands, onEventHubEvent, }: {
31
31
  namespaceId?: any;
32
32
  extensionsPath?: any;
33
33
  extensionsOptions?: any;
@@ -40,6 +40,8 @@ export declare const onInitializeComponentInstance: ({ namespaceId, extensionsPa
40
40
  emit: any;
41
41
  onComponentInstanceConsole: any;
42
42
  browserCommands: any;
43
+ serverCommands: any;
44
+ onEventHubEvent?: any;
43
45
  }) => Promise<void>;
44
46
  export declare const onDisconnect: ({ connectionId }: {
45
47
  connectionId: any;
package/dist/index.js CHANGED
@@ -74,7 +74,7 @@ const saveComponent = async ({ script, outputFile }) => {
74
74
  await fs_extra_1.default.outputFile(outputFile, transpiledComponentScript.outputText);
75
75
  };
76
76
  exports.saveComponent = saveComponent;
77
- const onInitializeComponentInstance = async ({ namespaceId = null, extensionsPath = null, extensionsOptions = null, componentNamePrefix = '', componentName, componentRootDir, componentInstanceId, componentOptions, connectionId, emit, onComponentInstanceConsole, browserCommands, }) => {
77
+ const onInitializeComponentInstance = async ({ namespaceId = null, extensionsPath = null, extensionsOptions = null, componentNamePrefix = '', componentName, componentRootDir, componentInstanceId, componentOptions, connectionId, emit, onComponentInstanceConsole, browserCommands, serverCommands, onEventHubEvent = null, }) => {
78
78
  if (componentOptions && typeof componentOptions === 'string') {
79
79
  componentOptions = JSON.parse(componentOptions);
80
80
  }
@@ -110,6 +110,7 @@ const onInitializeComponentInstance = async ({ namespaceId = null, extensionsPat
110
110
  else if (type === 'eventHubEvent') {
111
111
  const { eventPayload, groupId, type } = payload;
112
112
  exports.handleEventHubEvent({ data: eventPayload, groupId, type, namespaceId });
113
+ onEventHubEvent?.({ data: eventPayload, groupId, type, namespaceId });
113
114
  }
114
115
  else if (type === 'console') {
115
116
  const { text } = payload;
@@ -119,7 +120,7 @@ const onInitializeComponentInstance = async ({ namespaceId = null, extensionsPat
119
120
  emit({ type, payload, componentInstanceId });
120
121
  }
121
122
  });
122
- worker.initializeComponentInstance({ browserCommands, componentNamePrefix, componentName, componentRootDir, componentOptions, componentInstanceId, extensionsPath, extensionsOptions });
123
+ worker.initializeComponentInstance({ browserCommands, serverCommands, componentNamePrefix, componentName, componentRootDir, componentOptions, componentInstanceId, extensionsPath, extensionsOptions });
123
124
  await clearGarbage();
124
125
  };
125
126
  exports.onInitializeComponentInstance = onInitializeComponentInstance;
package/dist/utils.js CHANGED
@@ -25,7 +25,7 @@ const render = async (raw, childRenderer = null, renderedArr = [], events = {},
25
25
  // item = { ...rendered };
26
26
  // }
27
27
  item = { ...await parseFnType(item) };
28
- const result = await childRenderer?.(item.type, `${parent}/${renderedArr.length}/${item.type}`, item.props);
28
+ const result = await childRenderer?.(item.type, item.key ? `${parent}/${item.key}/${item.type}` : `${parent}/${renderedArr.length}/${item.type}`, item.props);
29
29
  if (result) {
30
30
  await exports.render(result, childRenderer, renderedArr, events, `${parent}`);
31
31
  }
package/jsx-runtime.js CHANGED
@@ -1,5 +1,5 @@
1
- function jsx(type, props) {
2
- return { type: type ? type : '$$fragment', props };
1
+ function jsx(type, props, key) {
2
+ return { type: type ? type : '$$fragment', props, key };
3
3
  }
4
4
 
5
5
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drayman/core",
3
- "version": "1.6.0",
3
+ "version": "1.9.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "@babel/preset-env": "^7.13.15",
23
23
  "@babel/preset-react": "^7.13.13",
24
24
  "@babel/preset-typescript": "^7.13.0",
25
- "@drayman/types": "^1.6.0",
25
+ "@drayman/types": "^1.8.0",
26
26
  "@types/jest": "^26.0.22",
27
27
  "@types/node": "^14.14.39",
28
28
  "babel-jest": "^26.6.3",
@@ -39,5 +39,5 @@
39
39
  "ts-node": "^9.1.1",
40
40
  "typescript": "~4.1.5"
41
41
  },
42
- "gitHead": "b66357fa2c562d0ae5f147953ece54e25ffceede"
42
+ "gitHead": "828de3167180b8e7920b86c9d44da55a7577961c"
43
43
  }