@sparted/shared-library 1.7.19 → 1.7.21
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/business/types/content.d.ts +36 -0
- package/business/types/content.js +8 -1
- package/business/types/content.js.map +1 -1
- package/business/types/index.js +1 -0
- package/business/types/index.js.map +1 -1
- package/http/build-search-params.js +1 -3
- package/http/build-search-params.js.map +1 -1
- package/http/encode-search-object.js +1 -4
- package/http/encode-search-object.js.map +1 -1
- package/http/fetch-with-timeout.js.map +1 -1
- package/package.json +1 -1
- package/types/search.d.ts +3 -3
|
@@ -1109,3 +1109,39 @@ export declare const isPartialGameSwipingCards: (game: DeepPartial<Game>) => gam
|
|
|
1109
1109
|
"th-TH"?: string | undefined;
|
|
1110
1110
|
} | undefined;
|
|
1111
1111
|
};
|
|
1112
|
+
export declare const extractExplanation: (content: Content) => Partial<{
|
|
1113
|
+
sk: string;
|
|
1114
|
+
sl: string;
|
|
1115
|
+
ar: string;
|
|
1116
|
+
lt: string;
|
|
1117
|
+
"en-US": string;
|
|
1118
|
+
"fr-FR": string;
|
|
1119
|
+
"es-ES": string;
|
|
1120
|
+
"it-IT": string;
|
|
1121
|
+
"de-DE": string;
|
|
1122
|
+
"ru-RU": string;
|
|
1123
|
+
"nl-NL": string;
|
|
1124
|
+
"pt-BR": string;
|
|
1125
|
+
"zh-CN": string;
|
|
1126
|
+
"he-IL": string;
|
|
1127
|
+
"cs-CZ": string;
|
|
1128
|
+
"ko-KR": string;
|
|
1129
|
+
"ja-JP": string;
|
|
1130
|
+
"zh-TW": string;
|
|
1131
|
+
"bg-BG": string;
|
|
1132
|
+
"hr-HR": string;
|
|
1133
|
+
"da-DK": string;
|
|
1134
|
+
"fi-FI": string;
|
|
1135
|
+
"el-GR": string;
|
|
1136
|
+
"hu-HU": string;
|
|
1137
|
+
"nb-NO": string;
|
|
1138
|
+
"pl-PL": string;
|
|
1139
|
+
"pt-PT": string;
|
|
1140
|
+
"ro-RO": string;
|
|
1141
|
+
"sv-SE": string;
|
|
1142
|
+
"tr-TR": string;
|
|
1143
|
+
"et-EE": string;
|
|
1144
|
+
"id-ID": string;
|
|
1145
|
+
"lv-LV": string;
|
|
1146
|
+
"th-TH": string;
|
|
1147
|
+
}> | undefined;
|
|
@@ -24,9 +24,16 @@ const isPartialGameOpenQuestion = (game) => game.type === GAME_TYPE.OPEN_QUESTIO
|
|
|
24
24
|
const isPartialGameNoInteraction = (game) => game.type === GAME_TYPE.NO_INTERACTION;
|
|
25
25
|
const isPartialGamePictureSpot = (game) => game.type === GAME_TYPE.PICTURE_SPOT;
|
|
26
26
|
const isPartialGameOrderingCards = (game) => game.type === GAME_TYPE.ORDERING_CARDS;
|
|
27
|
-
const isPartialGameSwipingCards = (game) => game.type === GAME_TYPE.SWIPING_CARDS;
|
|
27
|
+
const isPartialGameSwipingCards = (game) => game.type === GAME_TYPE.SWIPING_CARDS;
|
|
28
|
+
const extractExplanation = (content) => {
|
|
29
|
+
if (!content.game || content.game.type === 'no-interaction') {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return content.game.explanation;
|
|
33
|
+
};
|
|
28
34
|
|
|
29
35
|
exports.GAME_TYPE = GAME_TYPE;
|
|
36
|
+
exports.extractExplanation = extractExplanation;
|
|
30
37
|
exports.isGameErrorText = isGameErrorText;
|
|
31
38
|
exports.isGameMultipleChoiceQuestion = isGameMultipleChoiceQuestion;
|
|
32
39
|
exports.isGameNoInteraction = isGameNoInteraction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sources":["../../../src/business/types/content.ts"],"sourcesContent":["import { DeepPartial } from 'ts-essentials';\n\nimport { Image, Media } from './media';\nimport { LanguageCode, MultilingualLabel } from './multilingual';\nimport { Thematic } from './thematic';\n\nexport type ErrorText = {\n id: number;\n type: 'error-text';\n gameMedia: Media;\n wrongText: MultilingualLabel;\n correctText: MultilingualLabel;\n explanationMedia: Media;\n explanation: MultilingualLabel;\n};\n\nexport type ChoiceQuestion = {\n text: MultilingualLabel;\n correct: boolean;\n};\n\nexport type MultipleChoiceQuestion = {\n id: number;\n type: 'mcq';\n gameMedia: Media;\n question: MultilingualLabel;\n choices: ChoiceQuestion[];\n explanationMedia: Media;\n explanation: MultilingualLabel;\n};\n\nexport type NoInteraction = {\n id: number;\n type: 'no-interaction';\n firstMedia: Media;\n title: MultilingualLabel;\n text: MultilingualLabel;\n secondMedia: Media;\n};\n\nexport type OpenQuestion = {\n id: number;\n type: 'open-question';\n gameMedia: Media;\n question: MultilingualLabel;\n answer: MultilingualLabel;\n levenshteinDistance: number;\n explanationMedia: Media;\n explanation: MultilingualLabel;\n};\n\nexport type OrderingCards = {\n id: number;\n type: 'ordering-cards';\n question: MultilingualLabel;\n topLabel: MultilingualLabel;\n cards: MultilingualLabel[];\n bottomLabel: MultilingualLabel;\n explanation: MultilingualLabel;\n};\n\nexport type Spot = {\n id: number;\n x: number;\n y: number;\n r: number;\n question: MultilingualLabel;\n description: MultilingualLabel;\n};\n\nexport type PictureSpot = {\n id: number;\n type: 'picture-spot';\n image: Image;\n items: Spot[];\n explanation: MultilingualLabel;\n};\n\nexport type SwipingCardPosition = 'left' | 'right' | 'top' | 'bottom';\n\nexport type SwipingCardZone = {\n position: SwipingCardPosition;\n text: MultilingualLabel;\n};\n\nexport type SwipingCard = {\n image?: Image;\n text?: MultilingualLabel;\n answer: SwipingCardPosition;\n};\n\nexport type SwipingCards = {\n id: number;\n type: 'swiping-cards';\n question: MultilingualLabel;\n zones: SwipingCardZone[];\n cards: SwipingCard[];\n explanation: MultilingualLabel;\n};\n\nexport type Game =\n | ErrorText\n | MultipleChoiceQuestion\n | NoInteraction\n | OpenQuestion\n | OrderingCards\n | PictureSpot\n | SwipingCards;\n\nexport type GameType =\n | 'error-text'\n | 'mcq'\n | 'open-question'\n | 'no-interaction'\n | 'picture-spot'\n | 'swiping-cards'\n | 'ordering-cards';\n\nexport const GAME_TYPE: Record<string, GameType> = {\n MCQ: 'mcq',\n ERROR_TEXT: 'error-text',\n OPEN_QUESTION: 'open-question',\n NO_INTERACTION: 'no-interaction',\n PICTURE_SPOT: 'picture-spot',\n ORDERING_CARDS: 'ordering-cards',\n SWIPING_CARDS: 'swiping-cards',\n};\n\nexport type ContentStatuses = Partial<{\n [languageCode in LanguageCode]: 'draft' | 'validated' | 'waiting-translation' | 'waiting-validation';\n}>;\n\nexport type ContentMetadata = {\n identifier: string;\n coverImage?: Image;\n name: MultilingualLabel;\n thematic: Thematic;\n type: GameType;\n};\n\nexport type Content = {\n archived: boolean;\n id: number;\n metadata: ContentMetadata;\n statuses: ContentStatuses;\n game?: Game;\n};\n\nexport const isGameMultipleChoiceQuestion = (game: Game): game is MultipleChoiceQuestion => game.type === GAME_TYPE.MCQ;\nexport const isGameErrorText = (game: Game): game is ErrorText => game.type === GAME_TYPE.ERROR_TEXT;\nexport const isGameOpenQuestion = (game: Game): game is OpenQuestion => game.type === GAME_TYPE.OPEN_QUESTION;\nexport const isGameNoInteraction = (game: Game): game is NoInteraction => game.type === GAME_TYPE.NO_INTERACTION;\nexport const isGamePictureSpot = (game: Game): game is PictureSpot => game.type === GAME_TYPE.PICTURE_SPOT;\nexport const isGameOrderingCards = (game: Game): game is OrderingCards => game.type === GAME_TYPE.ORDERING_CARDS;\nexport const isGameSwipingCards = (game: Game): game is SwipingCards => game.type === GAME_TYPE.SWIPING_CARDS;\n\nexport const isPartialGameMultipleChoiceQuestion = (\n game: DeepPartial<Game>,\n): game is DeepPartial<MultipleChoiceQuestion> => game.type === GAME_TYPE.MCQ;\nexport const isPartialGameErrorText = (game: DeepPartial<Game>): game is DeepPartial<ErrorText> =>\n game.type === GAME_TYPE.ERROR_TEXT;\nexport const isPartialGameOpenQuestion = (game: DeepPartial<Game>): game is DeepPartial<OpenQuestion> =>\n game.type === GAME_TYPE.OPEN_QUESTION;\nexport const isPartialGameNoInteraction = (game: DeepPartial<Game>): game is DeepPartial<NoInteraction> =>\n game.type === GAME_TYPE.NO_INTERACTION;\nexport const isPartialGamePictureSpot = (game: DeepPartial<Game>): game is DeepPartial<PictureSpot> =>\n game.type === GAME_TYPE.PICTURE_SPOT;\nexport const isPartialGameOrderingCards = (game: DeepPartial<Game>): game is DeepPartial<OrderingCards> =>\n game.type === GAME_TYPE.ORDERING_CARDS;\nexport const isPartialGameSwipingCards = (game: DeepPartial<Game>): game is DeepPartial<SwipingCards> =>\n game.type === GAME_TYPE.SWIPING_CARDS;\n"],"names":[],"mappings":";;;;AAsHa,MAAA,SAAS,GAA6B;AACjD,IAAA,GAAG,EAAE,KAAK;AACV,IAAA,UAAU,EAAE,YAAY;AACxB,IAAA,aAAa,EAAE,eAAe;AAC9B,IAAA,cAAc,EAAE,gBAAgB;AAChC,IAAA,YAAY,EAAE,cAAc;AAC5B,IAAA,cAAc,EAAE,gBAAgB;AAChC,IAAA,aAAa,EAAE,eAAe;EAC9B;AAsBW,MAAA,4BAA4B,GAAG,CAAC,IAAU,KAAqC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI;AAC3G,MAAA,eAAe,GAAG,CAAC,IAAU,KAAwB,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,WAAW;AACxF,MAAA,kBAAkB,GAAG,CAAC,IAAU,KAA2B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,cAAc;AACjG,MAAA,mBAAmB,GAAG,CAAC,IAAU,KAA4B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,eAAe;AACpG,MAAA,iBAAiB,GAAG,CAAC,IAAU,KAA0B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,aAAa;AAC9F,MAAA,mBAAmB,GAAG,CAAC,IAAU,KAA4B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,eAAe;AACpG,MAAA,kBAAkB,GAAG,CAAC,IAAU,KAA2B,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,cAAc;AAEjG,MAAA,mCAAmC,GAAG,CACjD,IAAuB,KACyB,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI;AACjE,MAAA,sBAAsB,GAAG,CAAC,IAAuB,KAC5D,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,WAAW;AACxB,MAAA,yBAAyB,GAAG,CAAC,IAAuB,KAC/D,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,cAAc;AAC3B,MAAA,0BAA0B,GAAG,CAAC,IAAuB,KAChE,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,eAAe;AAC5B,MAAA,wBAAwB,GAAG,CAAC,IAAuB,KAC9D,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,aAAa;AAC1B,MAAA,0BAA0B,GAAG,CAAC,IAAuB,KAChE,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,eAAe;AAC5B,MAAA,yBAAyB,GAAG,CAAC,IAAuB,KAC/D,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC
|
|
1
|
+
{"version":3,"file":"content.js","sources":["../../../src/business/types/content.ts"],"sourcesContent":["import { DeepPartial } from 'ts-essentials';\n\nimport { Image, Media } from './media';\nimport { LanguageCode, MultilingualLabel } from './multilingual';\nimport { Thematic } from './thematic';\n\nexport type ErrorText = {\n id: number;\n type: 'error-text';\n gameMedia: Media;\n wrongText: MultilingualLabel;\n correctText: MultilingualLabel;\n explanationMedia: Media;\n explanation: MultilingualLabel;\n};\n\nexport type ChoiceQuestion = {\n text: MultilingualLabel;\n correct: boolean;\n};\n\nexport type MultipleChoiceQuestion = {\n id: number;\n type: 'mcq';\n gameMedia: Media;\n question: MultilingualLabel;\n choices: ChoiceQuestion[];\n explanationMedia: Media;\n explanation: MultilingualLabel;\n};\n\nexport type NoInteraction = {\n id: number;\n type: 'no-interaction';\n firstMedia: Media;\n title: MultilingualLabel;\n text: MultilingualLabel;\n secondMedia: Media;\n};\n\nexport type OpenQuestion = {\n id: number;\n type: 'open-question';\n gameMedia: Media;\n question: MultilingualLabel;\n answer: MultilingualLabel;\n levenshteinDistance: number;\n explanationMedia: Media;\n explanation: MultilingualLabel;\n};\n\nexport type OrderingCards = {\n id: number;\n type: 'ordering-cards';\n question: MultilingualLabel;\n topLabel: MultilingualLabel;\n cards: MultilingualLabel[];\n bottomLabel: MultilingualLabel;\n explanation: MultilingualLabel;\n};\n\nexport type Spot = {\n id: number;\n x: number;\n y: number;\n r: number;\n question: MultilingualLabel;\n description: MultilingualLabel;\n};\n\nexport type PictureSpot = {\n id: number;\n type: 'picture-spot';\n image: Image;\n items: Spot[];\n explanation: MultilingualLabel;\n};\n\nexport type SwipingCardPosition = 'left' | 'right' | 'top' | 'bottom';\n\nexport type SwipingCardZone = {\n position: SwipingCardPosition;\n text: MultilingualLabel;\n};\n\nexport type SwipingCard = {\n image?: Image;\n text?: MultilingualLabel;\n answer: SwipingCardPosition;\n};\n\nexport type SwipingCards = {\n id: number;\n type: 'swiping-cards';\n question: MultilingualLabel;\n zones: SwipingCardZone[];\n cards: SwipingCard[];\n explanation: MultilingualLabel;\n};\n\nexport type Game =\n | ErrorText\n | MultipleChoiceQuestion\n | NoInteraction\n | OpenQuestion\n | OrderingCards\n | PictureSpot\n | SwipingCards;\n\nexport type GameType =\n | 'error-text'\n | 'mcq'\n | 'open-question'\n | 'no-interaction'\n | 'picture-spot'\n | 'swiping-cards'\n | 'ordering-cards';\n\nexport const GAME_TYPE: Record<string, GameType> = {\n MCQ: 'mcq',\n ERROR_TEXT: 'error-text',\n OPEN_QUESTION: 'open-question',\n NO_INTERACTION: 'no-interaction',\n PICTURE_SPOT: 'picture-spot',\n ORDERING_CARDS: 'ordering-cards',\n SWIPING_CARDS: 'swiping-cards',\n};\n\nexport type ContentStatuses = Partial<{\n [languageCode in LanguageCode]: 'draft' | 'validated' | 'waiting-translation' | 'waiting-validation';\n}>;\n\nexport type ContentMetadata = {\n identifier: string;\n coverImage?: Image;\n name: MultilingualLabel;\n thematic: Thematic;\n type: GameType;\n};\n\nexport type Content = {\n archived: boolean;\n id: number;\n metadata: ContentMetadata;\n statuses: ContentStatuses;\n game?: Game;\n};\n\nexport const isGameMultipleChoiceQuestion = (game: Game): game is MultipleChoiceQuestion => game.type === GAME_TYPE.MCQ;\nexport const isGameErrorText = (game: Game): game is ErrorText => game.type === GAME_TYPE.ERROR_TEXT;\nexport const isGameOpenQuestion = (game: Game): game is OpenQuestion => game.type === GAME_TYPE.OPEN_QUESTION;\nexport const isGameNoInteraction = (game: Game): game is NoInteraction => game.type === GAME_TYPE.NO_INTERACTION;\nexport const isGamePictureSpot = (game: Game): game is PictureSpot => game.type === GAME_TYPE.PICTURE_SPOT;\nexport const isGameOrderingCards = (game: Game): game is OrderingCards => game.type === GAME_TYPE.ORDERING_CARDS;\nexport const isGameSwipingCards = (game: Game): game is SwipingCards => game.type === GAME_TYPE.SWIPING_CARDS;\n\nexport const isPartialGameMultipleChoiceQuestion = (\n game: DeepPartial<Game>,\n): game is DeepPartial<MultipleChoiceQuestion> => game.type === GAME_TYPE.MCQ;\nexport const isPartialGameErrorText = (game: DeepPartial<Game>): game is DeepPartial<ErrorText> =>\n game.type === GAME_TYPE.ERROR_TEXT;\nexport const isPartialGameOpenQuestion = (game: DeepPartial<Game>): game is DeepPartial<OpenQuestion> =>\n game.type === GAME_TYPE.OPEN_QUESTION;\nexport const isPartialGameNoInteraction = (game: DeepPartial<Game>): game is DeepPartial<NoInteraction> =>\n game.type === GAME_TYPE.NO_INTERACTION;\nexport const isPartialGamePictureSpot = (game: DeepPartial<Game>): game is DeepPartial<PictureSpot> =>\n game.type === GAME_TYPE.PICTURE_SPOT;\nexport const isPartialGameOrderingCards = (game: DeepPartial<Game>): game is DeepPartial<OrderingCards> =>\n game.type === GAME_TYPE.ORDERING_CARDS;\nexport const isPartialGameSwipingCards = (game: DeepPartial<Game>): game is DeepPartial<SwipingCards> =>\n game.type === GAME_TYPE.SWIPING_CARDS;\n\nexport const extractExplanation = (content: Content) => {\n if (!content.game || content.game.type === 'no-interaction') {\n return undefined;\n }\n\n return content.game.explanation;\n};\n"],"names":[],"mappings":";;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MAAA,wBAAwB,GAAG,CAAC,IAAuB,KAC9D,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,aAAa;AAC1B,MAAA,0BAA0B,GAAG,CAAC,IAAuB,KAChE,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,eAAe;AAC5B,MAAA,yBAAyB,GAAG,CAAC,IAAuB,KAC/D,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,cAAc;AAE3B,MAAA,kBAAkB,GAAG,CAAC,OAAgB,KAAI;AACrD,IAAA,IAAI,CAAC,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE;AAC3D,QAAA,OAAO,SAAS,CAAC;AAClB,KAAA;AAED,IAAA,OAAO,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC;AAClC;;;;;;;;;;;;;;;;;;;"}
|
package/business/types/index.js
CHANGED
|
@@ -14,6 +14,7 @@ exports.ACTIVITY_STATUS = activity.ACTIVITY_STATUS;
|
|
|
14
14
|
exports.isActivityBreakingNews = activity.isActivityBreakingNews;
|
|
15
15
|
exports.isActivityCampaign = activity.isActivityCampaign;
|
|
16
16
|
exports.GAME_TYPE = content.GAME_TYPE;
|
|
17
|
+
exports.extractExplanation = content.extractExplanation;
|
|
17
18
|
exports.isGameErrorText = content.isGameErrorText;
|
|
18
19
|
exports.isGameMultipleChoiceQuestion = content.isGameMultipleChoiceQuestion;
|
|
19
20
|
exports.isGameNoInteraction = content.isGameNoInteraction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
const buildSearchParams = (params) => {
|
|
6
|
-
const definedParams = Object
|
|
7
|
-
.entries(params)
|
|
8
|
-
.reduce((acc, [key, value]) => {
|
|
6
|
+
const definedParams = Object.entries(params).reduce((acc, [key, value]) => {
|
|
9
7
|
if (value !== undefined) {
|
|
10
8
|
return Object.assign(Object.assign({}, acc), { [key]: String(value) });
|
|
11
9
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-search-params.js","sources":["../../src/http/build-search-params.ts"],"sourcesContent":["import type { Primitive } from '../types';\n\nexport const buildSearchParams = (params: Record<string, Primitive | undefined>): URLSearchParams => {\n const definedParams = Object
|
|
1
|
+
{"version":3,"file":"build-search-params.js","sources":["../../src/http/build-search-params.ts"],"sourcesContent":["import type { Primitive } from '../types';\n\nexport const buildSearchParams = (params: Record<string, Primitive | undefined>): URLSearchParams => {\n const definedParams = Object.entries(params).reduce((acc, [key, value]) => {\n if (value !== undefined) {\n return {\n ...acc,\n [key]: String(value),\n };\n }\n\n return acc;\n }, {} as Record<string, string>);\n\n return new URLSearchParams(definedParams);\n};\n"],"names":[],"mappings":";;;;AAEa,MAAA,iBAAiB,GAAG,CAAC,MAA6C,KAAqB;IAClG,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,KAAI;QACxE,IAAI,KAAK,KAAK,SAAS,EAAE;YACvB,OACK,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,GAAG,CACN,EAAA,EAAA,CAAC,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,EACpB,CAAA,CAAA;AACH,SAAA;AAED,QAAA,OAAO,GAAG,CAAC;KACZ,EAAE,EAA4B,CAAC,CAAC;AAEjC,IAAA,OAAO,IAAI,eAAe,CAAC,aAAa,CAAC,CAAC;AAC5C;;;;"}
|
|
@@ -16,10 +16,7 @@ const encodeSearchObject = (searchObject) => {
|
|
|
16
16
|
const { sort, query, offset, limit } = searchObject;
|
|
17
17
|
const sortEncoded = sort ? encodeSearchValue(sort) : null;
|
|
18
18
|
const queryEncoded = query ? encodeSearchValue(query) : null;
|
|
19
|
-
const urlParams = new URLSearchParams({
|
|
20
|
-
offset: offset.toString(),
|
|
21
|
-
limit: limit.toString(),
|
|
22
|
-
});
|
|
19
|
+
const urlParams = new URLSearchParams(Object.assign(Object.assign({}, (offset !== undefined ? { offset: offset.toString() } : undefined)), (limit !== undefined ? { limit: limit.toString() } : undefined)));
|
|
23
20
|
if (sortEncoded)
|
|
24
21
|
urlParams.append('sort', sortEncoded);
|
|
25
22
|
if (queryEncoded)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encode-search-object.js","sources":["../../src/http/encode-search-object.ts"],"sourcesContent":["import { SearchObject } from '../types';\n\nexport type EncodingConfig = {\n keyValueDelimiter: string
|
|
1
|
+
{"version":3,"file":"encode-search-object.js","sources":["../../src/http/encode-search-object.ts"],"sourcesContent":["import { SearchObject } from '../types';\n\nexport type EncodingConfig = {\n keyValueDelimiter: string;\n pairDelimiter: string;\n};\n\nconst defaultEncodingConfig: EncodingConfig = {\n keyValueDelimiter: ':',\n pairDelimiter: '+',\n};\n\nexport const encodeSearchValue = <T extends Record<string, string>>(\n searchValue: T,\n config: EncodingConfig = defaultEncodingConfig,\n) => {\n const { pairDelimiter, keyValueDelimiter } = config;\n\n return Object.entries(searchValue)\n .map(([key, value]) => `${key}${keyValueDelimiter}${encodeURI(value)}`)\n .join(pairDelimiter);\n};\n\nexport const encodeSearchObject = (searchObject: SearchObject): string => {\n const { sort, query, offset, limit } = searchObject;\n\n const sortEncoded = sort ? encodeSearchValue(sort) : null;\n const queryEncoded = query ? encodeSearchValue(query) : null;\n\n const urlParams = new URLSearchParams({\n ...(offset !== undefined ? { offset: offset.toString() } : undefined),\n ...(limit !== undefined ? { limit: limit.toString() } : undefined),\n });\n\n if (sortEncoded) urlParams.append('sort', sortEncoded);\n if (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AAA,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AAE1D,IAAA,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAC9B;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-with-timeout.js","sources":["../../src/http/fetch-with-timeout.ts"],"sourcesContent":["export type RequestInitWithTimeout = RequestInit & {\n timeout?: number
|
|
1
|
+
{"version":3,"file":"fetch-with-timeout.js","sources":["../../src/http/fetch-with-timeout.ts"],"sourcesContent":["export type RequestInitWithTimeout = RequestInit & {\n timeout?: number;\n};\n\n/**\n * Use fetch to perform an HTTP request\n * Add an optional timeout, that will abort the request if it has not returned before\n */\nexport const fetchWithTimeout = (\n input: RequestInfo,\n init?: Omit<RequestInitWithTimeout, 'signal'> | undefined,\n): Promise<Response> => {\n const abortController = new AbortController();\n\n const { timeout, ...rest } = init || {};\n\n const params = {\n ...rest,\n signal: abortController.signal,\n };\n\n if (timeout !== undefined) {\n setTimeout(() => abortController.abort(), timeout);\n }\n\n return fetch(input, params);\n};\n"],"names":["__rest"],"mappings":";;;;;;AAIA;;;AAGG;MACU,gBAAgB,GAAG,CAC9B,KAAkB,EAClB,IAAyD,KACpC;AACrB,IAAA,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAE9C,IAAA,MAAM,EAAuB,GAAA,IAAI,IAAI,EAAE,EAAjC,EAAE,OAAO,EAAA,GAAA,EAAwB,EAAnB,IAAI,GAAlBA,aAAA,CAAA,EAAA,EAAA,CAAA,SAAA,CAAoB,CAAa,CAAC;IAExC,MAAM,MAAM,GACP,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAAA,IAAI,CACP,EAAA,EAAA,MAAM,EAAE,eAAe,CAAC,MAAM,EAAA,CAC/B,CAAC;IAEF,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,UAAU,CAAC,MAAM,eAAe,CAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;AACpD,KAAA;AAED,IAAA,OAAO,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAC9B;;;;"}
|
package/package.json
CHANGED
package/types/search.d.ts
CHANGED
|
@@ -9,13 +9,13 @@ export type SearchQuery = {
|
|
|
9
9
|
[property: SearchQueryProperty]: SearchQueryValue;
|
|
10
10
|
};
|
|
11
11
|
export type SearchObject = {
|
|
12
|
-
offset
|
|
13
|
-
limit
|
|
12
|
+
offset?: number;
|
|
13
|
+
limit?: number;
|
|
14
14
|
sort?: Record<string, SearchSortOrder>;
|
|
15
15
|
query?: SearchQuery;
|
|
16
16
|
};
|
|
17
17
|
export type SearchResponse<T> = {
|
|
18
|
-
items:
|
|
18
|
+
items: T[];
|
|
19
19
|
offset: number;
|
|
20
20
|
limit: number;
|
|
21
21
|
total: number;
|