@lossless.org/nosqldb 8.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.
Files changed (81) hide show
  1. package/.smartconfig.json +107 -0
  2. package/dist_rust/rustdb_linux_amd64 +0 -0
  3. package/dist_rust/rustdb_linux_amd64.tsrust-build.json +14 -0
  4. package/dist_rust/rustdb_linux_arm64 +0 -0
  5. package/dist_rust/rustdb_linux_arm64.tsrust-build.json +14 -0
  6. package/dist_rust/rustdb_macos_amd64 +0 -0
  7. package/dist_rust/rustdb_macos_amd64.tsrust-build.json +14 -0
  8. package/dist_rust/rustdb_macos_arm64 +0 -0
  9. package/dist_rust/rustdb_macos_arm64.tsrust-build.json +14 -0
  10. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  11. package/dist_ts/00_commitinfo_data.js +9 -0
  12. package/dist_ts/index.d.ts +8 -0
  13. package/dist_ts/index.js +10 -0
  14. package/dist_ts/ts_local/classes.localnosqldb.d.ts +119 -0
  15. package/dist_ts/ts_local/classes.localnosqldb.js +386 -0
  16. package/dist_ts/ts_local/index.d.ts +5 -0
  17. package/dist_ts/ts_local/index.js +3 -0
  18. package/dist_ts/ts_local/plugins.d.ts +1 -0
  19. package/dist_ts/ts_local/plugins.js +3 -0
  20. package/dist_ts/ts_nosqldb/classes.storagerehearsal.d.ts +19 -0
  21. package/dist_ts/ts_nosqldb/classes.storagerehearsal.js +122 -0
  22. package/dist_ts/ts_nosqldb/file-storage-options.d.ts +13 -0
  23. package/dist_ts/ts_nosqldb/file-storage-options.js +24 -0
  24. package/dist_ts/ts_nosqldb/file-storage-startup.d.ts +3 -0
  25. package/dist_ts/ts_nosqldb/file-storage-startup.js +6 -0
  26. package/dist_ts/ts_nosqldb/index.d.ts +14 -0
  27. package/dist_ts/ts_nosqldb/index.js +11 -0
  28. package/dist_ts/ts_nosqldb/offline-inspection.d.ts +72 -0
  29. package/dist_ts/ts_nosqldb/offline-inspection.js +282 -0
  30. package/dist_ts/ts_nosqldb/plugins.d.ts +7 -0
  31. package/dist_ts/ts_nosqldb/plugins.js +10 -0
  32. package/dist_ts/ts_nosqldb/resource-fencing.d.ts +39 -0
  33. package/dist_ts/ts_nosqldb/resource-fencing.js +271 -0
  34. package/dist_ts/ts_nosqldb/rust-db-bridge.d.ts +213 -0
  35. package/dist_ts/ts_nosqldb/rust-db-bridge.js +439 -0
  36. package/dist_ts/ts_nosqldb/server/classes.nosqldbserver.d.ts +204 -0
  37. package/dist_ts/ts_nosqldb/server/classes.nosqldbserver.js +456 -0
  38. package/dist_ts/ts_nosqldb/server/index.d.ts +3 -0
  39. package/dist_ts/ts_nosqldb/server/index.js +3 -0
  40. package/dist_ts/ts_nosqldb/service-types.d.ts +341 -0
  41. package/dist_ts/ts_nosqldb/service-types.js +62 -0
  42. package/dist_ts/ts_nosqldb/storage-rehearsal.d.ts +103 -0
  43. package/dist_ts/ts_nosqldb/storage-rehearsal.js +131 -0
  44. package/dist_ts/ts_nosqldb/storage-root-relocation.d.ts +27 -0
  45. package/dist_ts/ts_nosqldb/storage-root-relocation.js +211 -0
  46. package/dist_ts_debugserver/bundled.d.ts +4 -0
  47. package/dist_ts_debugserver/bundled.js +16 -0
  48. package/dist_ts_debugserver/classes.debugserver.d.ts +36 -0
  49. package/dist_ts_debugserver/classes.debugserver.js +95 -0
  50. package/dist_ts_debugserver/index.d.ts +2 -0
  51. package/dist_ts_debugserver/index.js +2 -0
  52. package/dist_ts_debugserver/plugins.d.ts +2 -0
  53. package/dist_ts_debugserver/plugins.js +3 -0
  54. package/dist_ts_debugui/index.d.ts +2 -0
  55. package/dist_ts_debugui/index.js +2 -0
  56. package/dist_ts_debugui/nosqldb-debugui.d.ts +62 -0
  57. package/dist_ts_debugui/nosqldb-debugui.js +1132 -0
  58. package/dist_ts_debugui/plugins.d.ts +1 -0
  59. package/dist_ts_debugui/plugins.js +2 -0
  60. package/license +21 -0
  61. package/package.json +82 -0
  62. package/readme.md +1733 -0
  63. package/third-party-notices.md +925 -0
  64. package/ts/00_commitinfo_data.ts +8 -0
  65. package/ts/index.ts +85 -0
  66. package/ts/ts_local/classes.localnosqldb.ts +500 -0
  67. package/ts/ts_local/index.ts +19 -0
  68. package/ts/ts_local/plugins.ts +1 -0
  69. package/ts/ts_nosqldb/classes.storagerehearsal.ts +109 -0
  70. package/ts/ts_nosqldb/file-storage-options.ts +33 -0
  71. package/ts/ts_nosqldb/file-storage-startup.ts +9 -0
  72. package/ts/ts_nosqldb/index.ts +104 -0
  73. package/ts/ts_nosqldb/offline-inspection.ts +375 -0
  74. package/ts/ts_nosqldb/plugins.ts +12 -0
  75. package/ts/ts_nosqldb/resource-fencing.ts +368 -0
  76. package/ts/ts_nosqldb/rust-db-bridge.ts +964 -0
  77. package/ts/ts_nosqldb/server/classes.nosqldbserver.ts +696 -0
  78. package/ts/ts_nosqldb/server/index.ts +4 -0
  79. package/ts/ts_nosqldb/service-types.ts +484 -0
  80. package/ts/ts_nosqldb/storage-rehearsal.ts +215 -0
  81. package/ts/ts_nosqldb/storage-root-relocation.ts +277 -0
@@ -0,0 +1,277 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ export const localNoSqlDbStorageRootRelocationErrorCodes = [
4
+ 'INVALID_REQUEST',
5
+ 'UNSUPPORTED',
6
+ 'BUSY',
7
+ 'NOT_FOUND',
8
+ 'DESTINATION_CONFLICT',
9
+ 'IDENTITY_MISMATCH',
10
+ 'STATE_CORRUPT',
11
+ 'SOURCE_CHANGED',
12
+ 'CAPACITY',
13
+ 'CANCELLED',
14
+ 'IO',
15
+ 'RECOVERY_REQUIRED',
16
+ ] as const;
17
+
18
+ export type TLocalNoSqlDbStorageRootRelocationErrorCode =
19
+ (typeof localNoSqlDbStorageRootRelocationErrorCodes)[number];
20
+
21
+ export interface ILocalNoSqlDbStoppedStorageRootRelocationInput {
22
+ sourceFolderPath: string;
23
+ destinationFolderPath: string;
24
+ relocationId: string;
25
+ }
26
+
27
+ export interface ILocalNoSqlDbStoppedStorageRootRelocationReceipt {
28
+ format: 'smartdb.storage-root-relocation.receipt.v1';
29
+ version: 1;
30
+ relocationId: string;
31
+ sourceFolderPath: string;
32
+ destinationFolderPath: string;
33
+ providerRootId: string;
34
+ storageRootDevice: string;
35
+ storageRootInode: string;
36
+ receiptSha256: string;
37
+ sourceReceiptRetained: true;
38
+ }
39
+
40
+ export class LocalNoSqlDbStorageRootRelocationError extends Error {
41
+ public readonly code: TLocalNoSqlDbStorageRootRelocationErrorCode;
42
+
43
+ public constructor(codeArg: TLocalNoSqlDbStorageRootRelocationErrorCode) {
44
+ super(`NoSQLDB stopped storage-root relocation failed with code ${codeArg}`);
45
+ this.name = 'LocalNoSqlDbStorageRootRelocationError';
46
+ this.code = codeArg;
47
+ }
48
+ }
49
+
50
+ const relocationInputKeys = [
51
+ 'sourceFolderPath',
52
+ 'destinationFolderPath',
53
+ 'relocationId',
54
+ ] as const;
55
+ const relocationReceiptKeys = [
56
+ 'format',
57
+ 'version',
58
+ 'relocationId',
59
+ 'sourceFolderPath',
60
+ 'destinationFolderPath',
61
+ 'providerRootId',
62
+ 'storageRootDevice',
63
+ 'storageRootInode',
64
+ 'receiptSha256',
65
+ 'sourceReceiptRetained',
66
+ ] as const;
67
+ const maximumFolderPathBytes = 4095;
68
+ const maximumRelocationIdBytes = 256;
69
+ const maximumU64Decimal = '18446744073709551615';
70
+ const receiptDigestDomain = 'smartdb.storage-root-relocation.receipt.v1\0';
71
+
72
+ const relocationError = (
73
+ codeArg: TLocalNoSqlDbStorageRootRelocationErrorCode,
74
+ ): LocalNoSqlDbStorageRootRelocationError =>
75
+ new LocalNoSqlDbStorageRootRelocationError(codeArg);
76
+
77
+ const isPlainExactDataObject = (
78
+ valueArg: unknown,
79
+ keysArg: readonly string[],
80
+ ): valueArg is Record<string, unknown> => {
81
+ if (
82
+ typeof valueArg !== 'object'
83
+ || valueArg === null
84
+ || Array.isArray(valueArg)
85
+ || Object.getPrototypeOf(valueArg) !== Object.prototype
86
+ ) {
87
+ return false;
88
+ }
89
+ const ownKeys = Reflect.ownKeys(valueArg);
90
+ if (
91
+ ownKeys.length !== keysArg.length
92
+ || ownKeys.some((keyArg) => typeof keyArg !== 'string' || !keysArg.includes(keyArg))
93
+ ) {
94
+ return false;
95
+ }
96
+ const descriptors = Object.getOwnPropertyDescriptors(valueArg);
97
+ return keysArg.every((keyArg) => {
98
+ const descriptor = descriptors[keyArg];
99
+ return descriptor !== undefined
100
+ && descriptor.enumerable
101
+ && Object.prototype.hasOwnProperty.call(descriptor, 'value');
102
+ });
103
+ };
104
+
105
+ const isValidUnicodeScalarString = (valueArg: string): boolean => {
106
+ for (let index = 0; index < valueArg.length; index++) {
107
+ const code = valueArg.charCodeAt(index);
108
+ if (code >= 0xd800 && code <= 0xdbff) {
109
+ const next = valueArg.charCodeAt(index + 1);
110
+ if (next < 0xdc00 || next > 0xdfff) return false;
111
+ index++;
112
+ } else if (code >= 0xdc00 && code <= 0xdfff) {
113
+ return false;
114
+ }
115
+ }
116
+ return true;
117
+ };
118
+
119
+ const isNestedPath = (parentArg: string, childArg: string): boolean => {
120
+ const relative = plugins.path.relative(parentArg, childArg);
121
+ return relative !== ''
122
+ && relative !== '..'
123
+ && !relative.startsWith(`..${plugins.path.sep}`)
124
+ && !plugins.path.isAbsolute(relative);
125
+ };
126
+
127
+ const normalizeFolderPath = (valueArg: unknown): string => {
128
+ if (
129
+ typeof valueArg !== 'string'
130
+ || !plugins.path.isAbsolute(valueArg)
131
+ || !isValidUnicodeScalarString(valueArg)
132
+ || [...valueArg].some(characterArg => /\p{Cc}/u.test(characterArg))
133
+ ) {
134
+ throw relocationError('INVALID_REQUEST');
135
+ }
136
+ const initialBytes = plugins.buffer.Buffer.byteLength(valueArg, 'utf8');
137
+ if (initialBytes < 1 || initialBytes > maximumFolderPathBytes) {
138
+ throw relocationError('INVALID_REQUEST');
139
+ }
140
+ const normalized = plugins.path.resolve(valueArg);
141
+ const normalizedBytes = plugins.buffer.Buffer.byteLength(normalized, 'utf8');
142
+ if (
143
+ normalizedBytes < 1
144
+ || normalizedBytes > maximumFolderPathBytes
145
+ || plugins.path.parse(normalized).root === normalized
146
+ || !isValidUnicodeScalarString(normalized)
147
+ || [...normalized].some(characterArg => /\p{Cc}/u.test(characterArg))
148
+ ) {
149
+ throw relocationError('INVALID_REQUEST');
150
+ }
151
+ return normalized;
152
+ };
153
+
154
+ export const normalizeLocalNoSqlDbStoppedStorageRootRelocationInput = (
155
+ inputArg: ILocalNoSqlDbStoppedStorageRootRelocationInput,
156
+ ): ILocalNoSqlDbStoppedStorageRootRelocationInput => {
157
+ if (!isPlainExactDataObject(inputArg, relocationInputKeys)) {
158
+ throw relocationError('INVALID_REQUEST');
159
+ }
160
+ const sourceFolderPath = normalizeFolderPath(inputArg.sourceFolderPath);
161
+ const destinationFolderPath = normalizeFolderPath(inputArg.destinationFolderPath);
162
+ if (
163
+ sourceFolderPath === destinationFolderPath
164
+ || isNestedPath(sourceFolderPath, destinationFolderPath)
165
+ || isNestedPath(destinationFolderPath, sourceFolderPath)
166
+ ) {
167
+ throw relocationError('INVALID_REQUEST');
168
+ }
169
+ if (
170
+ typeof inputArg.relocationId !== 'string'
171
+ || plugins.buffer.Buffer.byteLength(inputArg.relocationId, 'utf8') > maximumRelocationIdBytes
172
+ || !/^[A-Za-z0-9][A-Za-z0-9._:@-]*$/.test(inputArg.relocationId)
173
+ ) {
174
+ throw relocationError('INVALID_REQUEST');
175
+ }
176
+ return {
177
+ sourceFolderPath,
178
+ destinationFolderPath,
179
+ relocationId: inputArg.relocationId,
180
+ };
181
+ };
182
+
183
+ const receiptDigest = (
184
+ receiptArg: Omit<ILocalNoSqlDbStoppedStorageRootRelocationReceipt, 'receiptSha256'>,
185
+ ): string => plugins.crypto
186
+ .createHash('sha256')
187
+ .update(receiptDigestDomain, 'utf8')
188
+ .update(JSON.stringify(receiptArg), 'utf8')
189
+ .digest('hex');
190
+
191
+ const isCanonicalU64Decimal = (valueArg: unknown): valueArg is string =>
192
+ typeof valueArg === 'string'
193
+ && /^(?:0|[1-9][0-9]{0,19})$/.test(valueArg)
194
+ && (valueArg.length < 20 || valueArg <= maximumU64Decimal);
195
+
196
+ const isLowercaseSha256 = (valueArg: unknown): valueArg is string =>
197
+ typeof valueArg === 'string' && /^[0-9a-f]{64}$/.test(valueArg);
198
+
199
+ export const normalizeLocalNoSqlDbStoppedStorageRootRelocationReceipt = (
200
+ valueArg: unknown,
201
+ inputArg: ILocalNoSqlDbStoppedStorageRootRelocationInput,
202
+ ): ILocalNoSqlDbStoppedStorageRootRelocationReceipt => {
203
+ if (!isPlainExactDataObject(valueArg, relocationReceiptKeys)) {
204
+ throw relocationError('RECOVERY_REQUIRED');
205
+ }
206
+ const receipt = valueArg as unknown as ILocalNoSqlDbStoppedStorageRootRelocationReceipt;
207
+ if (
208
+ receipt.format !== 'smartdb.storage-root-relocation.receipt.v1'
209
+ || receipt.version !== 1
210
+ || receipt.relocationId !== inputArg.relocationId
211
+ || receipt.sourceFolderPath !== inputArg.sourceFolderPath
212
+ || receipt.destinationFolderPath !== inputArg.destinationFolderPath
213
+ || !isLowercaseSha256(receipt.providerRootId)
214
+ || !isCanonicalU64Decimal(receipt.storageRootDevice)
215
+ || !isCanonicalU64Decimal(receipt.storageRootInode)
216
+ || !isLowercaseSha256(receipt.receiptSha256)
217
+ || receipt.sourceReceiptRetained !== true
218
+ ) {
219
+ throw relocationError('RECOVERY_REQUIRED');
220
+ }
221
+ const withoutDigest = {
222
+ format: receipt.format,
223
+ version: receipt.version,
224
+ relocationId: receipt.relocationId,
225
+ sourceFolderPath: receipt.sourceFolderPath,
226
+ destinationFolderPath: receipt.destinationFolderPath,
227
+ providerRootId: receipt.providerRootId,
228
+ storageRootDevice: receipt.storageRootDevice,
229
+ storageRootInode: receipt.storageRootInode,
230
+ sourceReceiptRetained: receipt.sourceReceiptRetained,
231
+ } satisfies Omit<ILocalNoSqlDbStoppedStorageRootRelocationReceipt, 'receiptSha256'>;
232
+ if (receiptDigest(withoutDigest) !== receipt.receiptSha256) {
233
+ throw relocationError('RECOVERY_REQUIRED');
234
+ }
235
+ return { ...withoutDigest, receiptSha256: receipt.receiptSha256 };
236
+ };
237
+
238
+ export const assertNoLocalNoSqlDbStorageRootRelocationWorkspace = async (
239
+ storagePathArg: string,
240
+ ): Promise<void> => {
241
+ const storagePath = plugins.path.resolve(storagePathArg);
242
+ const internalPath = plugins.path.join(storagePath, '.__rustdb_internal');
243
+ const workspacePath = plugins.path.join(internalPath, 'storage-root-relocation');
244
+ try {
245
+ const storage = await plugins.fs.stat(storagePath);
246
+ if (!storage.isDirectory()) {
247
+ throw new Error('not a directory');
248
+ }
249
+ } catch (error) {
250
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return;
251
+ throw new Error('NoSQLDB storage-root relocation workspace inspection is ambiguous');
252
+ }
253
+ try {
254
+ const internal = await plugins.fs.lstat(internalPath);
255
+ if (internal.isSymbolicLink() || !internal.isDirectory()) {
256
+ throw new Error('not a safe directory');
257
+ }
258
+ } catch (error) {
259
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return;
260
+ throw new Error('NoSQLDB storage-root relocation workspace inspection is ambiguous');
261
+ }
262
+ try {
263
+ await plugins.fs.lstat(workspacePath);
264
+ } catch (error) {
265
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return;
266
+ throw new Error('NoSQLDB storage-root relocation workspace inspection is ambiguous');
267
+ }
268
+ throw new Error('NoSQLDB storage-root relocation recovery must complete before startup');
269
+ };
270
+
271
+ export const isLocalNoSqlDbStorageRootRelocationErrorCode = (
272
+ valueArg: unknown,
273
+ ): valueArg is TLocalNoSqlDbStorageRootRelocationErrorCode =>
274
+ typeof valueArg === 'string'
275
+ && localNoSqlDbStorageRootRelocationErrorCodes.includes(
276
+ valueArg as TLocalNoSqlDbStorageRootRelocationErrorCode,
277
+ );