@s-hirano-ist/s-scripts 1.26.8 → 4.0.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/README.md +2 -0
- package/dist/chunk-6ADTNHCK.js +85 -0
- package/dist/chunk-7PVU2Z32.js +71 -0
- package/dist/chunk-AJMTRCPJ.js +15 -0
- package/dist/chunk-AUD3PD6K.js +85 -0
- package/dist/chunk-F4J6JBR4.js +115 -0
- package/dist/chunk-HDYQV2Y2.js +58 -0
- package/dist/chunk-J4VLH4VA.js +267 -0
- package/dist/chunk-JZOR5GA2.js +42 -0
- package/dist/chunk-KKZP7ZF3.js +77 -0
- package/dist/chunk-M275YZQP.js +7723 -0
- package/dist/chunk-Q6QUV5VR.js +102 -0
- package/dist/chunk-TK456CR2.js +85 -0
- package/dist/chunk-UXGLXHQ6.js +40 -0
- package/dist/chunk-XG6LAGZO.js +590 -0
- package/dist/cleanup-minio-images.js +115 -92
- package/dist/enrich-books.js +87 -78
- package/dist/fetch-articles.js +101 -90
- package/dist/fetch-books.js +147 -128
- package/dist/fetch-images.js +88 -72
- package/dist/fetch-notes.js +66 -54
- package/dist/find-duplicate-json-articles.js +100 -97
- package/dist/fix-book-frontmatter.js +111 -99
- package/dist/fix-image-formats.js +81 -65
- package/dist/ingest-articles.js +30 -249
- package/dist/ingest-books.js +61 -318
- package/dist/ingest-images.js +33 -184
- package/dist/ingest-notes.js +41 -171
- package/dist/rag/delete-collection.js +32 -22
- package/dist/rag/ingest.js +371 -92
- package/dist/rag/search.js +80 -76
- package/dist/reset-articles.js +57 -60
- package/dist/reset-books.js +57 -59
- package/dist/reset-images.js +57 -59
- package/dist/reset-notes.js +57 -59
- package/dist/revert-articles.js +53 -55
- package/dist/revert-books.js +53 -53
- package/dist/revert-images.js +53 -53
- package/dist/revert-notes.js +53 -53
- package/dist/s-content-format.js +103 -13
- package/dist/update-json-articles.js +101 -97
- package/dist/update-raw-articles.js +130 -130
- package/dist/validate-json-articles.js +129 -130
- package/package.json +13 -50
- package/dist/cleanup-minio-images.d.ts +0 -3
- package/dist/cleanup-minio-images.d.ts.map +0 -1
- package/dist/cleanup-minio-images.js.map +0 -1
- package/dist/enrich-books.d.ts +0 -3
- package/dist/enrich-books.d.ts.map +0 -1
- package/dist/enrich-books.js.map +0 -1
- package/dist/fetch-articles.d.ts +0 -3
- package/dist/fetch-articles.d.ts.map +0 -1
- package/dist/fetch-articles.js.map +0 -1
- package/dist/fetch-books.d.ts +0 -3
- package/dist/fetch-books.d.ts.map +0 -1
- package/dist/fetch-books.js.map +0 -1
- package/dist/fetch-images.d.ts +0 -3
- package/dist/fetch-images.d.ts.map +0 -1
- package/dist/fetch-images.js.map +0 -1
- package/dist/fetch-notes.d.ts +0 -3
- package/dist/fetch-notes.d.ts.map +0 -1
- package/dist/fetch-notes.js.map +0 -1
- package/dist/find-duplicate-json-articles.d.ts +0 -3
- package/dist/find-duplicate-json-articles.d.ts.map +0 -1
- package/dist/find-duplicate-json-articles.js.map +0 -1
- package/dist/fix-book-frontmatter.d.ts +0 -3
- package/dist/fix-book-frontmatter.d.ts.map +0 -1
- package/dist/fix-book-frontmatter.js.map +0 -1
- package/dist/fix-image-formats.d.ts +0 -3
- package/dist/fix-image-formats.d.ts.map +0 -1
- package/dist/fix-image-formats.js.map +0 -1
- package/dist/infrastructures/articles-command-repository.d.ts +0 -57
- package/dist/infrastructures/articles-command-repository.d.ts.map +0 -1
- package/dist/infrastructures/articles-command-repository.js +0 -68
- package/dist/infrastructures/articles-command-repository.js.map +0 -1
- package/dist/infrastructures/books-command-repository.d.ts +0 -34
- package/dist/infrastructures/books-command-repository.d.ts.map +0 -1
- package/dist/infrastructures/books-command-repository.js +0 -53
- package/dist/infrastructures/books-command-repository.js.map +0 -1
- package/dist/infrastructures/cache-invalidation-client.d.ts +0 -9
- package/dist/infrastructures/cache-invalidation-client.d.ts.map +0 -1
- package/dist/infrastructures/cache-invalidation-client.js +0 -21
- package/dist/infrastructures/cache-invalidation-client.js.map +0 -1
- package/dist/infrastructures/cache-invalidation-client.test.d.ts +0 -2
- package/dist/infrastructures/cache-invalidation-client.test.d.ts.map +0 -1
- package/dist/infrastructures/cache-invalidation-client.test.js +0 -25
- package/dist/infrastructures/cache-invalidation-client.test.js.map +0 -1
- package/dist/infrastructures/images-command-repository.d.ts +0 -34
- package/dist/infrastructures/images-command-repository.d.ts.map +0 -1
- package/dist/infrastructures/images-command-repository.js +0 -53
- package/dist/infrastructures/images-command-repository.js.map +0 -1
- package/dist/infrastructures/notes-command-repository.d.ts +0 -34
- package/dist/infrastructures/notes-command-repository.d.ts.map +0 -1
- package/dist/infrastructures/notes-command-repository.js +0 -53
- package/dist/infrastructures/notes-command-repository.js.map +0 -1
- package/dist/ingest-articles.d.ts +0 -3
- package/dist/ingest-articles.d.ts.map +0 -1
- package/dist/ingest-articles.js.map +0 -1
- package/dist/ingest-books.d.ts +0 -3
- package/dist/ingest-books.d.ts.map +0 -1
- package/dist/ingest-books.js.map +0 -1
- package/dist/ingest-images.d.ts +0 -3
- package/dist/ingest-images.d.ts.map +0 -1
- package/dist/ingest-images.js.map +0 -1
- package/dist/ingest-notes.d.ts +0 -3
- package/dist/ingest-notes.d.ts.map +0 -1
- package/dist/ingest-notes.js.map +0 -1
- package/dist/lib/glob-paths.d.ts +0 -6
- package/dist/lib/glob-paths.d.ts.map +0 -1
- package/dist/lib/glob-paths.js +0 -9
- package/dist/lib/glob-paths.js.map +0 -1
- package/dist/lib/glob-paths.test.d.ts +0 -2
- package/dist/lib/glob-paths.test.d.ts.map +0 -1
- package/dist/lib/glob-paths.test.js +0 -30
- package/dist/lib/glob-paths.test.js.map +0 -1
- package/dist/lib/html-charset.d.ts +0 -4
- package/dist/lib/html-charset.d.ts.map +0 -1
- package/dist/lib/html-charset.js +0 -33
- package/dist/lib/html-charset.js.map +0 -1
- package/dist/lib/html-charset.test.d.ts +0 -2
- package/dist/lib/html-charset.test.d.ts.map +0 -1
- package/dist/lib/html-charset.test.js +0 -27
- package/dist/lib/html-charset.test.js.map +0 -1
- package/dist/rag/delete-collection.d.ts +0 -3
- package/dist/rag/delete-collection.d.ts.map +0 -1
- package/dist/rag/delete-collection.js.map +0 -1
- package/dist/rag/ingest-config.d.ts +0 -8
- package/dist/rag/ingest-config.d.ts.map +0 -1
- package/dist/rag/ingest-config.js +0 -8
- package/dist/rag/ingest-config.js.map +0 -1
- package/dist/rag/ingest.d.ts +0 -3
- package/dist/rag/ingest.d.ts.map +0 -1
- package/dist/rag/ingest.js.map +0 -1
- package/dist/rag/search.d.ts +0 -3
- package/dist/rag/search.d.ts.map +0 -1
- package/dist/rag/search.js.map +0 -1
- package/dist/reset-articles.d.ts +0 -3
- package/dist/reset-articles.d.ts.map +0 -1
- package/dist/reset-articles.js.map +0 -1
- package/dist/reset-books.d.ts +0 -3
- package/dist/reset-books.d.ts.map +0 -1
- package/dist/reset-books.js.map +0 -1
- package/dist/reset-images.d.ts +0 -3
- package/dist/reset-images.d.ts.map +0 -1
- package/dist/reset-images.js.map +0 -1
- package/dist/reset-notes.d.ts +0 -3
- package/dist/reset-notes.d.ts.map +0 -1
- package/dist/reset-notes.js.map +0 -1
- package/dist/revert-articles.d.ts +0 -3
- package/dist/revert-articles.d.ts.map +0 -1
- package/dist/revert-articles.js.map +0 -1
- package/dist/revert-books.d.ts +0 -3
- package/dist/revert-books.d.ts.map +0 -1
- package/dist/revert-books.js.map +0 -1
- package/dist/revert-images.d.ts +0 -3
- package/dist/revert-images.d.ts.map +0 -1
- package/dist/revert-images.js.map +0 -1
- package/dist/revert-notes.d.ts +0 -3
- package/dist/revert-notes.d.ts.map +0 -1
- package/dist/revert-notes.js.map +0 -1
- package/dist/s-content-format-runner.d.ts +0 -10
- package/dist/s-content-format-runner.d.ts.map +0 -1
- package/dist/s-content-format-runner.js +0 -76
- package/dist/s-content-format-runner.js.map +0 -1
- package/dist/s-content-format.d.ts +0 -3
- package/dist/s-content-format.d.ts.map +0 -1
- package/dist/s-content-format.js.map +0 -1
- package/dist/s-content-format.test.d.ts +0 -2
- package/dist/s-content-format.test.d.ts.map +0 -1
- package/dist/s-content-format.test.js +0 -99
- package/dist/s-content-format.test.js.map +0 -1
- package/dist/update-json-articles.d.ts +0 -3
- package/dist/update-json-articles.d.ts.map +0 -1
- package/dist/update-json-articles.js.map +0 -1
- package/dist/update-raw-articles.d.ts +0 -3
- package/dist/update-raw-articles.d.ts.map +0 -1
- package/dist/update-raw-articles.js.map +0 -1
- package/dist/validate-json-articles.d.ts +0 -3
- package/dist/validate-json-articles.d.ts.map +0 -1
- package/dist/validate-json-articles.js.map +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
makeExportedAt,
|
|
4
|
+
withTransactionRetry
|
|
5
|
+
} from "./chunk-M275YZQP.js";
|
|
6
|
+
|
|
7
|
+
// ../application/dist/batch/articles-batch-service.js
|
|
8
|
+
var ArticlesBatchApplicationService = class {
|
|
9
|
+
commandRepository;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new ArticlesBatchApplicationService instance.
|
|
12
|
+
*
|
|
13
|
+
* @param commandRepository - The command repository for batch updates
|
|
14
|
+
*/
|
|
15
|
+
constructor(commandRepository) {
|
|
16
|
+
this.commandRepository = commandRepository;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Resets articles for a new batch export.
|
|
20
|
+
*
|
|
21
|
+
* @param userId - The user ID for tenant isolation
|
|
22
|
+
* @returns The result containing finalized and marked counts
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Delegates to repository's resetStatus which performs two operations
|
|
26
|
+
* atomically within a single transaction:
|
|
27
|
+
* 1. Finalize: LAST_UPDATED -> EXPORTED (complete previous batch)
|
|
28
|
+
* 2. Mark: UNEXPORTED -> LAST_UPDATED (prepare current batch)
|
|
29
|
+
*/
|
|
30
|
+
async resetArticles(userId) {
|
|
31
|
+
return this.commandRepository.resetStatus(userId, makeExportedAt());
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reverts articles from LAST_UPDATED back to UNEXPORTED.
|
|
35
|
+
*
|
|
36
|
+
* @param userId - The user ID for tenant isolation
|
|
37
|
+
* @returns The result containing the count of reverted articles
|
|
38
|
+
*
|
|
39
|
+
* @remarks
|
|
40
|
+
* Used to undo a batch marking if something went wrong.
|
|
41
|
+
* Only affects articles in LAST_UPDATED status.
|
|
42
|
+
*/
|
|
43
|
+
async revertArticles(userId) {
|
|
44
|
+
return this.commandRepository.bulkUpdateStatus({
|
|
45
|
+
userId,
|
|
46
|
+
fromStatus: "LAST_UPDATED",
|
|
47
|
+
toStatus: "UNEXPORTED"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// ../infrastructure/dist/batch/articles-command-repository.js
|
|
53
|
+
function createArticlesCommandRepository(prisma) {
|
|
54
|
+
return {
|
|
55
|
+
async bulkUpdateStatus(params) {
|
|
56
|
+
const { userId, fromStatus, toStatus, exportedAt } = params;
|
|
57
|
+
const result = await prisma.article.updateMany({
|
|
58
|
+
where: {
|
|
59
|
+
userId,
|
|
60
|
+
status: fromStatus
|
|
61
|
+
},
|
|
62
|
+
data: {
|
|
63
|
+
status: toStatus,
|
|
64
|
+
...exportedAt && { exportedAt }
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return { count: result.count };
|
|
68
|
+
},
|
|
69
|
+
async resetStatus(userId, exportedAt) {
|
|
70
|
+
const [finalized, marked] = await withTransactionRetry(() => prisma.$transaction([
|
|
71
|
+
prisma.article.updateMany({
|
|
72
|
+
where: {
|
|
73
|
+
userId,
|
|
74
|
+
status: "LAST_UPDATED"
|
|
75
|
+
},
|
|
76
|
+
data: {
|
|
77
|
+
status: "EXPORTED",
|
|
78
|
+
exportedAt
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
prisma.article.updateMany({
|
|
82
|
+
where: {
|
|
83
|
+
userId,
|
|
84
|
+
status: "UNEXPORTED"
|
|
85
|
+
},
|
|
86
|
+
data: {
|
|
87
|
+
status: "LAST_UPDATED"
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
]));
|
|
91
|
+
return {
|
|
92
|
+
finalized: { count: finalized.count },
|
|
93
|
+
marked: { count: marked.count }
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export {
|
|
100
|
+
ArticlesBatchApplicationService,
|
|
101
|
+
createArticlesCommandRepository
|
|
102
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
makeExportedAt,
|
|
4
|
+
withTransactionRetry
|
|
5
|
+
} from "./chunk-M275YZQP.js";
|
|
6
|
+
|
|
7
|
+
// ../application/dist/batch/images-batch-service.js
|
|
8
|
+
var ImagesBatchApplicationService = class {
|
|
9
|
+
commandRepository;
|
|
10
|
+
constructor(commandRepository) {
|
|
11
|
+
this.commandRepository = commandRepository;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Resets images for a new batch export.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Delegates to repository's resetStatus which performs two operations
|
|
18
|
+
* atomically within a single transaction.
|
|
19
|
+
*/
|
|
20
|
+
async resetImages(userId) {
|
|
21
|
+
return this.commandRepository.resetStatus(userId, makeExportedAt());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Reverts images from LAST_UPDATED back to UNEXPORTED.
|
|
25
|
+
*/
|
|
26
|
+
async revertImages(userId) {
|
|
27
|
+
return this.commandRepository.bulkUpdateStatus({
|
|
28
|
+
userId,
|
|
29
|
+
fromStatus: "LAST_UPDATED",
|
|
30
|
+
toStatus: "UNEXPORTED"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// ../infrastructure/dist/batch/images-command-repository.js
|
|
36
|
+
function createImagesCommandRepository(prisma) {
|
|
37
|
+
return {
|
|
38
|
+
async bulkUpdateStatus(params) {
|
|
39
|
+
const { userId, fromStatus, toStatus, exportedAt } = params;
|
|
40
|
+
const result = await prisma.image.updateMany({
|
|
41
|
+
where: {
|
|
42
|
+
userId,
|
|
43
|
+
status: fromStatus
|
|
44
|
+
},
|
|
45
|
+
data: {
|
|
46
|
+
status: toStatus,
|
|
47
|
+
...exportedAt && { exportedAt }
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return { count: result.count };
|
|
51
|
+
},
|
|
52
|
+
async resetStatus(userId, exportedAt) {
|
|
53
|
+
const [finalized, marked] = await withTransactionRetry(() => prisma.$transaction([
|
|
54
|
+
prisma.image.updateMany({
|
|
55
|
+
where: {
|
|
56
|
+
userId,
|
|
57
|
+
status: "LAST_UPDATED"
|
|
58
|
+
},
|
|
59
|
+
data: {
|
|
60
|
+
status: "EXPORTED",
|
|
61
|
+
exportedAt
|
|
62
|
+
}
|
|
63
|
+
}),
|
|
64
|
+
prisma.image.updateMany({
|
|
65
|
+
where: {
|
|
66
|
+
userId,
|
|
67
|
+
status: "UNEXPORTED"
|
|
68
|
+
},
|
|
69
|
+
data: {
|
|
70
|
+
status: "LAST_UPDATED"
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
]));
|
|
74
|
+
return {
|
|
75
|
+
finalized: { count: finalized.count },
|
|
76
|
+
marked: { count: marked.count }
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
ImagesBatchApplicationService,
|
|
84
|
+
createImagesCommandRepository
|
|
85
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createRequire as __cliCreateRequire } from "node:module"; const require = __cliCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/html-charset.ts
|
|
4
|
+
var CHARSET_ALIASES = {
|
|
5
|
+
eucjp: "euc-jp",
|
|
6
|
+
sjis: "shift_jis",
|
|
7
|
+
shiftjis: "shift_jis",
|
|
8
|
+
utf8: "utf-8",
|
|
9
|
+
xeucjp: "euc-jp",
|
|
10
|
+
xsjis: "shift_jis"
|
|
11
|
+
};
|
|
12
|
+
function normalizeCharset(charset) {
|
|
13
|
+
const trimmed = charset.trim().replaceAll(/^['"]|['"]$/gu, "");
|
|
14
|
+
const normalized = trimmed.toLowerCase().replaceAll(/[^a-z0-9]/gu, "");
|
|
15
|
+
return CHARSET_ALIASES[normalized] ?? trimmed.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
function detectHtmlCharset(headers, bytes) {
|
|
18
|
+
const contentType = headers.get("content-type") ?? "";
|
|
19
|
+
const headerMatch = /charset\s*=\s*["']?([^"'\s;]+)/iu.exec(contentType);
|
|
20
|
+
if (headerMatch) return normalizeCharset(headerMatch[1]);
|
|
21
|
+
const preview = new TextDecoder("windows-1252").decode(
|
|
22
|
+
bytes.subarray(0, Math.min(4096, bytes.length))
|
|
23
|
+
);
|
|
24
|
+
const metaCharset = /<meta\s{1,200}charset=["']?([^"'\s>]+)/iu.exec(preview);
|
|
25
|
+
if (metaCharset) return normalizeCharset(metaCharset[1]);
|
|
26
|
+
const metaHttpEquiv = /<meta[^>]{1,500}http-equiv=["']?Content-Type["']?[^>]{1,500}content=["'][^"']{0,500}charset=([^"'\s;]+)/iu.exec(
|
|
27
|
+
preview
|
|
28
|
+
);
|
|
29
|
+
if (metaHttpEquiv) return normalizeCharset(metaHttpEquiv[1]);
|
|
30
|
+
return "utf-8";
|
|
31
|
+
}
|
|
32
|
+
function decodeHtml(headers, bytes) {
|
|
33
|
+
return new TextDecoder(detectHtmlCharset(headers, bytes), {
|
|
34
|
+
fatal: false
|
|
35
|
+
}).decode(bytes);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
decodeHtml
|
|
40
|
+
};
|