@mdgf11/filesystem-lib 2.0.0
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 +9 -0
- package/dist/descritores.d.ts +1 -0
- package/dist/descritores.js +4248 -0
- package/dist/filesystemDocumentMethods.d.ts +7 -0
- package/dist/filesystemDocumentMethods.js +227 -0
- package/dist/filesystemUpdateMethods.d.ts +5 -0
- package/dist/filesystemUpdateMethods.js +74 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +19 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.js +21 -0
- package/package.json +30 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PartialJurisprudenciaDocument } from "@stjiris/jurisprudencia-document";
|
|
2
|
+
import { ContentType, Date_Area_Section, FilesystemDocument, Retrievable_Metadata, Sharepoint_Metadata } from "./types";
|
|
3
|
+
export declare function writeFilesystemDocument(filesystem_document: FilesystemDocument): void;
|
|
4
|
+
export declare function loadFilesystemDocument(jsonPath: string): FilesystemDocument;
|
|
5
|
+
export declare function createJurisprudenciaDocument(retrievable_Metadata: Retrievable_Metadata, contents: ContentType[], date_area_section: Date_Area_Section, sharepoint_metadata?: Sharepoint_Metadata): Promise<PartialJurisprudenciaDocument>;
|
|
6
|
+
export declare function hasSelectableText(buffer: Buffer): Promise<boolean>;
|
|
7
|
+
export declare function generateFilePath(date_area_section: Date_Area_Section, retrievable_metadata: Retrievable_Metadata): string;
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.writeFilesystemDocument = writeFilesystemDocument;
|
|
40
|
+
exports.loadFilesystemDocument = loadFilesystemDocument;
|
|
41
|
+
exports.createJurisprudenciaDocument = createJurisprudenciaDocument;
|
|
42
|
+
exports.hasSelectableText = hasSelectableText;
|
|
43
|
+
exports.generateFilePath = generateFilePath;
|
|
44
|
+
const jurisprudencia_document_1 = require("@stjiris/jurisprudencia-document");
|
|
45
|
+
const fs_1 = __importDefault(require("fs"));
|
|
46
|
+
const mammoth_1 = __importDefault(require("mammoth"));
|
|
47
|
+
const pdfjsLib = __importStar(require("pdfjs-dist/legacy/build/pdf.mjs"));
|
|
48
|
+
const types_1 = require("./types");
|
|
49
|
+
const descritores_1 = require("./descritores");
|
|
50
|
+
function writeFilesystemDocument(filesystem_document) {
|
|
51
|
+
if (!filesystem_document.content)
|
|
52
|
+
return;
|
|
53
|
+
const safe = {
|
|
54
|
+
...filesystem_document,
|
|
55
|
+
content: filesystem_document.content?.map(({ extension }) => ({ extension }))
|
|
56
|
+
};
|
|
57
|
+
const content = filesystem_document.content;
|
|
58
|
+
if (filesystem_document.file_path) {
|
|
59
|
+
// make filesystem paths
|
|
60
|
+
const filesystem_dir_path = `${types_1.ROOT_PATH}${types_1.FILESYSTEM_PATH}${filesystem_document.file_path}`;
|
|
61
|
+
const filesystem_metadata_path = `${filesystem_dir_path}/${types_1.DETAILS_NAME}.json`;
|
|
62
|
+
fs_1.default.mkdirSync(filesystem_dir_path, { recursive: true });
|
|
63
|
+
fs_1.default.writeFileSync(filesystem_metadata_path, JSON.stringify(safe, null, 2), { encoding: "utf-8" });
|
|
64
|
+
for (const content_i of content) {
|
|
65
|
+
const filesystem_original_path = `${filesystem_dir_path}/${types_1.ORIGINAL_NAME}.${content_i.extension}`;
|
|
66
|
+
fs_1.default.writeFileSync(filesystem_original_path, content_i.data, { encoding: "utf-8" });
|
|
67
|
+
}
|
|
68
|
+
// make metadata copy on filesystem copy
|
|
69
|
+
if (filesystem_document.sharepoint_metadata) {
|
|
70
|
+
const filesystem_sharepoint_dir_path = `${types_1.ROOT_PATH}${types_1.SHAREPOINT_COPY_PATH}${filesystem_document.sharepoint_metadata.sharepoint_path_rel}`;
|
|
71
|
+
const filesystem_sharepoint_path = `${filesystem_sharepoint_dir_path}/${types_1.DETAILS_NAME}.json`;
|
|
72
|
+
fs_1.default.mkdirSync(filesystem_sharepoint_dir_path, { recursive: true });
|
|
73
|
+
fs_1.default.writeFileSync(filesystem_sharepoint_path, JSON.stringify(safe, null, 2), { encoding: "utf-8" });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (filesystem_document.sharepoint_metadata) {
|
|
78
|
+
const filesystem_sharepoint_dir_path = `${types_1.ROOT_PATH}${types_1.SHAREPOINT_COPY_PATH}${filesystem_document.sharepoint_metadata.sharepoint_path_rel}`;
|
|
79
|
+
const filesystem_sharepoint_path = `${filesystem_sharepoint_dir_path}/${types_1.DETAILS_NAME}.json`;
|
|
80
|
+
fs_1.default.mkdirSync(filesystem_sharepoint_dir_path, { recursive: true });
|
|
81
|
+
fs_1.default.writeFileSync(filesystem_sharepoint_path, JSON.stringify(safe, null, 2), { encoding: "utf-8" });
|
|
82
|
+
for (const content_i of content) {
|
|
83
|
+
const filesystem_original_path = `${filesystem_sharepoint_dir_path}/${types_1.ORIGINAL_NAME}.${content_i.extension}`;
|
|
84
|
+
fs_1.default.writeFileSync(filesystem_original_path, content_i.data, { encoding: "utf-8" });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function loadFilesystemDocument(jsonPath) {
|
|
90
|
+
const jsonString = fs_1.default.readFileSync(jsonPath, 'utf-8');
|
|
91
|
+
const parsed = JSON.parse(jsonString);
|
|
92
|
+
return {
|
|
93
|
+
...parsed,
|
|
94
|
+
creation_date: new Date(parsed.creation_date),
|
|
95
|
+
last_update_date: new Date(parsed.last_update_date),
|
|
96
|
+
content: parsed.content?.map((item) => ({
|
|
97
|
+
extension: item.extension,
|
|
98
|
+
data: Buffer.from([])
|
|
99
|
+
}))
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function createJurisprudenciaDocument(retrievable_Metadata, contents, date_area_section, sharepoint_metadata) {
|
|
103
|
+
if (!retrievable_Metadata) {
|
|
104
|
+
throw new Error("Missing metadata.");
|
|
105
|
+
}
|
|
106
|
+
const content = await extractContent(contents);
|
|
107
|
+
const url = sharepoint_metadata ? sharepoint_metadata.sharepoint_url : "";
|
|
108
|
+
let Original = {};
|
|
109
|
+
let CONTENT = content;
|
|
110
|
+
let numProc = retrievable_Metadata.process_number;
|
|
111
|
+
let Data = Intl.DateTimeFormat("pt-PT").format(date_area_section.file_date);
|
|
112
|
+
let origin = "STJ (Sharepoint)";
|
|
113
|
+
Original["Decisão Texto Integral"] = content.map(line => `<p><font>${line}</font><br>`).join('');
|
|
114
|
+
Original["Data"] = Data;
|
|
115
|
+
Original["Número de Processo"] = numProc;
|
|
116
|
+
Original["Fonte"] = origin;
|
|
117
|
+
Original["URL"] = url;
|
|
118
|
+
Original["Jurisprudência"] = "Simples";
|
|
119
|
+
let obj = {
|
|
120
|
+
"Original": Original,
|
|
121
|
+
"CONTENT": CONTENT,
|
|
122
|
+
"Data": Data,
|
|
123
|
+
"Número de Processo": numProc,
|
|
124
|
+
"Fonte": origin,
|
|
125
|
+
"URL": url,
|
|
126
|
+
"Jurisprudência": { Index: ["Simples"], Original: ["Simples"], Show: ["Simples"] },
|
|
127
|
+
"STATE": "importação",
|
|
128
|
+
};
|
|
129
|
+
obj.Sumário = "";
|
|
130
|
+
obj.Texto = content.map(line => `<p><font>${line}</font><br>`).join('');
|
|
131
|
+
if (retrievable_Metadata.descriptors && retrievable_Metadata.descriptors.length > 0) {
|
|
132
|
+
obj.Descritores = {
|
|
133
|
+
Index: retrievable_Metadata.descriptors.map(desc => descritores_1.DescritorOficial[desc]),
|
|
134
|
+
Original: retrievable_Metadata.descriptors,
|
|
135
|
+
Show: retrievable_Metadata.descriptors.map(desc => descritores_1.DescritorOficial[desc])
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
if (date_area_section.area && date_area_section.area.length > 0) {
|
|
139
|
+
obj.Área = { Index: [date_area_section.area], Original: [date_area_section.area], Show: [date_area_section.area] };
|
|
140
|
+
}
|
|
141
|
+
if (date_area_section.section && date_area_section.section.length > 0) {
|
|
142
|
+
obj.Secção = { Index: [date_area_section.section], Original: [date_area_section.section], Show: [date_area_section.section] };
|
|
143
|
+
}
|
|
144
|
+
if (retrievable_Metadata.judge && retrievable_Metadata.judge.length > 0) {
|
|
145
|
+
obj["Relator Nome Profissional"] = { Index: [retrievable_Metadata.judge], Original: [retrievable_Metadata.judge], Show: [retrievable_Metadata.judge] };
|
|
146
|
+
}
|
|
147
|
+
if (retrievable_Metadata.process_mean && retrievable_Metadata.process_mean.length > 0) {
|
|
148
|
+
obj["Meio Processual"] = { Index: [retrievable_Metadata.process_mean], Original: [retrievable_Metadata.process_mean], Show: [retrievable_Metadata.process_mean] };
|
|
149
|
+
}
|
|
150
|
+
if (retrievable_Metadata.decision && retrievable_Metadata.decision.length > 0) {
|
|
151
|
+
obj["Decisão"] = { Index: [retrievable_Metadata.decision], Original: [retrievable_Metadata.decision], Show: [retrievable_Metadata.decision] };
|
|
152
|
+
}
|
|
153
|
+
obj["HASH"] = (0, jurisprudencia_document_1.calculateHASH)({
|
|
154
|
+
...obj,
|
|
155
|
+
Original: obj.Original,
|
|
156
|
+
"Número de Processo": obj["Número de Processo"] || "",
|
|
157
|
+
Sumário: obj.Sumário || "",
|
|
158
|
+
Texto: obj.Texto || "",
|
|
159
|
+
});
|
|
160
|
+
obj["UUID"] = (0, jurisprudencia_document_1.calculateUUID)(obj["HASH"]);
|
|
161
|
+
return obj;
|
|
162
|
+
}
|
|
163
|
+
async function hasSelectableText(buffer) {
|
|
164
|
+
try {
|
|
165
|
+
const uint8Array = new Uint8Array(buffer);
|
|
166
|
+
const loadingTask = pdfjsLib.getDocument({
|
|
167
|
+
data: uint8Array,
|
|
168
|
+
standardFontDataUrl: 'node_modules/pdfjs-dist/standard_fonts/',
|
|
169
|
+
});
|
|
170
|
+
const pdf = await loadingTask.promise;
|
|
171
|
+
const pagesToCheck = Math.min(3, pdf.numPages);
|
|
172
|
+
for (let i = 1; i <= pagesToCheck; i++) {
|
|
173
|
+
const page = await pdf.getPage(i);
|
|
174
|
+
const textContent = await page.getTextContent();
|
|
175
|
+
if (textContent.items.some((item) => item.str?.trim().length > 0)) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
console.error('Error reading PDF:', error);
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function generateFilePath(date_area_section, retrievable_metadata) {
|
|
187
|
+
return `/${date_area_section.area}/${date_area_section.file_date.getFullYear()}/${date_area_section.file_date.getMonth() + 1}/${date_area_section.file_date.getDate()}/${retrievable_metadata.process_number.replace("/", "-")}`;
|
|
188
|
+
}
|
|
189
|
+
async function extractContent(contents) {
|
|
190
|
+
for (const content of contents) {
|
|
191
|
+
if (content.extension === "txt") {
|
|
192
|
+
return content.data.toString('utf-8').split(/\r?\n/).filter(line => line.trim().length > 0);
|
|
193
|
+
}
|
|
194
|
+
if (content.extension === "pdf") {
|
|
195
|
+
return await pdfToLines(content.data);
|
|
196
|
+
}
|
|
197
|
+
if (content.extension === "docx") {
|
|
198
|
+
return await docxToLines(content.data);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
throw new Error("Contents are not a supported format.");
|
|
202
|
+
}
|
|
203
|
+
async function pdfToLines(buffer) {
|
|
204
|
+
const uint8Array = new Uint8Array(buffer);
|
|
205
|
+
const loadingTask = pdfjsLib.getDocument({ data: uint8Array, verbosity: 0 });
|
|
206
|
+
const pdf = await loadingTask.promise;
|
|
207
|
+
const allLines = [];
|
|
208
|
+
for (let i = 1; i <= pdf.numPages; i++) {
|
|
209
|
+
const page = await pdf.getPage(i);
|
|
210
|
+
const textContent = await page.getTextContent();
|
|
211
|
+
const pageText = textContent.items
|
|
212
|
+
.map((item) => item.str)
|
|
213
|
+
.join('\n');
|
|
214
|
+
const lines = pageText.split('\n').filter(line => line.trim().length > 0);
|
|
215
|
+
allLines.push(...lines);
|
|
216
|
+
}
|
|
217
|
+
return allLines;
|
|
218
|
+
}
|
|
219
|
+
async function docxToLines(buffer) {
|
|
220
|
+
const result = await mammoth_1.default.extractRawText({ buffer });
|
|
221
|
+
const text = result.value || "";
|
|
222
|
+
const content = text
|
|
223
|
+
.split(/\r?\n/)
|
|
224
|
+
.map(line => line.trim())
|
|
225
|
+
.filter(Boolean);
|
|
226
|
+
return content;
|
|
227
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { FilesystemDocument, FilesystemUpdate } from "./types";
|
|
2
|
+
export declare function addFileToUpdate(update: FilesystemUpdate, filesystem_document: FilesystemDocument): void;
|
|
3
|
+
export declare function writeFilesystemUpdate(update: FilesystemUpdate): void;
|
|
4
|
+
export declare function logDocumentProcessingError(update: FilesystemUpdate, err: string): void;
|
|
5
|
+
export declare function loadLastFilesystemUpdate(): FilesystemUpdate;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addFileToUpdate = addFileToUpdate;
|
|
7
|
+
exports.writeFilesystemUpdate = writeFilesystemUpdate;
|
|
8
|
+
exports.logDocumentProcessingError = logDocumentProcessingError;
|
|
9
|
+
exports.loadLastFilesystemUpdate = loadLastFilesystemUpdate;
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
const fs_1 = __importDefault(require("fs"));
|
|
12
|
+
const types_1 = require("./types");
|
|
13
|
+
function addFileToUpdate(update, filesystem_document) {
|
|
14
|
+
if (!filesystem_document.file_path) {
|
|
15
|
+
throw new Error("File to be added to update doesn't have a system path.");
|
|
16
|
+
}
|
|
17
|
+
if (!update.created) {
|
|
18
|
+
update.created = [];
|
|
19
|
+
}
|
|
20
|
+
if (!update.created_num) {
|
|
21
|
+
update.created_num = 0;
|
|
22
|
+
}
|
|
23
|
+
update.created_num += 1;
|
|
24
|
+
update.created.push(filesystem_document.file_path);
|
|
25
|
+
}
|
|
26
|
+
function writeFilesystemUpdate(update) {
|
|
27
|
+
update.date_end = new Date();
|
|
28
|
+
fs_1.default.mkdirSync(types_1.UPDATE_DIR, { recursive: true });
|
|
29
|
+
const updates_file_path = `${types_1.UPDATE_DIR}/log_${formatUpdateDate(update.date_end)}.json`;
|
|
30
|
+
const drive_dir_path = `${types_1.UPDATE_DIR}/All`;
|
|
31
|
+
fs_1.default.mkdirSync(drive_dir_path, { recursive: true });
|
|
32
|
+
const drive_file_path = `${drive_dir_path}/log_${formatUpdateDate(update.date_end)}.json`;
|
|
33
|
+
removeOldUpdate(types_1.UPDATE_DIR);
|
|
34
|
+
fs_1.default.writeFileSync(drive_file_path, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
35
|
+
fs_1.default.writeFileSync(updates_file_path, JSON.stringify(update, null, 2), { encoding: "utf-8" });
|
|
36
|
+
}
|
|
37
|
+
function logDocumentProcessingError(update, err) {
|
|
38
|
+
update.file_errors.push(err);
|
|
39
|
+
}
|
|
40
|
+
function loadLastFilesystemUpdate() {
|
|
41
|
+
const empty_update = {
|
|
42
|
+
updateSource: "STJ (Sharepoint)",
|
|
43
|
+
file_errors: [],
|
|
44
|
+
date_start: new Date()
|
|
45
|
+
};
|
|
46
|
+
if (!fs_1.default.existsSync(types_1.UPDATE_DIR))
|
|
47
|
+
return empty_update;
|
|
48
|
+
const files = fs_1.default.readdirSync(types_1.UPDATE_DIR);
|
|
49
|
+
for (const file of files) {
|
|
50
|
+
const fullPath = path_1.default.join(types_1.UPDATE_DIR, file);
|
|
51
|
+
if (fs_1.default.statSync(fullPath).isFile() && file.toLowerCase().includes("log")) {
|
|
52
|
+
const jsonString = fs_1.default.readFileSync(fullPath, 'utf-8');
|
|
53
|
+
const parsed = JSON.parse(jsonString);
|
|
54
|
+
return parsed;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return empty_update;
|
|
58
|
+
}
|
|
59
|
+
function formatUpdateDate(d = new Date()) {
|
|
60
|
+
const pad = (n) => n.toString().padStart(2, "0");
|
|
61
|
+
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}_${pad(d.getHours())}-${pad(d.getMinutes())}-${pad(d.getSeconds())}`;
|
|
62
|
+
}
|
|
63
|
+
function removeOldUpdate(folderPath) {
|
|
64
|
+
if (!fs_1.default.existsSync(folderPath))
|
|
65
|
+
return;
|
|
66
|
+
const files = fs_1.default.readdirSync(folderPath);
|
|
67
|
+
for (const file of files) {
|
|
68
|
+
const fullPath = path_1.default.join(folderPath, file);
|
|
69
|
+
if (fs_1.default.statSync(fullPath).isFile() && file.toLowerCase().includes("log")) {
|
|
70
|
+
fs_1.default.unlinkSync(fullPath);
|
|
71
|
+
console.log(`Deleted: ${fullPath} `);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./filesystemDocumentMethods"), exports);
|
|
18
|
+
__exportStar(require("./filesystemUpdateMethods"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare const UpdateSources: readonly ["STJ (Sharepoint)", "Juris"];
|
|
2
|
+
export type SupportedUpdateSources = typeof UpdateSources[number];
|
|
3
|
+
import { PartialJurisprudenciaDocument } from '@stjiris/jurisprudencia-document';
|
|
4
|
+
export declare const ROOT_PATH: string;
|
|
5
|
+
export declare const FILESYSTEM_PATH = "/FileSystem";
|
|
6
|
+
export declare const SHAREPOINT_COPY_PATH = "/Sharepoint";
|
|
7
|
+
export declare const DETAILS_NAME = "Detalhes";
|
|
8
|
+
export declare const ORIGINAL_NAME = "Original";
|
|
9
|
+
export declare const LOGS_PATH = "/Updates";
|
|
10
|
+
export declare const UPDATE_DIR: string;
|
|
11
|
+
export type FilesystemUpdate = {
|
|
12
|
+
updateSource: SupportedUpdateSources;
|
|
13
|
+
date_start: Date;
|
|
14
|
+
file_errors: string[];
|
|
15
|
+
date_end?: Date;
|
|
16
|
+
created_num?: number;
|
|
17
|
+
created?: string[];
|
|
18
|
+
deleted_num?: number;
|
|
19
|
+
deleted?: string[];
|
|
20
|
+
updated_num?: number;
|
|
21
|
+
updated?: string[];
|
|
22
|
+
next_link?: string;
|
|
23
|
+
delta_link?: string;
|
|
24
|
+
};
|
|
25
|
+
export type Sharepoint_Metadata = {
|
|
26
|
+
drive_name: string;
|
|
27
|
+
drive_id: string;
|
|
28
|
+
sharepoint_id: string;
|
|
29
|
+
parent_sharepoint_id: string;
|
|
30
|
+
sharepoint_path: string;
|
|
31
|
+
sharepoint_path_rel: string;
|
|
32
|
+
sharepoint_url: string;
|
|
33
|
+
extensions: Supported_Content_Extensions[];
|
|
34
|
+
xor_hash?: string;
|
|
35
|
+
};
|
|
36
|
+
export type Retrievable_Metadata = {
|
|
37
|
+
process_number: string;
|
|
38
|
+
judge: string;
|
|
39
|
+
process_mean: string;
|
|
40
|
+
decision: string;
|
|
41
|
+
descriptors?: string[];
|
|
42
|
+
};
|
|
43
|
+
export type Date_Area_Section = {
|
|
44
|
+
file_date: Date;
|
|
45
|
+
area: string;
|
|
46
|
+
section: string;
|
|
47
|
+
};
|
|
48
|
+
export declare const SUPPORTED_EXTENSIONS: readonly ["txt", "pdf", "docx"];
|
|
49
|
+
export type Supported_Content_Extensions = typeof SUPPORTED_EXTENSIONS[number];
|
|
50
|
+
export type ContentType = {
|
|
51
|
+
extension: Supported_Content_Extensions;
|
|
52
|
+
data: Buffer;
|
|
53
|
+
};
|
|
54
|
+
export type FilesystemDocument = {
|
|
55
|
+
creation_date: Date;
|
|
56
|
+
last_update_date: Date;
|
|
57
|
+
jurisprudencia_document: PartialJurisprudenciaDocument;
|
|
58
|
+
file_path: string;
|
|
59
|
+
sharepoint_metadata?: Sharepoint_Metadata;
|
|
60
|
+
content?: ContentType[];
|
|
61
|
+
};
|
|
62
|
+
export declare function isSupportedExtension(ext: string): ext is Supported_Content_Extensions;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SUPPORTED_EXTENSIONS = exports.UPDATE_DIR = exports.LOGS_PATH = exports.ORIGINAL_NAME = exports.DETAILS_NAME = exports.SHAREPOINT_COPY_PATH = exports.FILESYSTEM_PATH = exports.ROOT_PATH = exports.UpdateSources = void 0;
|
|
7
|
+
exports.isSupportedExtension = isSupportedExtension;
|
|
8
|
+
exports.UpdateSources = ["STJ (Sharepoint)", "Juris"];
|
|
9
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
|
+
dotenv_1.default.config();
|
|
11
|
+
exports.ROOT_PATH = process.env['LOCAL_ROOT'] || 'results';
|
|
12
|
+
exports.FILESYSTEM_PATH = `/FileSystem`;
|
|
13
|
+
exports.SHAREPOINT_COPY_PATH = `/Sharepoint`;
|
|
14
|
+
exports.DETAILS_NAME = "Detalhes";
|
|
15
|
+
exports.ORIGINAL_NAME = "Original";
|
|
16
|
+
exports.LOGS_PATH = "/Updates";
|
|
17
|
+
exports.UPDATE_DIR = `${exports.ROOT_PATH}${exports.LOGS_PATH}`;
|
|
18
|
+
exports.SUPPORTED_EXTENSIONS = ["txt", "pdf", "docx"];
|
|
19
|
+
function isSupportedExtension(ext) {
|
|
20
|
+
return exports.SUPPORTED_EXTENSIONS.includes(ext);
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mdgf11/filesystem-lib",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Library to extend usage of jurisprudencia-document",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"license": "ISC",
|
|
9
|
+
"author": "Miguel Fonseca",
|
|
10
|
+
"type": "commonjs",
|
|
11
|
+
"main": "dist/index.js",
|
|
12
|
+
"types": "dist/index.d.ts",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"run": "node dist/index.js",
|
|
16
|
+
"start": "npm run build && npm run run"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@stjiris/jurisprudencia-document": "npm:@mdgf11/jurisprudencia-document@^13.1.0",
|
|
20
|
+
"dotenv": "^17.2.2",
|
|
21
|
+
"mammoth": "^1.10.0",
|
|
22
|
+
"pdfjs-dist": "^5.4.530"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^20.19.24",
|
|
26
|
+
"ts-jest": "^29.1.1",
|
|
27
|
+
"ts-node": "^10.9.2",
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
}
|
|
30
|
+
}
|