@innet/server 2.0.0-alpha.17 → 2.0.0-alpha.18

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/README.md CHANGED
@@ -247,8 +247,8 @@ export default (
247
247
 
248
248
  [← back](#main)
249
249
 
250
- `<api>` element MUST be placed in `<server>` element.
251
250
  This element defines a REST API on the server.
251
+ This element MUST be placed in [\<server>](#server) element.
252
252
 
253
253
  #### title
254
254
 
@@ -329,7 +329,7 @@ export default (
329
329
  )
330
330
  ```
331
331
 
332
- *default: 0.0.0*
332
+ *default: `INNET_API_VERSION` || `'0.0.0'`*
333
333
 
334
334
  #### prefix
335
335
 
@@ -3380,7 +3380,7 @@ export default (
3380
3380
 
3381
3381
  #### dir
3382
3382
 
3383
- By default, it looks at project folder.
3383
+ By default, it equals `INNET_CMS_DIR` node env variable or the project folder.
3384
3384
  If you try the previous example on [http://localhost/package.json](http://localhost/package.json)
3385
3385
  you get the project `package.json` file.
3386
3386
 
@@ -3403,6 +3403,7 @@ you get the index file in `src` folder.
3403
3403
  #### prefix
3404
3404
 
3405
3405
  `<cms>` matches full `path`, you should take it into account if you add `prefix` on `<api>`.
3406
+ By default, it equals `INNET_CMS_PREFIX` node env variable or `/`.
3406
3407
 
3407
3408
  *src/app.tsx*
3408
3409
  ```typescript jsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@innet/server",
3
- "version": "2.0.0-alpha.17",
3
+ "version": "2.0.0-alpha.18",
4
4
  "description": "Create server-side application with innet",
5
5
  "main": "index.js",
6
6
  "module": "index.es6.js",
@@ -12,11 +12,10 @@ import { RulesError } from '../../../utils/rules/helpers.es6.js';
12
12
  import { paramsContext } from '../../../hooks/useParams/useParams.es6.js';
13
13
 
14
14
  const api = () => {
15
- var _a;
16
15
  const handler = useNewHandler();
17
16
  const { props = {}, children } = useApp();
18
- const { prefix = '', title = '', include, exclude } = props, rest = __rest(props, ["prefix", "title", "include", "exclude"]);
19
- const info = Object.assign(Object.assign({}, rest), { version: (_a = rest.version) !== null && _a !== void 0 ? _a : '0.0.0', title });
17
+ const { prefix = '', title = '', include, exclude, version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = __rest(props, ["prefix", "title", "include", "exclude", "version"]);
18
+ const info = Object.assign(Object.assign({}, rest), { version, title });
20
19
  const endpoints = {};
21
20
  const docs = {
22
21
  openapi: '3.1.0',
@@ -39,7 +38,7 @@ const api = () => {
39
38
  serverPlugins.set(handler, plugins);
40
39
  apiContext.set(handler, context);
41
40
  useServerPlugin(() => __awaiter(void 0, void 0, void 0, function* () {
42
- var _b, _c, _d, _e, _f, _g;
41
+ var _a, _b, _c, _d, _e, _f;
43
42
  const action = useAction();
44
43
  if (!condition(action))
45
44
  return;
@@ -53,7 +52,7 @@ const api = () => {
53
52
  res.end();
54
53
  return null;
55
54
  }
56
- const method = ((_c = (_b = req.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : 'get');
55
+ const method = ((_b = (_a = req.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'get');
57
56
  const rawSplitPath = url.slice(prefix.length).split('/').slice(1);
58
57
  const splitPath = rawSplitPath.at(-1) ? rawSplitPath : rawSplitPath.slice(0, -1);
59
58
  const endpoint = endpoints[method];
@@ -138,8 +137,8 @@ const api = () => {
138
137
  return true;
139
138
  });
140
139
  }
141
- if ((_e = (_d = currentEndpoint.static) === null || _d === void 0 ? void 0 : _d[key]) === null || _e === void 0 ? void 0 : _e.plugins) {
142
- if (!(yield run((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key], params)))
140
+ if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
141
+ if (!(yield run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params)))
143
142
  continue;
144
143
  return null;
145
144
  }
@@ -154,7 +153,7 @@ const api = () => {
154
153
  }
155
154
  break;
156
155
  }
157
- if ((_g = currentEndpoint.static) === null || _g === void 0 ? void 0 : _g[key]) {
156
+ if ((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key]) {
158
157
  endpointQueue.push([deep + 1, currentEndpoint.static[key], params]);
159
158
  }
160
159
  if (currentEndpoint.dynamic) {
@@ -20,11 +20,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
20
20
  var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
21
21
 
22
22
  const api = () => {
23
- var _a;
24
23
  const handler = innet.useNewHandler();
25
24
  const { props = {}, children } = innet.useApp();
26
- const { prefix = '', title = '', include, exclude } = props, rest = tslib.__rest(props, ["prefix", "title", "include", "exclude"]);
27
- const info = Object.assign(Object.assign({}, rest), { version: (_a = rest.version) !== null && _a !== void 0 ? _a : '0.0.0', title });
25
+ const { prefix = '', title = '', include, exclude, version = process.env.INNET_API_VERSION || '0.0.0' } = props, rest = tslib.__rest(props, ["prefix", "title", "include", "exclude", "version"]);
26
+ const info = Object.assign(Object.assign({}, rest), { version, title });
28
27
  const endpoints = {};
29
28
  const docs = {
30
29
  openapi: '3.1.0',
@@ -47,7 +46,7 @@ const api = () => {
47
46
  useServerPlugins.serverPlugins.set(handler, plugins);
48
47
  useApi.apiContext.set(handler, context);
49
48
  useServerPlugin.useServerPlugin(() => tslib.__awaiter(void 0, void 0, void 0, function* () {
50
- var _b, _c, _d, _e, _f, _g;
49
+ var _a, _b, _c, _d, _e, _f;
51
50
  const action = useAction.useAction();
52
51
  if (!condition(action))
53
52
  return;
@@ -61,7 +60,7 @@ const api = () => {
61
60
  res.end();
62
61
  return null;
63
62
  }
64
- const method = ((_c = (_b = req.method) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== null && _c !== void 0 ? _c : 'get');
63
+ const method = ((_b = (_a = req.method) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : 'get');
65
64
  const rawSplitPath = url.slice(prefix.length).split('/').slice(1);
66
65
  const splitPath = rawSplitPath.at(-1) ? rawSplitPath : rawSplitPath.slice(0, -1);
67
66
  const endpoint = endpoints[method];
@@ -146,8 +145,8 @@ const api = () => {
146
145
  return true;
147
146
  });
148
147
  }
149
- if ((_e = (_d = currentEndpoint.static) === null || _d === void 0 ? void 0 : _d[key]) === null || _e === void 0 ? void 0 : _e.plugins) {
150
- if (!(yield run((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key], params)))
148
+ if ((_d = (_c = currentEndpoint.static) === null || _c === void 0 ? void 0 : _c[key]) === null || _d === void 0 ? void 0 : _d.plugins) {
149
+ if (!(yield run((_e = currentEndpoint.static) === null || _e === void 0 ? void 0 : _e[key], params)))
151
150
  continue;
152
151
  return null;
153
152
  }
@@ -162,7 +161,7 @@ const api = () => {
162
161
  }
163
162
  break;
164
163
  }
165
- if ((_g = currentEndpoint.static) === null || _g === void 0 ? void 0 : _g[key]) {
164
+ if ((_f = currentEndpoint.static) === null || _f === void 0 ? void 0 : _f[key]) {
166
165
  endpointQueue.push([deep + 1, currentEndpoint.static[key], params]);
167
166
  }
168
167
  if (currentEndpoint.dynamic) {
@@ -7,7 +7,7 @@ import { usePath } from '../../../hooks/usePath/usePath.es6.js';
7
7
  import { file } from '../file/file.es6.js';
8
8
 
9
9
  function cms() {
10
- const { prefix = '/', dir = '.' } = useProps() || {};
10
+ const { prefix = process.env.INNET_CMS_PREFIX || '/', dir = process.env.INNET_CMS_DIR || '.', } = useProps() || {};
11
11
  const children = useChildren();
12
12
  const handler = useHandler();
13
13
  let url = usePath();
@@ -16,7 +16,7 @@ var innet__default = /*#__PURE__*/_interopDefaultLegacy(innet);
16
16
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
17
17
 
18
18
  function cms() {
19
- const { prefix = '/', dir = '.' } = jsx.useProps() || {};
19
+ const { prefix = process.env.INNET_CMS_PREFIX || '/', dir = process.env.INNET_CMS_DIR || '.', } = jsx.useProps() || {};
20
20
  const children = jsx.useChildren();
21
21
  const handler = innet.useHandler();
22
22
  let url = usePath.usePath();
@@ -21,6 +21,16 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
21
21
  if (['boolean', 'number', 'null'].includes(schema.type)) {
22
22
  return `${schema.type}${lastChar}`;
23
23
  }
24
+ if (schema.oneOf) {
25
+ let result = '';
26
+ for (const item of schema.oneOf) {
27
+ if (result) {
28
+ result += ' | ';
29
+ }
30
+ result += generateSchemaTypes(item, spaces + 2, '');
31
+ }
32
+ return result + lastChar;
33
+ }
24
34
  if (schema.type === 'array') {
25
35
  if (!schema.items)
26
36
  return `any[]${lastChar}`;
@@ -32,15 +42,23 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
32
42
  }
33
43
  let result = '{\n';
34
44
  const required = schema.required || [];
35
- for (const key in schema.properties) {
36
- const prop = schema.properties[key];
37
- const splitter = required.includes(key) || hasDefault(prop)
38
- ? ':'
39
- : '?:';
40
- result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
45
+ const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
46
+ const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
47
+ Object.keys(schema.additionalProperties).length);
48
+ if (hasProps) {
49
+ for (const key in schema.properties) {
50
+ const prop = schema.properties[key];
51
+ const splitter = required.includes(key) || hasDefault(prop)
52
+ ? ':'
53
+ : '?:';
54
+ result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
55
+ }
41
56
  }
42
- if (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length) {
43
- result += `${space}[key: string]: any\n`;
57
+ if (hasRestProps) {
58
+ const value = hasProps
59
+ ? 'any\n'
60
+ : generateSchemaTypes(schema.additionalProperties, spaces + 2);
61
+ result += `${space}[key: string]: ${value}`;
44
62
  }
45
63
  return `${result}${space.slice(0, -2)}}${lastChar}`;
46
64
  }
@@ -25,6 +25,16 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
25
25
  if (['boolean', 'number', 'null'].includes(schema.type)) {
26
26
  return `${schema.type}${lastChar}`;
27
27
  }
28
+ if (schema.oneOf) {
29
+ let result = '';
30
+ for (const item of schema.oneOf) {
31
+ if (result) {
32
+ result += ' | ';
33
+ }
34
+ result += generateSchemaTypes(item, spaces + 2, '');
35
+ }
36
+ return result + lastChar;
37
+ }
28
38
  if (schema.type === 'array') {
29
39
  if (!schema.items)
30
40
  return `any[]${lastChar}`;
@@ -36,15 +46,23 @@ function generateSchemaTypes(schema, spaces = 2, lastChar = '\n') {
36
46
  }
37
47
  let result = '{\n';
38
48
  const required = schema.required || [];
39
- for (const key in schema.properties) {
40
- const prop = schema.properties[key];
41
- const splitter = required.includes(key) || hasDefault(prop)
42
- ? ':'
43
- : '?:';
44
- result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
49
+ const hasProps = Boolean(schema.properties && Object.keys(schema.properties).length);
50
+ const hasRestProps = Boolean(typeof schema.additionalProperties === 'object' &&
51
+ Object.keys(schema.additionalProperties).length);
52
+ if (hasProps) {
53
+ for (const key in schema.properties) {
54
+ const prop = schema.properties[key];
55
+ const splitter = required.includes(key) || hasDefault(prop)
56
+ ? ':'
57
+ : '?:';
58
+ result += `${space}${key}${splitter} ${generateSchemaTypes(prop, spaces + 2)}`;
59
+ }
45
60
  }
46
- if (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length) {
47
- result += `${space}[key: string]: any\n`;
61
+ if (hasRestProps) {
62
+ const value = hasProps
63
+ ? 'any\n'
64
+ : generateSchemaTypes(schema.additionalProperties, spaces + 2);
65
+ result += `${space}[key: string]: ${value}`;
48
66
  }
49
67
  return `${result}${space.slice(0, -2)}}${lastChar}`;
50
68
  }