@nocobase/plugin-backup-restore 1.2.13-alpha → 1.3.0-alpha.20240710084543

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.
Files changed (152) hide show
  1. package/package.json +2 -2
  2. package/dist/client/Configuration.d.ts +0 -10
  3. package/dist/client/DuplicatorProvider.d.ts +0 -10
  4. package/dist/client/index.d.ts +0 -13
  5. package/dist/client/index.js +0 -10
  6. package/dist/client/locale/index.d.ts +0 -12
  7. package/dist/externalVersion.js +0 -23
  8. package/dist/index.d.ts +0 -10
  9. package/dist/index.js +0 -48
  10. package/dist/locale/en-US.json +0 -44
  11. package/dist/locale/ja-JP.d.ts +0 -33
  12. package/dist/locale/ja-JP.js +0 -55
  13. package/dist/locale/ko_KR.json +0 -50
  14. package/dist/locale/pt-BR.d.ts +0 -34
  15. package/dist/locale/pt-BR.js +0 -57
  16. package/dist/locale/zh-CN.json +0 -50
  17. package/dist/node_modules/@hapi/topo/lib/index.d.ts +0 -60
  18. package/dist/node_modules/@hapi/topo/lib/index.js +0 -1
  19. package/dist/node_modules/@hapi/topo/package.json +0 -1
  20. package/dist/node_modules/archiver/LICENSE +0 -22
  21. package/dist/node_modules/archiver/index.js +0 -68
  22. package/dist/node_modules/archiver/lib/core.js +0 -974
  23. package/dist/node_modules/archiver/lib/error.js +0 -40
  24. package/dist/node_modules/archiver/lib/plugins/json.js +0 -110
  25. package/dist/node_modules/archiver/lib/plugins/tar.js +0 -167
  26. package/dist/node_modules/archiver/lib/plugins/zip.js +0 -120
  27. package/dist/node_modules/archiver/node_modules/readable-stream/errors-browser.js +0 -127
  28. package/dist/node_modules/archiver/node_modules/readable-stream/errors.js +0 -116
  29. package/dist/node_modules/archiver/node_modules/readable-stream/experimentalWarning.js +0 -17
  30. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_duplex.js +0 -126
  31. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_passthrough.js +0 -37
  32. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_readable.js +0 -1027
  33. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_transform.js +0 -190
  34. package/dist/node_modules/archiver/node_modules/readable-stream/lib/_stream_writable.js +0 -641
  35. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/async_iterator.js +0 -180
  36. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/buffer_list.js +0 -183
  37. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/destroy.js +0 -96
  38. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/end-of-stream.js +0 -86
  39. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/from-browser.js +0 -3
  40. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/from.js +0 -52
  41. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/pipeline.js +0 -86
  42. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/state.js +0 -22
  43. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/stream-browser.js +0 -1
  44. package/dist/node_modules/archiver/node_modules/readable-stream/lib/internal/streams/stream.js +0 -1
  45. package/dist/node_modules/archiver/node_modules/readable-stream/package.json +0 -68
  46. package/dist/node_modules/archiver/node_modules/readable-stream/readable-browser.js +0 -9
  47. package/dist/node_modules/archiver/node_modules/readable-stream/readable.js +0 -16
  48. package/dist/node_modules/archiver/node_modules/string_decoder/lib/string_decoder.js +0 -296
  49. package/dist/node_modules/archiver/node_modules/string_decoder/package.json +0 -34
  50. package/dist/node_modules/archiver/node_modules/tar-stream/extract.js +0 -257
  51. package/dist/node_modules/archiver/node_modules/tar-stream/headers.js +0 -295
  52. package/dist/node_modules/archiver/node_modules/tar-stream/index.js +0 -2
  53. package/dist/node_modules/archiver/node_modules/tar-stream/pack.js +0 -255
  54. package/dist/node_modules/archiver/node_modules/tar-stream/package.json +0 -58
  55. package/dist/node_modules/archiver/node_modules/tar-stream/sandbox.js +0 -11
  56. package/dist/node_modules/archiver/package.json +0 -1
  57. package/dist/node_modules/decompress/index.js +0 -16
  58. package/dist/node_modules/decompress/license +0 -9
  59. package/dist/node_modules/decompress/node_modules/make-dir/index.js +0 -85
  60. package/dist/node_modules/decompress/node_modules/make-dir/license +0 -9
  61. package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/index.js +0 -84
  62. package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/license +0 -9
  63. package/dist/node_modules/decompress/node_modules/make-dir/node_modules/pify/package.json +0 -51
  64. package/dist/node_modules/decompress/node_modules/make-dir/package.json +0 -54
  65. package/dist/node_modules/decompress/package.json +0 -1
  66. package/dist/node_modules/mkdirp/LICENSE +0 -21
  67. package/dist/node_modules/mkdirp/bin/cmd.js +0 -68
  68. package/dist/node_modules/mkdirp/index.js +0 -1
  69. package/dist/node_modules/mkdirp/lib/find-made.js +0 -29
  70. package/dist/node_modules/mkdirp/lib/mkdirp-manual.js +0 -64
  71. package/dist/node_modules/mkdirp/lib/mkdirp-native.js +0 -39
  72. package/dist/node_modules/mkdirp/lib/opts-arg.js +0 -23
  73. package/dist/node_modules/mkdirp/lib/path-arg.js +0 -29
  74. package/dist/node_modules/mkdirp/lib/use-native.js +0 -10
  75. package/dist/node_modules/mkdirp/package.json +0 -1
  76. package/dist/node_modules/mkdirp/readme.markdown +0 -266
  77. package/dist/node_modules/semver/LICENSE +0 -15
  78. package/dist/node_modules/semver/bin/semver.js +0 -197
  79. package/dist/node_modules/semver/classes/comparator.js +0 -141
  80. package/dist/node_modules/semver/classes/index.js +0 -5
  81. package/dist/node_modules/semver/classes/range.js +0 -539
  82. package/dist/node_modules/semver/classes/semver.js +0 -302
  83. package/dist/node_modules/semver/functions/clean.js +0 -6
  84. package/dist/node_modules/semver/functions/cmp.js +0 -52
  85. package/dist/node_modules/semver/functions/coerce.js +0 -52
  86. package/dist/node_modules/semver/functions/compare-build.js +0 -7
  87. package/dist/node_modules/semver/functions/compare-loose.js +0 -3
  88. package/dist/node_modules/semver/functions/compare.js +0 -5
  89. package/dist/node_modules/semver/functions/diff.js +0 -65
  90. package/dist/node_modules/semver/functions/eq.js +0 -3
  91. package/dist/node_modules/semver/functions/gt.js +0 -3
  92. package/dist/node_modules/semver/functions/gte.js +0 -3
  93. package/dist/node_modules/semver/functions/inc.js +0 -19
  94. package/dist/node_modules/semver/functions/lt.js +0 -3
  95. package/dist/node_modules/semver/functions/lte.js +0 -3
  96. package/dist/node_modules/semver/functions/major.js +0 -3
  97. package/dist/node_modules/semver/functions/minor.js +0 -3
  98. package/dist/node_modules/semver/functions/neq.js +0 -3
  99. package/dist/node_modules/semver/functions/parse.js +0 -16
  100. package/dist/node_modules/semver/functions/patch.js +0 -3
  101. package/dist/node_modules/semver/functions/prerelease.js +0 -6
  102. package/dist/node_modules/semver/functions/rcompare.js +0 -3
  103. package/dist/node_modules/semver/functions/rsort.js +0 -3
  104. package/dist/node_modules/semver/functions/satisfies.js +0 -10
  105. package/dist/node_modules/semver/functions/sort.js +0 -3
  106. package/dist/node_modules/semver/functions/valid.js +0 -6
  107. package/dist/node_modules/semver/index.js +0 -1
  108. package/dist/node_modules/semver/internal/constants.js +0 -35
  109. package/dist/node_modules/semver/internal/debug.js +0 -9
  110. package/dist/node_modules/semver/internal/identifiers.js +0 -23
  111. package/dist/node_modules/semver/internal/parse-options.js +0 -15
  112. package/dist/node_modules/semver/internal/re.js +0 -212
  113. package/dist/node_modules/semver/package.json +0 -1
  114. package/dist/node_modules/semver/preload.js +0 -2
  115. package/dist/node_modules/semver/range.bnf +0 -16
  116. package/dist/node_modules/semver/ranges/gtr.js +0 -4
  117. package/dist/node_modules/semver/ranges/intersects.js +0 -7
  118. package/dist/node_modules/semver/ranges/ltr.js +0 -4
  119. package/dist/node_modules/semver/ranges/max-satisfying.js +0 -25
  120. package/dist/node_modules/semver/ranges/min-satisfying.js +0 -24
  121. package/dist/node_modules/semver/ranges/min-version.js +0 -61
  122. package/dist/node_modules/semver/ranges/outside.js +0 -80
  123. package/dist/node_modules/semver/ranges/simplify.js +0 -47
  124. package/dist/node_modules/semver/ranges/subset.js +0 -247
  125. package/dist/node_modules/semver/ranges/to-comparators.js +0 -8
  126. package/dist/node_modules/semver/ranges/valid.js +0 -11
  127. package/dist/server/app-migrator.d.ts +0 -25
  128. package/dist/server/app-migrator.js +0 -70
  129. package/dist/server/commands/restore-command.d.ts +0 -10
  130. package/dist/server/commands/restore-command.js +0 -77
  131. package/dist/server/dumper.d.ts +0 -79
  132. package/dist/server/dumper.js +0 -420
  133. package/dist/server/errors/restore-check-error.d.ts +0 -11
  134. package/dist/server/errors/restore-check-error.js +0 -41
  135. package/dist/server/field-value-writer.d.ts +0 -17
  136. package/dist/server/field-value-writer.js +0 -110
  137. package/dist/server/index.d.ts +0 -9
  138. package/dist/server/index.js +0 -42
  139. package/dist/server/locale/zh-CN.d.ts +0 -17
  140. package/dist/server/locale/zh-CN.js +0 -39
  141. package/dist/server/migrations/20240618103927-update-snippet-name.d.ts +0 -14
  142. package/dist/server/migrations/20240618103927-update-snippet-name.js +0 -60
  143. package/dist/server/resourcers/backup-files.d.ts +0 -33
  144. package/dist/server/resourcers/backup-files.js +0 -202
  145. package/dist/server/restorer.d.ts +0 -43
  146. package/dist/server/restorer.js +0 -363
  147. package/dist/server/server.d.ts +0 -13
  148. package/dist/server/server.js +0 -54
  149. package/dist/server/utils.d.ts +0 -13
  150. package/dist/server/utils.js +0 -87
  151. package/dist/swagger/index.d.ts +0 -400
  152. package/dist/swagger/index.js +0 -456
@@ -1,420 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var dumper_exports = {};
38
- __export(dumper_exports, {
39
- Dumper: () => Dumper
40
- });
41
- module.exports = __toCommonJS(dumper_exports);
42
- var import_database = require("@nocobase/database");
43
- var import_archiver = __toESM(require("archiver"));
44
- var import_dayjs = __toESM(require("dayjs"));
45
- var import_fs = __toESM(require("fs"));
46
- var import_promises = __toESM(require("fs/promises"));
47
- var import_lodash = __toESM(require("lodash"));
48
- var import_mkdirp = __toESM(require("mkdirp"));
49
- var import_path = __toESM(require("path"));
50
- var process = __toESM(require("process"));
51
- var import_stream = __toESM(require("stream"));
52
- var import_util = __toESM(require("util"));
53
- var import_app_migrator = require("./app-migrator");
54
- var import_field_value_writer = require("./field-value-writer");
55
- var import_utils = require("./utils");
56
- const finished = import_util.default.promisify(import_stream.default.finished);
57
- class Dumper extends import_app_migrator.AppMigrator {
58
- static dumpTasks = /* @__PURE__ */ new Map();
59
- direction = "dump";
60
- sqlContent = {};
61
- static getTaskPromise(taskId) {
62
- return this.dumpTasks.get(taskId);
63
- }
64
- static async getFileStatus(filePath) {
65
- const lockFile = filePath + ".lock";
66
- const fileName = import_path.default.basename(filePath);
67
- return import_fs.default.promises.stat(lockFile).then((lockFileStat) => {
68
- if (lockFileStat.isFile()) {
69
- return {
70
- name: fileName,
71
- inProgress: true,
72
- status: "in_progress"
73
- };
74
- } else {
75
- throw new Error("Lock file is not a file");
76
- }
77
- }).catch((error) => {
78
- if (error.code === "ENOENT") {
79
- return import_fs.default.promises.stat(filePath).then((backupFileStat) => {
80
- if (backupFileStat.isFile()) {
81
- return {
82
- name: fileName,
83
- createdAt: backupFileStat.ctime,
84
- fileSize: (0, import_utils.humanFileSize)(backupFileStat.size),
85
- status: "ok"
86
- };
87
- } else {
88
- throw new Error("Path is not a file");
89
- }
90
- });
91
- }
92
- throw error;
93
- });
94
- }
95
- static generateFileName() {
96
- return `backup_${(0, import_dayjs.default)().format(`YYYYMMDD_HHmmss_${Math.floor(1e3 + Math.random() * 9e3)}`)}.${import_utils.DUMPED_EXTENSION}`;
97
- }
98
- writeSQLContent(key, data) {
99
- this.sqlContent[key] = data;
100
- }
101
- getSQLContent(key) {
102
- return this.sqlContent[key];
103
- }
104
- async getCollectionsByDataTypes(groups) {
105
- const dumpableCollectionsGroupByDataTypes = await this.collectionsGroupByDataTypes();
106
- return [...groups].reduce((acc, key) => {
107
- return acc.concat(dumpableCollectionsGroupByDataTypes[key] || []);
108
- }, []);
109
- }
110
- async dumpableCollections() {
111
- return (await Promise.all(
112
- [...this.app.db.collections.values()].map(async (c) => {
113
- try {
114
- const dumpRules = import_database.CollectionGroupManager.unifyDumpRules(c.options.dumpRules);
115
- const options = {
116
- name: c.name,
117
- title: c.options.title || c.name,
118
- options: c.options,
119
- group: dumpRules == null ? void 0 : dumpRules.group,
120
- isView: c.isView(),
121
- origin: c.origin
122
- };
123
- if (c.options.inherits && c.options.inherits.length > 0) {
124
- options.inherits = c.options.inherits;
125
- }
126
- return options;
127
- } catch (e) {
128
- console.error(e);
129
- throw new Error(`collection ${c.name} has invalid dumpRules option`, { cause: e });
130
- }
131
- })
132
- )).map((item) => {
133
- if (!item.group) {
134
- item.group = "unknown";
135
- }
136
- return item;
137
- });
138
- }
139
- async collectionsGroupByDataTypes() {
140
- const grouped = import_lodash.default.groupBy(await this.dumpableCollections(), "group");
141
- return Object.fromEntries(Object.entries(grouped).map(([key, value]) => [key, value.map((item) => item.name)]));
142
- }
143
- backUpStorageDir() {
144
- return import_path.default.resolve(process.cwd(), "storage", "backups");
145
- }
146
- async allBackUpFilePaths(options) {
147
- const dirname = (options == null ? void 0 : options.dir) || this.backUpStorageDir();
148
- const includeInProgress = options == null ? void 0 : options.includeInProgress;
149
- try {
150
- const files = await import_promises.default.readdir(dirname);
151
- const lockFilesSet = new Set(
152
- files.filter((file) => import_path.default.extname(file) === ".lock").map((file) => import_path.default.basename(file, ".lock"))
153
- );
154
- const filteredFiles = files.filter((file) => {
155
- const baseName = import_path.default.basename(file);
156
- const isLockFile = import_path.default.extname(file) === ".lock";
157
- const isDumpFile = import_path.default.extname(file) === `.${import_utils.DUMPED_EXTENSION}`;
158
- return includeInProgress && isLockFile || isDumpFile && !lockFilesSet.has(baseName);
159
- }).map(async (file) => {
160
- const filePath = import_path.default.resolve(dirname, file);
161
- const stats = await import_promises.default.stat(filePath);
162
- return { filePath, birthtime: stats.birthtime.getTime() };
163
- });
164
- const filesData = await Promise.all(filteredFiles);
165
- filesData.sort((a, b) => b.birthtime - a.birthtime);
166
- return filesData.map((fileData) => fileData.filePath);
167
- } catch (error) {
168
- if (!error.message.includes("no such file or directory")) {
169
- console.error("Error reading directory:", error);
170
- }
171
- return [];
172
- }
173
- }
174
- backUpFilePath(fileName) {
175
- const dirname = this.backUpStorageDir();
176
- return import_path.default.resolve(dirname, fileName);
177
- }
178
- lockFilePath(fileName) {
179
- const lockFile = fileName + ".lock";
180
- const dirname = this.backUpStorageDir();
181
- return import_path.default.resolve(dirname, lockFile);
182
- }
183
- async writeLockFile(fileName) {
184
- const dirname = this.backUpStorageDir();
185
- await (0, import_mkdirp.default)(dirname);
186
- const filePath = this.lockFilePath(fileName);
187
- await import_promises.default.writeFile(filePath, "lock", "utf8");
188
- }
189
- async cleanLockFile(fileName) {
190
- const filePath = this.lockFilePath(fileName);
191
- await import_promises.default.unlink(filePath);
192
- }
193
- async runDumpTask(options) {
194
- const backupFileName = Dumper.generateFileName();
195
- await this.writeLockFile(backupFileName);
196
- const promise = this.dump({
197
- groups: options.groups,
198
- fileName: backupFileName
199
- }).finally(() => {
200
- this.cleanLockFile(backupFileName);
201
- Dumper.dumpTasks.delete(backupFileName);
202
- });
203
- Dumper.dumpTasks.set(backupFileName, promise);
204
- return backupFileName;
205
- }
206
- async dumpableCollectionsGroupByGroup() {
207
- return (0, import_lodash.default)(await this.dumpableCollections()).map((c) => import_lodash.default.pick(c, ["name", "group", "origin", "title", "isView", "inherits"])).groupBy("group").mapValues((items) => import_lodash.default.sortBy(items, (item) => item.name)).value();
208
- }
209
- async dump(options) {
210
- const dumpingGroups = options.groups;
211
- dumpingGroups.add("required");
212
- const delayCollections = /* @__PURE__ */ new Set();
213
- const dumpedCollections = await this.getCollectionsByDataTypes(dumpingGroups);
214
- for (const collectionName of dumpedCollections) {
215
- const collection = this.app.db.getCollection(collectionName);
216
- if (import_lodash.default.get(collection.options, "dumpRules.delayRestore")) {
217
- delayCollections.add(collectionName);
218
- }
219
- await this.dumpCollection({
220
- name: collectionName
221
- });
222
- }
223
- await this.dumpMeta({
224
- dumpableCollectionsGroupByGroup: import_lodash.default.pick(await this.dumpableCollectionsGroupByGroup(), [...dumpingGroups]),
225
- dumpedGroups: [...dumpingGroups],
226
- delayCollections: [...delayCollections]
227
- });
228
- await this.dumpDb(options);
229
- const backupFileName = options.fileName || Dumper.generateFileName();
230
- const filePath = await this.packDumpedDir(backupFileName);
231
- await this.clearWorkDir();
232
- return filePath;
233
- }
234
- async dumpDb(options) {
235
- var _a;
236
- for (const collection of this.app.db.collections.values()) {
237
- const collectionOnDumpOption = (_a = this.app.db.collectionFactory.collectionTypes.get(
238
- collection.constructor
239
- )) == null ? void 0 : _a.onDump;
240
- if (collectionOnDumpOption) {
241
- await collectionOnDumpOption(this, collection);
242
- }
243
- }
244
- if (this.hasSqlContent()) {
245
- const dbDumpPath = import_path.default.resolve(this.workDir, "sql-content.json");
246
- await import_promises.default.writeFile(
247
- dbDumpPath,
248
- JSON.stringify(
249
- Object.keys(this.sqlContent).filter((key) => options.groups.has(this.sqlContent[key].group)).reduce((acc, key) => {
250
- acc[key] = this.sqlContent[key];
251
- return acc;
252
- }, {})
253
- ),
254
- "utf8"
255
- );
256
- }
257
- }
258
- hasSqlContent() {
259
- return Object.keys(this.sqlContent).length > 0;
260
- }
261
- async dumpMeta(additionalMeta = {}) {
262
- const metaPath = import_path.default.resolve(this.workDir, "meta");
263
- const metaObj = {
264
- version: await this.app.version.get(),
265
- dialect: this.app.db.sequelize.getDialect(),
266
- DB_UNDERSCORED: process.env.DB_UNDERSCORED,
267
- DB_TABLE_PREFIX: process.env.DB_TABLE_PREFIX,
268
- DB_SCHEMA: process.env.DB_SCHEMA,
269
- COLLECTION_MANAGER_SCHEMA: process.env.COLLECTION_MANAGER_SCHEMA,
270
- ...additionalMeta
271
- };
272
- if (this.app.db.inDialect("postgres")) {
273
- if (this.app.db.inheritanceMap.nodes.size > 0) {
274
- metaObj["dialectOnly"] = true;
275
- }
276
- }
277
- if (this.hasSqlContent()) {
278
- metaObj["dialectOnly"] = true;
279
- }
280
- await import_promises.default.writeFile(metaPath, JSON.stringify(metaObj), "utf8");
281
- }
282
- async dumpCollection(options) {
283
- var _a;
284
- const app = this.app;
285
- const dir = this.workDir;
286
- const collectionName = options.name;
287
- app.log.info(`dumping collection ${collectionName}`);
288
- const collection = app.db.getCollection(collectionName);
289
- if (!collection) {
290
- this.app.log.warn(`collection ${collectionName} not found`);
291
- return;
292
- }
293
- const collectionOnDumpOption = (_a = this.app.db.collectionFactory.collectionTypes.get(
294
- collection.constructor
295
- )) == null ? void 0 : _a.onDump;
296
- if (collectionOnDumpOption) {
297
- return;
298
- }
299
- const attributes = collection.model.tableAttributes;
300
- const columns = [...new Set(import_lodash.default.map(attributes, "field"))];
301
- const collectionDataDir = import_path.default.resolve(dir, "collections", collectionName);
302
- await import_promises.default.mkdir(collectionDataDir, { recursive: true });
303
- let count = 0;
304
- if (columns.length !== 0) {
305
- const dataFilePath = import_path.default.resolve(collectionDataDir, "data");
306
- const dataStream = import_fs.default.createWriteStream(dataFilePath);
307
- const rows = await app.db.sequelize.query(
308
- (0, import_utils.sqlAdapter)(
309
- app.db,
310
- `SELECT *
311
- FROM ${collection.isParent() ? "ONLY" : ""} ${collection.quotedTableName()}`
312
- ),
313
- {
314
- type: "SELECT"
315
- }
316
- );
317
- for (const row of rows) {
318
- const rowData = JSON.stringify(
319
- columns.map((col) => {
320
- const val = row[col];
321
- const field = collection.getField(col);
322
- return field ? import_field_value_writer.FieldValueWriter.toDumpedValue(field, val) : val;
323
- })
324
- );
325
- dataStream.write(rowData + "\r\n", "utf8");
326
- }
327
- dataStream.end();
328
- await finished(dataStream);
329
- count = rows.length;
330
- }
331
- const metaAttributes = import_lodash.default.mapValues(attributes, (attr, key) => {
332
- var _a2, _b, _c;
333
- const collectionField = collection.getField(key);
334
- const fieldOptionKeys = ["field", "primaryKey", "autoIncrement", "allowNull", "defaultValue", "unique"];
335
- if (collectionField) {
336
- const fieldAttributes = {
337
- field: attr.field,
338
- isCollectionField: true,
339
- type: collectionField.type,
340
- typeOptions: collectionField.options
341
- };
342
- if (((_c = (_b = (_a2 = fieldAttributes.typeOptions) == null ? void 0 : _a2.defaultValue) == null ? void 0 : _b.constructor) == null ? void 0 : _c.name) === "UUIDV4") {
343
- delete fieldAttributes.typeOptions.defaultValue;
344
- }
345
- return fieldAttributes;
346
- }
347
- return {
348
- ...import_lodash.default.pick(attr, fieldOptionKeys),
349
- type: attr.type.constructor.toString(),
350
- isCollectionField: false,
351
- typeOptions: attr.type.options
352
- };
353
- });
354
- const meta = {
355
- name: collectionName,
356
- tableName: collection.getTableNameWithSchema(),
357
- count,
358
- columns,
359
- attributes: metaAttributes
360
- };
361
- if (collection.options.inherits) {
362
- meta["inherits"] = import_lodash.default.uniq(collection.options.inherits);
363
- }
364
- const autoIncrAttr = collection.model.autoIncrementAttribute;
365
- if (autoIncrAttr && collection.model.rawAttributes[autoIncrAttr] && collection.model.rawAttributes[autoIncrAttr].autoIncrement) {
366
- const queryInterface = app.db.queryInterface;
367
- const autoIncrInfo = await queryInterface.getAutoIncrementInfo({
368
- tableInfo: {
369
- tableName: collection.model.tableName,
370
- schema: collection.collectionSchema()
371
- },
372
- fieldName: autoIncrAttr
373
- });
374
- meta["autoIncrement"] = {
375
- ...autoIncrInfo,
376
- fieldName: autoIncrAttr
377
- };
378
- }
379
- await import_promises.default.writeFile(import_path.default.resolve(collectionDataDir, "meta"), JSON.stringify(meta), "utf8");
380
- }
381
- async packDumpedDir(fileName) {
382
- const dirname = this.backUpStorageDir();
383
- await (0, import_mkdirp.default)(dirname);
384
- const filePath = import_path.default.resolve(dirname, fileName);
385
- const output = import_fs.default.createWriteStream(filePath);
386
- const archive = (0, import_archiver.default)("zip", {
387
- zlib: { level: 9 }
388
- });
389
- const onClose = new Promise((resolve, reject) => {
390
- output.on("close", function() {
391
- console.log("dumped file size: " + (0, import_utils.humanFileSize)(archive.pointer(), true));
392
- resolve(true);
393
- });
394
- output.on("end", function() {
395
- console.log("Data has been drained");
396
- });
397
- archive.on("warning", function(err) {
398
- if (err.code === "ENOENT") {
399
- } else {
400
- reject(err);
401
- }
402
- });
403
- archive.on("error", function(err) {
404
- reject(err);
405
- });
406
- });
407
- archive.pipe(output);
408
- archive.directory(this.workDir, false);
409
- await archive.finalize();
410
- await onClose;
411
- return {
412
- filePath,
413
- dirname
414
- };
415
- }
416
- }
417
- // Annotate the CommonJS export names for ESM import in node:
418
- 0 && (module.exports = {
419
- Dumper
420
- });
@@ -1,11 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export declare class RestoreCheckError extends Error {
10
- constructor(message: any);
11
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __defProp = Object.defineProperty;
11
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
- var __getOwnPropNames = Object.getOwnPropertyNames;
13
- var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __export = (target, all) => {
15
- for (var name in all)
16
- __defProp(target, name, { get: all[name], enumerable: true });
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
- var restore_check_error_exports = {};
28
- __export(restore_check_error_exports, {
29
- RestoreCheckError: () => RestoreCheckError
30
- });
31
- module.exports = __toCommonJS(restore_check_error_exports);
32
- class RestoreCheckError extends Error {
33
- constructor(message) {
34
- super(message);
35
- this.name = "RestoreCheckError";
36
- }
37
- }
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- RestoreCheckError
41
- });
@@ -1,17 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- import { Field } from '@nocobase/database';
10
- type WriterFunc = (val: any) => any;
11
- export declare class FieldValueWriter {
12
- static writers: Map<string, WriterFunc>;
13
- static write(field: Field, val: any): any;
14
- static toDumpedValue(field: Field, val: any): any;
15
- static registerWriter(types: string | string[], writer: WriterFunc): void;
16
- }
17
- export {};
@@ -1,110 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var field_value_writer_exports = {};
38
- __export(field_value_writer_exports, {
39
- FieldValueWriter: () => FieldValueWriter
40
- });
41
- module.exports = __toCommonJS(field_value_writer_exports);
42
- var import_database = require("@nocobase/database");
43
- var import_lodash = __toESM(require("lodash"));
44
- const getMapFieldWriter = (field) => {
45
- return (val) => {
46
- const mockObj = {
47
- setDataValue: (name, newVal) => {
48
- val = newVal;
49
- }
50
- };
51
- field.options.set.call(mockObj, val);
52
- return val;
53
- };
54
- };
55
- class FieldValueWriter {
56
- static writers = /* @__PURE__ */ new Map();
57
- static write(field, val) {
58
- if (val === null)
59
- return val;
60
- if (field.type == "point" || field.type == "lineString" || field.type == "circle" || field.type === "polygon") {
61
- return getMapFieldWriter(field)(import_lodash.default.isString(val) ? JSON.parse(val) : val);
62
- }
63
- const fieldType = field.typeToString();
64
- const writer = FieldValueWriter.writers[fieldType];
65
- if (writer) {
66
- val = writer(val);
67
- }
68
- return val;
69
- }
70
- static toDumpedValue(field, val) {
71
- if (val === null)
72
- return val;
73
- if (field.type == "point" || field.type == "lineString" || field.type == "circle" || field.type === "polygon") {
74
- const mockObj = {
75
- getDataValue: () => val
76
- };
77
- const newValue = field.options.get.call(mockObj);
78
- return newValue;
79
- }
80
- return val;
81
- }
82
- static registerWriter(types, writer) {
83
- for (const type of import_lodash.default.castArray(types)) {
84
- FieldValueWriter.writers[type] = writer;
85
- }
86
- }
87
- }
88
- function isJSONObjectOrArrayString(str) {
89
- try {
90
- const parsed = JSON.parse(str);
91
- return typeof parsed === "object" && parsed !== null;
92
- } catch (e) {
93
- return false;
94
- }
95
- }
96
- FieldValueWriter.registerWriter([import_database.DataTypes.JSON.toString(), import_database.DataTypes.JSONB.toString()], (val) => {
97
- try {
98
- return isJSONObjectOrArrayString(val) ? JSON.parse(val) : val;
99
- } catch (err) {
100
- if (err instanceof SyntaxError && err.message.includes("Unexpected")) {
101
- return val;
102
- }
103
- throw err;
104
- }
105
- });
106
- FieldValueWriter.registerWriter(import_database.DataTypes.BOOLEAN.toString(), (val) => Boolean(val));
107
- // Annotate the CommonJS export names for ESM import in node:
108
- 0 && (module.exports = {
109
- FieldValueWriter
110
- });
@@ -1,9 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- export { default } from './server';
@@ -1,42 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- var __create = Object.create;
11
- var __defProp = Object.defineProperty;
12
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
- var __getOwnPropNames = Object.getOwnPropertyNames;
14
- var __getProtoOf = Object.getPrototypeOf;
15
- var __hasOwnProp = Object.prototype.hasOwnProperty;
16
- var __export = (target, all) => {
17
- for (var name in all)
18
- __defProp(target, name, { get: all[name], enumerable: true });
19
- };
20
- var __copyProps = (to, from, except, desc) => {
21
- if (from && typeof from === "object" || typeof from === "function") {
22
- for (let key of __getOwnPropNames(from))
23
- if (!__hasOwnProp.call(to, key) && key !== except)
24
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
- }
26
- return to;
27
- };
28
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
- // If the importer is in node compatibility mode or this is not an ESM
30
- // file that has been converted to a CommonJS file using a Babel-
31
- // compatible transform (i.e. "__esModule" has not been set), then set
32
- // "default" to the CommonJS "module.exports" for node compatibility.
33
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
- mod
35
- ));
36
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var server_exports = {};
38
- __export(server_exports, {
39
- default: () => import_server.default
40
- });
41
- module.exports = __toCommonJS(server_exports);
42
- var import_server = __toESM(require("./server"));
@@ -1,17 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
- declare const _default: {
10
- 'Select Import data': string;
11
- 'Select Import Plugins': string;
12
- 'Select User Collections': string;
13
- 'Basic Data': string;
14
- 'Optional Data': string;
15
- 'User Data': string;
16
- };
17
- export default _default;