@miso.ai/client-sdk-codegen 1.11.6-beta.0 → 1.11.6-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/cjs/codegen.js +11 -24
- package/dist/cjs/index.js +8 -18
- package/dist/cjs/output.js +37 -0
- package/dist/cjs/params.js +11 -3
- package/dist/cjs/spec/features.js +30 -26
- package/dist/cjs/spec/index.js +15 -5
- package/dist/cjs/spec/presets.js +29 -0
- package/dist/cjs/spec/utils.js +10 -0
- package/dist/cjs/spec/workflows.js +25 -29
- package/dist/cjs/spec/workflows.slug.js +23 -0
- package/dist/cjs/template/client.js +29 -0
- package/dist/cjs/template/entrypoints.js +15 -0
- package/dist/cjs/template/features.js +19 -0
- package/dist/cjs/{utils.js → template/helpers.js} +26 -8
- package/dist/cjs/template/index.js +39 -0
- package/dist/cjs/ui/hybrid-search.js +74 -0
- package/dist/cjs/ui/index.js +38 -0
- package/dist/cjs/ui/search.js +91 -0
- package/dist/cjs/ui/ui.js +36 -0
- package/package.json +2 -2
- package/src/codegen.js +8 -20
- package/src/index.js +2 -2
- package/src/output.js +33 -0
- package/src/params.js +11 -2
- package/src/spec/features.js +24 -26
- package/src/spec/index.js +2 -5
- package/src/spec/presets.js +24 -0
- package/src/spec/utils.js +5 -0
- package/src/spec/workflows.js +23 -35
- package/src/spec/workflows.slug.js +24 -0
- package/src/template/client.js +25 -0
- package/src/template/entrypoints.js +10 -0
- package/src/template/features.js +10 -0
- package/src/{utils.js → template/helpers.js} +19 -0
- package/src/template/index.js +4 -0
- package/src/ui/hybrid-search.js +71 -0
- package/src/ui/index.js +3 -0
- package/src/ui/search.js +91 -0
- package/src/ui/ui.js +26 -0
- package/dist/cjs/features.js +0 -12
- package/dist/cjs/templates.js +0 -34
- package/dist/cjs/workflow/hybrid-search.js +0 -51
- package/dist/cjs/workflow/index.js +0 -22
- package/src/features.js +0 -5
- package/src/templates.js +0 -26
- package/src/workflow/hybrid-search.js +0 -48
- package/src/workflow/index.js +0 -3
package/dist/cjs/codegen.js
CHANGED
|
@@ -4,33 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.codegen = codegen;
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function
|
|
7
|
+
var _index = require("./ui/index.js");
|
|
8
|
+
var _output = _interopRequireDefault(require("./output.js"));
|
|
9
|
+
const _excluded = ["schema"];
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
12
|
-
function
|
|
13
|
-
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12
|
+
function codegen(_ref = {}) {
|
|
14
13
|
let {
|
|
15
|
-
|
|
14
|
+
schema = 'ui'
|
|
16
15
|
} = _ref,
|
|
17
16
|
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
switch (schema) {
|
|
18
|
+
case 'ui':
|
|
19
|
+
return new _output.default((0, _index.ui)(options));
|
|
20
|
+
default:
|
|
21
|
+
throw new Error(`Unrecognized schema: "${schema}"`);
|
|
21
22
|
}
|
|
22
|
-
workflow = workflow.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
23
|
-
return Object.assign({
|
|
24
|
-
workflow
|
|
25
|
-
}, options);
|
|
26
|
-
}
|
|
27
|
-
function codegen(options) {
|
|
28
|
-
options = normalizeOptions(options);
|
|
29
|
-
const {
|
|
30
|
-
workflow
|
|
31
|
-
} = options;
|
|
32
|
-
if (!workflows[workflow]) {
|
|
33
|
-
throw new Error(`Workflow "${workflow}" is not found`);
|
|
34
|
-
}
|
|
35
|
-
return workflows[workflow](options);
|
|
36
23
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -4,9 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
-
|
|
7
|
+
spec: true,
|
|
8
|
+
ui: true
|
|
8
9
|
};
|
|
9
|
-
exports.
|
|
10
|
+
exports.ui = exports.spec = void 0;
|
|
11
|
+
var _spec = _interopRequireWildcard(require("./spec/index.js"));
|
|
12
|
+
exports.spec = _spec;
|
|
10
13
|
var _params = require("./params.js");
|
|
11
14
|
Object.keys(_params).forEach(function (key) {
|
|
12
15
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -31,19 +34,6 @@ Object.keys(_codegen).forEach(function (key) {
|
|
|
31
34
|
}
|
|
32
35
|
});
|
|
33
36
|
});
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
38
|
-
if (key in exports && exports[key] === _index[key]) return;
|
|
39
|
-
Object.defineProperty(exports, key, {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
get: function () {
|
|
42
|
-
return _index[key];
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
var _workflows = _interopRequireWildcard(require("./workflow/index.js"));
|
|
47
|
-
exports.workflows = _workflows;
|
|
48
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
49
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
37
|
+
var _ui = _interopRequireWildcard(require("./ui/index.js"));
|
|
38
|
+
exports.ui = _ui;
|
|
39
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
class Output {
|
|
8
|
+
constructor(items) {
|
|
9
|
+
this._items = items;
|
|
10
|
+
}
|
|
11
|
+
get items() {
|
|
12
|
+
return this._items;
|
|
13
|
+
}
|
|
14
|
+
[Symbol.iterator]() {
|
|
15
|
+
return this._items[Symbol.iterator]();
|
|
16
|
+
}
|
|
17
|
+
concat() {
|
|
18
|
+
return this._items.filter(item => item).map(item => asHtml(item)).join('\n');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = Output;
|
|
22
|
+
function asHtml({
|
|
23
|
+
type,
|
|
24
|
+
content
|
|
25
|
+
} = {}) {
|
|
26
|
+
// TODO: minify
|
|
27
|
+
switch (type) {
|
|
28
|
+
case 'html':
|
|
29
|
+
return content;
|
|
30
|
+
case 'js':
|
|
31
|
+
return `<script async>\n${content}\n</script>`;
|
|
32
|
+
case 'css':
|
|
33
|
+
return `<style>\n${content}\n</style>`;
|
|
34
|
+
default:
|
|
35
|
+
throw new Error(`Unrecognized type: "${type}"`);
|
|
36
|
+
}
|
|
37
|
+
}
|
package/dist/cjs/params.js
CHANGED
|
@@ -5,14 +5,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.decodeParameters = decodeParameters;
|
|
7
7
|
exports.encodeParameters = encodeParameters;
|
|
8
|
-
function encodeParameters() {
|
|
9
|
-
|
|
8
|
+
function encodeParameters(params) {
|
|
9
|
+
if (params === undefined || params === null) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
if (typeof params !== 'object') {
|
|
13
|
+
throw new Error('params must be an object');
|
|
14
|
+
}
|
|
10
15
|
// JSON string -> base64
|
|
11
16
|
return base64Encode(JSON.stringify(params));
|
|
12
17
|
}
|
|
13
18
|
function decodeParameters(params) {
|
|
19
|
+
if (params === undefined || params === null) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
14
22
|
// base64 -> JSON string
|
|
15
|
-
return
|
|
23
|
+
return JSON.parse(base64Decode(params));
|
|
16
24
|
}
|
|
17
25
|
function base64Encode(str) {
|
|
18
26
|
return typeof window !== 'undefined' ? window.btoa(str) : Buffer.from(str).toString('base64');
|
|
@@ -3,38 +3,42 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
const
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _utils = require("./utils.js");
|
|
8
|
+
var _workflowsSlug = require("./workflows.slug.js");
|
|
9
|
+
const _excluded = ["slug", "workflows"];
|
|
10
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
11
|
+
var _default = exports.default = [{
|
|
10
12
|
slug: 'use-api',
|
|
11
|
-
|
|
12
|
-
workflows: (0, _workflows.resolveWorkflows)('*')
|
|
13
|
+
workflows: '*'
|
|
13
14
|
}, {
|
|
14
15
|
slug: 'use-link',
|
|
15
|
-
|
|
16
|
-
workflows: (0, _workflows.resolveWorkflows)('ahes')
|
|
17
|
-
}, {
|
|
18
|
-
slug: 'follow-up',
|
|
19
|
-
name: 'Follow Up',
|
|
20
|
-
workflows: (0, _workflows.resolveWorkflows)('a')
|
|
21
|
-
}, {
|
|
22
|
-
slug: 'auto-query',
|
|
23
|
-
name: 'Auto Query',
|
|
24
|
-
workflows: (0, _workflows.resolveWorkflows)('ahes')
|
|
16
|
+
workflows: 'ahes'
|
|
25
17
|
}, {
|
|
26
18
|
slug: 'autocomplete',
|
|
27
|
-
|
|
28
|
-
workflows: (0, _workflows.resolveWorkflows)('hs')
|
|
19
|
+
workflows: 'hs'
|
|
29
20
|
}, {
|
|
30
21
|
slug: 'pagination',
|
|
31
|
-
|
|
32
|
-
workflows: (0, _workflows.resolveWorkflows)('hs')
|
|
22
|
+
workflows: 'hs'
|
|
33
23
|
}, {
|
|
34
24
|
slug: 'facets',
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
workflows: 'hs'
|
|
26
|
+
}, {
|
|
27
|
+
slug: 'follow-up',
|
|
28
|
+
workflows: 'a'
|
|
29
|
+
}, {
|
|
30
|
+
slug: 'auto-query',
|
|
31
|
+
workflows: 'ahes'
|
|
32
|
+
}].reduce((map, _ref) => {
|
|
33
|
+
let {
|
|
34
|
+
slug,
|
|
35
|
+
workflows
|
|
36
|
+
} = _ref,
|
|
37
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
38
|
+
map[slug] = Object.freeze(Object.assign({
|
|
39
|
+
slug,
|
|
40
|
+
name: (0, _utils.toName)(slug),
|
|
41
|
+
workflows: (0, _workflowsSlug.resolveWorkflows)(workflows)
|
|
42
|
+
}, rest));
|
|
43
|
+
return map;
|
|
44
|
+
}, {});
|
package/dist/cjs/spec/index.js
CHANGED
|
@@ -3,8 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
6
|
+
Object.defineProperty(exports, "features", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _features.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "workflows", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _workflows.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _workflows = _interopRequireDefault(require("./workflows.js"));
|
|
19
|
+
var _features = _interopRequireDefault(require("./features.js"));
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.search = exports.hybridSearch = void 0;
|
|
7
|
+
const hybridSearch = exports.hybridSearch = Object.freeze({
|
|
8
|
+
standard: Object.freeze({
|
|
9
|
+
workflow: 'hybrid-search',
|
|
10
|
+
autoQuery: true,
|
|
11
|
+
autocomplete: true,
|
|
12
|
+
facets: ['categories'],
|
|
13
|
+
answerBox: true
|
|
14
|
+
}),
|
|
15
|
+
minimal: Object.freeze({
|
|
16
|
+
workflow: 'hybrid-search'
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
const search = exports.search = Object.freeze({
|
|
20
|
+
standard: Object.freeze({
|
|
21
|
+
workflow: 'search',
|
|
22
|
+
autoQuery: true,
|
|
23
|
+
autocomplete: true
|
|
24
|
+
//facets: ['categories'],
|
|
25
|
+
}),
|
|
26
|
+
minimal: Object.freeze({
|
|
27
|
+
workflow: 'search'
|
|
28
|
+
})
|
|
29
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toName = toName;
|
|
7
|
+
var _commons = require("@miso.ai/commons");
|
|
8
|
+
function toName(str) {
|
|
9
|
+
return (0, _commons.capitalize)((0, _commons.kebabOrSnakeToHuman)(str));
|
|
10
|
+
}
|
|
@@ -3,34 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.resolveWorkflows = resolveWorkflows;
|
|
6
|
+
exports.default = void 0;
|
|
8
7
|
var _commons = require("@miso.ai/commons");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}, {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
slug
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (!ABV_TO_WORKFLOW[abv]) {
|
|
32
|
-
throw new Error(`Workflow "${abv}" is not found`);
|
|
33
|
-
}
|
|
34
|
-
return ABV_TO_WORKFLOW[abv];
|
|
8
|
+
var _utils = require("./utils.js");
|
|
9
|
+
var _workflowsSlug = require("./workflows.slug.js");
|
|
10
|
+
var _features = _interopRequireDefault(require("./features.js"));
|
|
11
|
+
var presets = _interopRequireWildcard(require("./presets.js"));
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function getFeatures(features, slug) {
|
|
15
|
+
return Object.values(features).filter(feature => feature.workflows.includes(slug));
|
|
16
|
+
}
|
|
17
|
+
function getPresets(presets, slug) {
|
|
18
|
+
return Object.entries(presets[(0, _commons.kebabToLowerCamel)(slug)] || {}).map(([key, value]) => Object.freeze({
|
|
19
|
+
slug: key,
|
|
20
|
+
name: (0, _utils.toName)(key),
|
|
21
|
+
value
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
var _default = exports.default = _workflowsSlug.WORKFLOW_SLUGS.reduce((obj, slug) => {
|
|
25
|
+
obj[slug] = Object.freeze({
|
|
26
|
+
slug,
|
|
27
|
+
name: (0, _utils.toName)(slug),
|
|
28
|
+
features: getFeatures(_features.default, slug),
|
|
29
|
+
presets: getPresets(presets, slug)
|
|
35
30
|
});
|
|
36
|
-
|
|
31
|
+
return obj;
|
|
32
|
+
}, {});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.WORKFLOW_SLUGS = void 0;
|
|
7
|
+
exports.resolveWorkflows = resolveWorkflows;
|
|
8
|
+
const WORKFLOW_SLUGS = exports.WORKFLOW_SLUGS = ['ask', 'hybrid-search', 'explore', 'search', 'recommendation'];
|
|
9
|
+
const ABV_TO_WORKFLOW = WORKFLOW_SLUGS.reduce((map, slug) => {
|
|
10
|
+
map[slug.charAt(0)] = slug;
|
|
11
|
+
return map;
|
|
12
|
+
}, {});
|
|
13
|
+
function resolveWorkflows(abvs) {
|
|
14
|
+
if (abvs === '*') {
|
|
15
|
+
return [...WORKFLOW_SLUGS];
|
|
16
|
+
}
|
|
17
|
+
return abvs.split('').map(abv => {
|
|
18
|
+
if (!ABV_TO_WORKFLOW[abv]) {
|
|
19
|
+
throw new Error(`Workflow "${abv}" is not found`);
|
|
20
|
+
}
|
|
21
|
+
return ABV_TO_WORKFLOW[abv];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createClient = createClient;
|
|
7
|
+
var _helpers = require("./helpers.js");
|
|
8
|
+
function createClient(options) {
|
|
9
|
+
return (0, _helpers.blocks)(`const MisoClient = window.MisoClient;`, ...clientPlugins(options), `const client = new MisoClient(${clientOptions(options)});`);
|
|
10
|
+
}
|
|
11
|
+
function clientPlugins({
|
|
12
|
+
dryRun
|
|
13
|
+
} = {}) {
|
|
14
|
+
const blocks = [];
|
|
15
|
+
if (dryRun) {
|
|
16
|
+
blocks.push(`MisoClient.plugins.use("std:dry-run");`);
|
|
17
|
+
}
|
|
18
|
+
return blocks;
|
|
19
|
+
}
|
|
20
|
+
function clientOptions({
|
|
21
|
+
apiKey,
|
|
22
|
+
apiKeyParam = false
|
|
23
|
+
} = {}) {
|
|
24
|
+
if (!apiKeyParam) {
|
|
25
|
+
return `'${apiKey}'`;
|
|
26
|
+
}
|
|
27
|
+
apiKeyParam = apiKeyParam === true ? 'api-key' : apiKeyParam;
|
|
28
|
+
return `new URLSearchParams(window.location.search).get('${apiKeyParam}') || '${apiKey}'`;
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.misocmd = misocmd;
|
|
7
|
+
var _helpers = require("./helpers.js");
|
|
8
|
+
function misocmd(body) {
|
|
9
|
+
return `
|
|
10
|
+
const misocmd = window.misocmd || (window.misocmd = []);
|
|
11
|
+
misocmd.push(async () => {
|
|
12
|
+
${(0, _helpers.indent)(body, 2)}
|
|
13
|
+
});
|
|
14
|
+
`.trim();
|
|
15
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.autoQuery = autoQuery;
|
|
7
|
+
exports.facets = facets;
|
|
8
|
+
var _helpers = require("./helpers.js");
|
|
9
|
+
function facets(options) {
|
|
10
|
+
return options ? `workflow.useFacets(${(0, _helpers.format)(options, {
|
|
11
|
+
multiline: true
|
|
12
|
+
})});` : '';
|
|
13
|
+
}
|
|
14
|
+
function autoQuery(options) {
|
|
15
|
+
// TODO: consider when options === false
|
|
16
|
+
return options ? `workflow.autoQuery(${typeof options === 'object' ? (0, _helpers.format)(options, {
|
|
17
|
+
multiline: true
|
|
18
|
+
}) : ''});` : '';
|
|
19
|
+
}
|
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.blocks = blocks;
|
|
6
7
|
exports.format = format;
|
|
7
8
|
exports.indent = indent;
|
|
9
|
+
exports.paragraphs = paragraphs;
|
|
8
10
|
exports.resolvePreset = resolvePreset;
|
|
9
11
|
const _excluded = ["preset"];
|
|
10
12
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
11
|
-
function indent(str) {
|
|
12
|
-
|
|
13
|
+
function indent(str, level = 1) {
|
|
14
|
+
// TODO: trim and deal with blank lines
|
|
13
15
|
return str.replace(/\n/g, '\n' + ' '.repeat(level));
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -20,15 +22,32 @@ function indent(str) {
|
|
|
20
22
|
* @param {boolean} options.multiline - Whether to use multiline
|
|
21
23
|
* @returns {string}
|
|
22
24
|
*/
|
|
23
|
-
function format(value
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25
|
+
function format(value, {
|
|
26
|
+
multiline = false
|
|
27
|
+
} = {}) {
|
|
27
28
|
// use single quote
|
|
28
29
|
// no quote for simple key in object
|
|
29
30
|
return JSON.stringify(value, null, multiline ? 2 : 0).replace(/"/g, "'").replace(/\s*:\s*/g, ': ');
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Join blocks with proper newlines
|
|
35
|
+
* @param {string[]} blocks - Blocks to join
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
function blocks(...blocks) {
|
|
39
|
+
return blocks.map(block => block.trim()).filter(block => block).join('\n');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Join paragraphs with proper newlines
|
|
44
|
+
* @param {string[]} paragraphs - Paragraphs to join
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
function paragraphs(...paragraphs) {
|
|
48
|
+
return paragraphs.map(paragraph => paragraph.trim()).filter(paragraph => paragraph).join('\n\n');
|
|
49
|
+
}
|
|
50
|
+
|
|
32
51
|
/**
|
|
33
52
|
* Resolve preset options
|
|
34
53
|
* @param {Object} presets - Available presets
|
|
@@ -37,8 +56,7 @@ function format(value) {
|
|
|
37
56
|
* @param {Object} options - Other options
|
|
38
57
|
* @returns {Object} Resolved options
|
|
39
58
|
*/
|
|
40
|
-
function resolvePreset(presets) {
|
|
41
|
-
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
59
|
+
function resolvePreset(presets, _ref = {}) {
|
|
42
60
|
let {
|
|
43
61
|
preset
|
|
44
62
|
} = _ref,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
features: true,
|
|
8
|
+
helpers: true
|
|
9
|
+
};
|
|
10
|
+
exports.helpers = exports.features = void 0;
|
|
11
|
+
var _entrypoints = require("./entrypoints.js");
|
|
12
|
+
Object.keys(_entrypoints).forEach(function (key) {
|
|
13
|
+
if (key === "default" || key === "__esModule") return;
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
15
|
+
if (key in exports && exports[key] === _entrypoints[key]) return;
|
|
16
|
+
Object.defineProperty(exports, key, {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () {
|
|
19
|
+
return _entrypoints[key];
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
var _client = require("./client.js");
|
|
24
|
+
Object.keys(_client).forEach(function (key) {
|
|
25
|
+
if (key === "default" || key === "__esModule") return;
|
|
26
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
27
|
+
if (key in exports && exports[key] === _client[key]) return;
|
|
28
|
+
Object.defineProperty(exports, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () {
|
|
31
|
+
return _client[key];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
var _features = _interopRequireWildcard(require("./features.js"));
|
|
36
|
+
exports.features = _features;
|
|
37
|
+
var _helpers = _interopRequireWildcard(require("./helpers.js"));
|
|
38
|
+
exports.helpers = _helpers;
|
|
39
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hybridSearch = hybridSearch;
|
|
7
|
+
var _presets = require("../spec/presets.js");
|
|
8
|
+
var _helpers = require("../template/helpers.js");
|
|
9
|
+
var _index = require("../template/index.js");
|
|
10
|
+
var _features = require("../template/features.js");
|
|
11
|
+
const _excluded = ["facets"];
|
|
12
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
13
|
+
// TODO: refactor these
|
|
14
|
+
function normalizeOptions(_ref = {}) {
|
|
15
|
+
let {
|
|
16
|
+
facets
|
|
17
|
+
} = _ref,
|
|
18
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
19
|
+
if (facets === true) {
|
|
20
|
+
facets = ['categories'];
|
|
21
|
+
}
|
|
22
|
+
return Object.assign({}, options, {
|
|
23
|
+
facets
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function hybridSearch(options) {
|
|
27
|
+
options = normalizeOptions((0, _helpers.resolvePreset)(_presets.hybridSearch, options));
|
|
28
|
+
const items = [{
|
|
29
|
+
type: 'html',
|
|
30
|
+
name: 'HTML',
|
|
31
|
+
content: html(options)
|
|
32
|
+
}, {
|
|
33
|
+
type: 'js',
|
|
34
|
+
name: 'JavaScript',
|
|
35
|
+
content: js(options)
|
|
36
|
+
}];
|
|
37
|
+
return items;
|
|
38
|
+
}
|
|
39
|
+
function js(options) {
|
|
40
|
+
// TODO: support loading from Node module
|
|
41
|
+
// TODO: useLink
|
|
42
|
+
return (0, _index.misocmd)(`
|
|
43
|
+
// client
|
|
44
|
+
${(0, _index.createClient)(options)}
|
|
45
|
+
|
|
46
|
+
// workflow
|
|
47
|
+
const workflow = client.ui.hybridSearch;
|
|
48
|
+
|
|
49
|
+
// setup: TODO
|
|
50
|
+
|
|
51
|
+
${jsElements(options)}
|
|
52
|
+
|
|
53
|
+
${(0, _features.autoQuery)(options.autoQuery)}
|
|
54
|
+
`);
|
|
55
|
+
}
|
|
56
|
+
function jsElements(options) {
|
|
57
|
+
if (options.elements === false) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
60
|
+
return `
|
|
61
|
+
// render Miso elements
|
|
62
|
+
await client.ui.ready;
|
|
63
|
+
const { templates, wireAnswerBox } = MisoClient.ui.defaults.hybridSearch;
|
|
64
|
+
const rootElement = document.querySelector('#miso-hybrid-search-combo');
|
|
65
|
+
rootElement.innerHTML = templates.root();
|
|
66
|
+
wireAnswerBox(client, rootElement);
|
|
67
|
+
`.trim();
|
|
68
|
+
}
|
|
69
|
+
function html(options) {
|
|
70
|
+
if (options.elements === false) {
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
return `<div id="miso-hybrid-search-combo" class="miso-hybrid-search-combo"></div>`.trim();
|
|
74
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _hybridSearch = require("./hybrid-search.js");
|
|
7
|
+
Object.keys(_hybridSearch).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _hybridSearch[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _hybridSearch[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _search = require("./search.js");
|
|
18
|
+
Object.keys(_search).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _search[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _search[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _ui = require("./ui.js");
|
|
29
|
+
Object.keys(_ui).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _ui[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _ui[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|