Skip to content

Commit e53e8d7

Browse files
committed
feature: scaffold new fern-adapter package to be run as cron
1 parent 918c7f9 commit e53e8d7

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

clients/trieve-fern-adapter/index.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
#!/usr/bin/env node
2+
13
/* eslint-disable @typescript-eslint/no-explicit-any */
24
import { Command } from 'commander';
35
import { parse } from 'yaml';
46
import { Window } from 'happy-dom';
57
import fs from 'node:fs';
8+
import { join } from 'node:path';
69
import { TrieveSDK, ChunkReqPayload } from 'trieve-ts-sdk';
710
import { marked } from 'marked';
811
import { dereferenceSync } from '@trojs/openapi-dereference';
12+
import pluralize from 'pluralize'
913

1014
const splitHtmlIntoHeadAndBodies = (html: Element): [string, string][] => {
1115
const headingRegex = /h\d/gi;
@@ -120,7 +124,7 @@ const extractChunksFromPath = async (
120124
.filter((x) => x);
121125
const metadata: any = {
122126
url: link,
123-
heirarchy: tag_set,
127+
hierarchy: tag_set,
124128
heading: heading,
125129
};
126130

@@ -196,11 +200,13 @@ const extractChunksFromOpenapiSpec = async (
196200
const operationId = pathData[method].operationId;
197201
const summary = pathData[method].summary;
198202
const description = pathData[method].description;
199-
const pageLink = `${siteUrl}/${apiRefParent}/${summary?.split(' ').join('-').toLowerCase() ?? path}`;
203+
const [namespace, ...parts] = summary?.toLowerCase().split(' ') ?? []
204+
const endpoint = namespace ? join(pluralize(parts.join('-')), namespace) : path
205+
const pageLink = `${siteUrl}/${apiRefParent}/${endpoint}`;
200206
const metadata = {
201207
operation_id: operationId,
202208
url: pageLink,
203-
heirarchy: [
209+
hierarchy: [
204210
apiRefParent,
205211
summary?.split(' ').join('-').toLowerCase() ?? path,
206212
],
@@ -337,8 +343,8 @@ try {
337343
}
338344
console.info('Waiting on delete...');
339345
}
340-
} catch (err) {
341-
console.info('Dataset not found, creating...', err);
346+
} catch {
347+
console.info('Dataset not found, creating...');
342348
try {
343349
const createdDataset = await trieve.createDataset({
344350
tracking_id: trieveDatasetTrackingId,
@@ -366,4 +372,4 @@ for (let i = 0; i < chunkReqPayloads.length; i += 120) {
366372
}
367373

368374
console.log('Done!');
369-
process.exit(0);
375+
process.exit(0);

clients/trieve-fern-adapter/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"devDependencies": {
1616
"@eslint/js": "^9.15.0",
1717
"@types/node": "^22.10.0",
18+
"@types/pluralize": "^0.0.33",
1819
"@typescript-eslint/eslint-plugin": "^8.16.0",
1920
"@typescript-eslint/parser": "^8.16.0",
2021
"eslint": "^9.15.0",
@@ -29,6 +30,7 @@
2930
"commander": "^12.1.0",
3031
"happy-dom": "^15.11.6",
3132
"marked": "^15.0.2",
33+
"pluralize": "^8.0.0",
3234
"trieve-ts-sdk": "^0.0.35",
3335
"yaml": "^2.6.1"
3436
}

clients/trieve-fern-adapter/yarn.lock

+25-15
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
"@eslint/[email protected]", "@eslint/js@^9.15.0":
4747
version "9.15.0"
48-
resolved "https://registry.npmjs.org/@eslint/js/-/js-9.15.0.tgz"
48+
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.15.0.tgz#df0e24fe869143b59731942128c19938fdbadfb5"
4949
integrity sha512-tMTqrY+EzbXmKJR5ToI8lxu7jaN5EdmrBFJpQk5JmSlyLsx6o4t27r883K5xsLuCYCpfKBCGswMSWXsM+jB7lg==
5050

5151
"@eslint/object-schema@^2.1.4":
@@ -131,6 +131,11 @@
131131
dependencies:
132132
undici-types "~6.20.0"
133133

134+
"@types/pluralize@^0.0.33":
135+
version "0.0.33"
136+
resolved "https://registry.yarnpkg.com/@types/pluralize/-/pluralize-0.0.33.tgz#8ad9018368c584d268667dd9acd5b3b806e8c82a"
137+
integrity sha512-JOqsl+ZoCpP4e8TDke9W79FDcSgPAR0l6pixx2JHkhnRjvShyYiAYw2LVsnA7K08Y6DeOnaU6ujmENO4os/cYg==
138+
134139
"@typescript-eslint/[email protected]", "@typescript-eslint/eslint-plugin@^8.16.0":
135140
version "8.16.0"
136141
resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.16.0.tgz"
@@ -298,7 +303,7 @@ color-name@~1.1.4:
298303

299304
commander@^12.1.0:
300305
version "12.1.0"
301-
resolved "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz"
306+
resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3"
302307
integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==
303308

304309
@@ -329,7 +334,7 @@ deep-is@^0.1.3:
329334

330335
entities@^4.5.0:
331336
version "4.5.0"
332-
resolved "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz"
337+
resolved "https://registry.yarnpkg.com/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48"
333338
integrity sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==
334339

335340
escape-string-regexp@^4.0.0:
@@ -339,7 +344,7 @@ escape-string-regexp@^4.0.0:
339344

340345
eslint-config-prettier@^9.1.0:
341346
version "9.1.0"
342-
resolved "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz"
347+
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz#31af3d94578645966c082fcb71a5846d3c94867f"
343348
integrity sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==
344349

345350
eslint-scope@^8.2.0:
@@ -362,7 +367,7 @@ eslint-visitor-keys@^4.2.0:
362367

363368
eslint@^9.15.0:
364369
version "9.15.0"
365-
resolved "https://registry.npmjs.org/eslint/-/eslint-9.15.0.tgz"
370+
resolved "https://registry.yarnpkg.com/eslint/-/eslint-9.15.0.tgz#77c684a4e980e82135ebff8ee8f0a9106ce6b8a6"
366371
integrity sha512-7CrWySmIibCgT1Os28lUU6upBshZ+GxybLOrmRzi08kS8MBuO8QA7pXEgYgY5W8vK3e74xv0lpjo9DbaGU9Rkw==
367372
dependencies:
368373
"@eslint-community/eslint-utils" "^4.2.0"
@@ -522,7 +527,7 @@ globals@^14.0.0:
522527

523528
globals@^15.12.0:
524529
version "15.12.0"
525-
resolved "https://registry.npmjs.org/globals/-/globals-15.12.0.tgz"
530+
resolved "https://registry.yarnpkg.com/globals/-/globals-15.12.0.tgz#1811872883ad8f41055b61457a130221297de5b5"
526531
integrity sha512-1+gLErljJFhbOVyaetcwJiJ4+eLe45S2E7P5UiZ9xGfeq3ATQf5DOv9G7MH3gGbKQLkzmNh2DxfZwLdw+j6oTQ==
527532

528533
graphemer@^1.4.0:
@@ -532,7 +537,7 @@ graphemer@^1.4.0:
532537

533538
happy-dom@^15.11.6:
534539
version "15.11.6"
535-
resolved "https://registry.npmjs.org/happy-dom/-/happy-dom-15.11.6.tgz"
540+
resolved "https://registry.yarnpkg.com/happy-dom/-/happy-dom-15.11.6.tgz#b40d46060114fee5c4f0e79c6a1aec50cd42e4c8"
536541
integrity sha512-elX7iUTu+5+3b2+NGQc0L3eWyq9jKhuJJ4GpOMxxT/c2pg9O3L5H3ty2VECX0XXZgRmmRqXyOK8brA2hDI6LsQ==
537542
dependencies:
538543
entities "^4.5.0"
@@ -586,7 +591,7 @@ isexe@^2.0.0:
586591

587592
js-yaml@^4.1.0:
588593
version "4.1.0"
589-
resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz"
594+
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
590595
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
591596
dependencies:
592597
argparse "^2.0.1"
@@ -635,7 +640,7 @@ lodash.merge@^4.6.2:
635640

636641
marked@^15.0.2:
637642
version "15.0.2"
638-
resolved "https://registry.npmjs.org/marked/-/marked-15.0.2.tgz"
643+
resolved "https://registry.yarnpkg.com/marked/-/marked-15.0.2.tgz#e6f8c351554e05cfbe77fee5fa2d6116d361787b"
639644
integrity sha512-85RUkoYKIVB21PbMKrnD6aCl9ws+XKEyhJNMbLn206NyD3jbBo7Ec7Wi4Jrsn4dV1a2ng7K/jfkmIN0DNoS41w==
640645

641646
merge2@^1.3.0:
@@ -723,14 +728,19 @@ picomatch@^2.3.1:
723728
resolved "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz"
724729
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
725730

731+
pluralize@^8.0.0:
732+
version "8.0.0"
733+
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-8.0.0.tgz#1a6fa16a38d12a1901e0320fa017051c539ce3b1"
734+
integrity sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==
735+
726736
prelude-ls@^1.2.1:
727737
version "1.2.1"
728738
resolved "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz"
729739
integrity sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==
730740

731741
732742
version "3.4.1"
733-
resolved "https://registry.npmjs.org/prettier/-/prettier-3.4.1.tgz"
743+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.4.1.tgz#e211d451d6452db0a291672ca9154bc8c2579f7b"
734744
integrity sha512-G+YdqtITVZmOJje6QkXQWzl3fSfMxFwm1tjTyo9exhkmWSqC4Yhd1+lug++IlR2mvRVAxEDDWYkQdeSztajqgg==
735745

736746
punycode@^2.1.0:
@@ -798,7 +808,7 @@ to-regex-range@^5.0.1:
798808

799809
trieve-ts-sdk@^0.0.35:
800810
version "0.0.35"
801-
resolved "https://registry.npmjs.org/trieve-ts-sdk/-/trieve-ts-sdk-0.0.35.tgz"
811+
resolved "https://registry.yarnpkg.com/trieve-ts-sdk/-/trieve-ts-sdk-0.0.35.tgz#c93f0dba6bd3422cdeae4e569b9dfa59688162f5"
802812
integrity sha512-aTaJ+CQDOvnef1Vt+d/tJX+Y3eRleWqxdlbn80VX3XJ7kUQZog37XdqepjqV0RHZt+8+NKMZ7nkUBXQwxPc/gw==
803813

804814
ts-api-utils@^1.3.0:
@@ -815,7 +825,7 @@ type-check@^0.4.0, type-check@~0.4.0:
815825

816826
typescript-eslint@^8.16.0:
817827
version "8.16.0"
818-
resolved "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.16.0.tgz"
828+
resolved "https://registry.yarnpkg.com/typescript-eslint/-/typescript-eslint-8.16.0.tgz#d608c972d6b2461ca10ec30fd3fa62a080baba19"
819829
integrity sha512-wDkVmlY6O2do4V+lZd0GtRfbtXbeD0q9WygwXXSJnC1xorE8eqyC2L1tJimqpSeFrOzRlYtWnUp/uzgHQOgfBQ==
820830
dependencies:
821831
"@typescript-eslint/eslint-plugin" "8.16.0"
@@ -841,12 +851,12 @@ uri-js@^4.2.2:
841851

842852
webidl-conversions@^7.0.0:
843853
version "7.0.0"
844-
resolved "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz"
854+
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-7.0.0.tgz#256b4e1882be7debbf01d05f0aa2039778ea080a"
845855
integrity sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==
846856

847857
whatwg-mimetype@^3.0.0:
848858
version "3.0.0"
849-
resolved "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz"
859+
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-3.0.0.tgz#5fa1a7623867ff1af6ca3dc72ad6b8a4208beba7"
850860
integrity sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q==
851861

852862
which@^2.0.1:
@@ -863,7 +873,7 @@ word-wrap@^1.2.5:
863873

864874
yaml@^2.6.1:
865875
version "2.6.1"
866-
resolved "https://registry.npmjs.org/yaml/-/yaml-2.6.1.tgz"
876+
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.6.1.tgz#42f2b1ba89203f374609572d5349fb8686500773"
867877
integrity sha512-7r0XPzioN/Q9kXBro/XPnA6kznR73DHq+GXh5ON7ZozRO6aMjbmiBuKste2wslTFkC5d1dw0GooOCepZXJ2SAg==
868878

869879
yocto-queue@^0.1.0:

0 commit comments

Comments
 (0)