cozy-search 2.3.2 → 2.3.3

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.
@@ -42,7 +42,8 @@ const makeClient = ({
42
42
  query: jest.fn(async definition => {
43
43
  if (definition.doctype === 'io.cozy.ai.chat.assistants') {
44
44
  const doc = assistants[definition.id]
45
- if (!doc) throw notFound()
45
+ // cozy-client answers a 404 on getById with a null document.
46
+ if (!doc) return { data: null }
46
47
  return { data: doc }
47
48
  }
48
49
  throw new Error(`unexpected query ${definition.doctype}`)
@@ -398,7 +399,7 @@ describe('ensureProvisionedAssistants', () => {
398
399
  client.query.mockImplementation(async definition => {
399
400
  if (definition.doctype === 'io.cozy.ai.chat.assistants') {
400
401
  queries += 1
401
- if (queries === 1) throw notFound()
402
+ if (queries === 1) return { data: null }
402
403
  return {
403
404
  data: {
404
405
  _id: 'docs',
@@ -86,7 +86,7 @@ var DeleteAssistantDialog = function DeleteAssistantDialog(_ref) {
86
86
  isDeleting = _useState2[0],
87
87
  setIsDeleting = _useState2[1];
88
88
 
89
- var assistantQuery = (0, _queries.buildAssistantByIdQuery)(assistantIdInAction);
89
+ var assistantQuery = (0, _queries.buildAssistantByIdWithProviderQuery)(assistantIdInAction);
90
90
 
91
91
  var _ref2 = (0, _cozyClient.useQuery)(assistantQuery.definition, assistantQuery.options) || {},
92
92
  assistant = _ref2.data,
@@ -120,13 +120,13 @@ var EditAssistantDialog = function EditAssistantDialog(_ref) {
120
120
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
121
121
  var _assistant$relationsh, _assistant$relationsh2, _assistant$relationsh3, _assistant$relationsh4, _provider$data, _provider$auth, _provider$data2, _provider$auth2, _provider$auth3, _provider$data3, _provider$auth4;
122
122
 
123
- var _buildAssistantByIdQu, definition, options, response, assistant, provider, providerId, model, selectProviderDefault;
123
+ var _buildAssistantByIdWi, definition, options, response, assistant, provider, providerId, model, selectProviderDefault;
124
124
 
125
125
  return _regenerator.default.wrap(function _callee$(_context) {
126
126
  while (1) {
127
127
  switch (_context.prev = _context.next) {
128
128
  case 0:
129
- _buildAssistantByIdQu = (0, _queries.buildAssistantByIdQuery)(assistantIdInAction), definition = _buildAssistantByIdQu.definition, options = _buildAssistantByIdQu.options;
129
+ _buildAssistantByIdWi = (0, _queries.buildAssistantByIdWithProviderQuery)(assistantIdInAction), definition = _buildAssistantByIdWi.definition, options = _buildAssistantByIdWi.options;
130
130
  _context.next = 3;
131
131
  return client.query(definition(), {
132
132
  as: options.as
@@ -43,6 +43,15 @@ export function buildAssistantByIdQuery(id: any): {
43
43
  enabled: boolean;
44
44
  };
45
45
  };
46
+ export function buildAssistantByIdWithProviderQuery(id: any): {
47
+ definition: () => import("cozy-client").QueryDefinition;
48
+ options: {
49
+ as: string;
50
+ fetchPolicy: Function;
51
+ singleDocData: boolean;
52
+ enabled: boolean;
53
+ };
54
+ };
46
55
  export function buildFileByIdQuery(fileId: any): {
47
56
  definition: () => import("cozy-client").QueryDefinition;
48
57
  options: {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.buildMyselfQuery = exports.buildFilesByIds = exports.buildFileByIdQuery = exports.buildChatConversationsQuery = exports.buildChatConversationQueryById = exports.buildAssistantsQuery = exports.buildAssistantByIdQuery = exports.buildAllAssistantsQuery = exports.FILES_DOCTYPE = exports.EMAIL_DOCTYPE = exports.CHAT_EVENTS_DOCTYPE = exports.CHAT_CONVERSATIONS_DOCTYPE = exports.ASSISTANTS_DOCTYPE = exports.ACCOUNTS_DOCTYPE = void 0;
6
+ exports.buildMyselfQuery = exports.buildFilesByIds = exports.buildFileByIdQuery = exports.buildChatConversationsQuery = exports.buildChatConversationQueryById = exports.buildAssistantsQuery = exports.buildAssistantByIdWithProviderQuery = exports.buildAssistantByIdQuery = exports.buildAllAssistantsQuery = exports.FILES_DOCTYPE = exports.EMAIL_DOCTYPE = exports.CHAT_EVENTS_DOCTYPE = exports.CHAT_CONVERSATIONS_DOCTYPE = exports.ASSISTANTS_DOCTYPE = exports.ACCOUNTS_DOCTYPE = void 0;
7
7
 
8
8
  var _cozyClient = require("cozy-client");
9
9
 
@@ -78,14 +78,16 @@ var buildAssistantsQuery = function buildAssistantsQuery() {
78
78
  fetchPolicy: defaultFetchPolicy
79
79
  }
80
80
  };
81
- };
81
+ }; // The bare assistant document. On a missing id cozy-client resolves to
82
+ // `{ data: null }` rather than throwing, which callers can rely on.
83
+
82
84
 
83
85
  exports.buildAssistantsQuery = buildAssistantsQuery;
84
86
 
85
87
  var buildAssistantByIdQuery = function buildAssistantByIdQuery(id) {
86
88
  return {
87
89
  definition: function definition() {
88
- return (0, _cozyClient.Q)('io.cozy.ai.chat.assistants').getById(id).include(['provider']);
90
+ return (0, _cozyClient.Q)('io.cozy.ai.chat.assistants').getById(id);
89
91
  },
90
92
  options: {
91
93
  as: 'io.cozy.ai.chat.assistants/' + id,
@@ -94,10 +96,29 @@ var buildAssistantByIdQuery = function buildAssistantByIdQuery(id) {
94
96
  enabled: !!id
95
97
  }
96
98
  };
97
- };
99
+ }; // The assistant with its provider account in `included`. Only for ids known
100
+ // to exist: resolving the include on a missing document throws a TypeError
101
+ // in cozy-client instead of yielding a null document.
102
+
98
103
 
99
104
  exports.buildAssistantByIdQuery = buildAssistantByIdQuery;
100
105
 
106
+ var buildAssistantByIdWithProviderQuery = function buildAssistantByIdWithProviderQuery(id) {
107
+ return {
108
+ definition: function definition() {
109
+ return (0, _cozyClient.Q)('io.cozy.ai.chat.assistants').getById(id).include(['provider']);
110
+ },
111
+ options: {
112
+ as: 'io.cozy.ai.chat.assistants/' + id + '/with-provider',
113
+ fetchPolicy: defaultFetchPolicy,
114
+ singleDocData: true,
115
+ enabled: !!id
116
+ }
117
+ };
118
+ };
119
+
120
+ exports.buildAssistantByIdWithProviderQuery = buildAssistantByIdWithProviderQuery;
121
+
101
122
  var buildFileByIdQuery = function buildFileByIdQuery(fileId) {
102
123
  return {
103
124
  definition: function definition() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cozy-search",
3
3
  "description": "UI components about search bar and IA assistant",
4
- "version": "2.3.2",
4
+ "version": "2.3.3",
5
5
  "author": {
6
6
  "name": "Cozy Cloud",
7
7
  "url": "https://github.com/cozy"
@@ -96,5 +96,5 @@
96
96
  "lint": "cd .. && yarn eslint --ext js,jsx,ts packages/cozy-search"
97
97
  },
98
98
  "types": "dist/index.d.ts",
99
- "gitHead": "96598a165eae6c8eef3da4b6451af1dfdb8801a0"
99
+ "gitHead": "5269c3bcf245d4e9e47cbefd29286aa733602bb7"
100
100
  }