@bazariodev/docket 0.0.0-stage → 1.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 (96) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/LICENSE +21 -0
  3. package/README.md +985 -2
  4. package/dist/browser/constants.d.cts +14 -0
  5. package/dist/browser/constants.d.ts +14 -0
  6. package/dist/browser/index.cjs +192 -0
  7. package/dist/browser/index.cjs.map +1 -0
  8. package/dist/browser/index.d.cts +29 -0
  9. package/dist/browser/index.d.ts +29 -0
  10. package/dist/browser/index.js +187 -0
  11. package/dist/browser/index.js.map +1 -0
  12. package/dist/chunk-7ld72rnl.js +376 -0
  13. package/dist/chunk-7ld72rnl.js.map +1 -0
  14. package/dist/chunk-BLf-eCDO.cjs +53 -0
  15. package/dist/chunk-BLf-eCDO.cjs.map +1 -0
  16. package/dist/chunk-CEhpwtwJ.cjs +379 -0
  17. package/dist/chunk-CEhpwtwJ.cjs.map +1 -0
  18. package/dist/chunk-CSS3f4_M.js +46 -0
  19. package/dist/chunk-CSS3f4_M.js.map +1 -0
  20. package/dist/chunk-CXZYNALm.cjs +124 -0
  21. package/dist/chunk-CXZYNALm.cjs.map +1 -0
  22. package/dist/chunk-DYcNnkOV.js +50 -0
  23. package/dist/chunk-DYcNnkOV.js.map +1 -0
  24. package/dist/chunk-DkvWLziD.js +437 -0
  25. package/dist/chunk-DkvWLziD.js.map +1 -0
  26. package/dist/chunk-DqK_3eFr.cjs +53 -0
  27. package/dist/chunk-DqK_3eFr.cjs.map +1 -0
  28. package/dist/chunk-LRCHwVuE.js +110 -0
  29. package/dist/chunk-LRCHwVuE.js.map +1 -0
  30. package/dist/chunk-ieB8yTEn.cjs +439 -0
  31. package/dist/chunk-ieB8yTEn.cjs.map +1 -0
  32. package/dist/client/index.cjs +167 -0
  33. package/dist/client/index.cjs.map +1 -0
  34. package/dist/client/index.d.cts +40 -0
  35. package/dist/client/index.d.ts +40 -0
  36. package/dist/client/index.js +165 -0
  37. package/dist/client/index.js.map +1 -0
  38. package/dist/constants.d.cts +4 -0
  39. package/dist/constants.d.ts +4 -0
  40. package/dist/core/constants.d.cts +43 -0
  41. package/dist/core/constants.d.ts +43 -0
  42. package/dist/devtools/index.cjs +37 -0
  43. package/dist/devtools/index.cjs.map +1 -0
  44. package/dist/devtools/index.d.cts +11 -0
  45. package/dist/devtools/index.d.ts +11 -0
  46. package/dist/devtools/index.js +35 -0
  47. package/dist/devtools/index.js.map +1 -0
  48. package/dist/export/index.cjs +139 -0
  49. package/dist/export/index.cjs.map +1 -0
  50. package/dist/export/index.d.cts +49 -0
  51. package/dist/export/index.d.ts +49 -0
  52. package/dist/export/index.js +137 -0
  53. package/dist/export/index.js.map +1 -0
  54. package/dist/history/index.cjs +30 -0
  55. package/dist/history/index.cjs.map +1 -0
  56. package/dist/history/index.d.cts +11 -0
  57. package/dist/history/index.d.ts +11 -0
  58. package/dist/history/index.js +28 -0
  59. package/dist/history/index.js.map +1 -0
  60. package/dist/index.cjs +14 -0
  61. package/dist/index.cjs.map +1 -0
  62. package/dist/index.d.cts +159 -0
  63. package/dist/index.d.ts +159 -0
  64. package/dist/index.js +6 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/indexeddb/index.cjs +26 -0
  67. package/dist/indexeddb/index.cjs.map +1 -0
  68. package/dist/indexeddb/index.d.cts +61 -0
  69. package/dist/indexeddb/index.d.ts +61 -0
  70. package/dist/indexeddb/index.js +23 -0
  71. package/dist/indexeddb/index.js.map +1 -0
  72. package/dist/redaction/index.cjs +154 -0
  73. package/dist/redaction/index.cjs.map +1 -0
  74. package/dist/redaction/index.d.cts +70 -0
  75. package/dist/redaction/index.d.ts +70 -0
  76. package/dist/redaction/index.js +152 -0
  77. package/dist/redaction/index.js.map +1 -0
  78. package/dist/sip/index.cjs +336 -0
  79. package/dist/sip/index.cjs.map +1 -0
  80. package/dist/sip/index.d.cts +34 -0
  81. package/dist/sip/index.d.ts +34 -0
  82. package/dist/sip/index.js +333 -0
  83. package/dist/sip/index.js.map +1 -0
  84. package/dist/storage/constants.d.cts +11 -0
  85. package/dist/storage/constants.d.ts +11 -0
  86. package/dist/storage/contracts.d.cts +31 -0
  87. package/dist/storage/contracts.d.ts +31 -0
  88. package/dist/upload/constants.d.cts +17 -0
  89. package/dist/upload/constants.d.ts +17 -0
  90. package/dist/upload/index.cjs +246 -0
  91. package/dist/upload/index.cjs.map +1 -0
  92. package/dist/upload/index.d.cts +51 -0
  93. package/dist/upload/index.d.ts +51 -0
  94. package/dist/upload/index.js +244 -0
  95. package/dist/upload/index.js.map +1 -0
  96. package/package.json +150 -3
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ var common = require('../chunk-CXZYNALm.cjs');
4
+ var conversion = require('../chunk-CEhpwtwJ.cjs');
5
+ var format = require('../chunk-DqK_3eFr.cjs');
6
+ require('../chunk-BLf-eCDO.cjs');
7
+
8
+ const EXPORT_LIMITS = /* @__PURE__ */ Object.freeze({
9
+ YIELD_RECORDS: 100,
10
+ ENCODING_BUFFER_BYTES: 4096,
11
+ });
12
+ const EXPORT_ERRORS = /* @__PURE__ */ Object.freeze({
13
+ INPUT_LIMIT: 'ZIP input limit exceeded',
14
+ });
15
+
16
+ async function createLogBundle(options, archive) {
17
+ if (
18
+ !archive ||
19
+ typeof archive.balingZip !== 'function' ||
20
+ typeof archive.validateFileNames !== 'function' ||
21
+ typeof archive.validateZipOptions !== 'function'
22
+ )
23
+ throw new TypeError('Archive capabilities are required');
24
+ const {
25
+ source,
26
+ redactor,
27
+ files,
28
+ from,
29
+ to,
30
+ now = Date.now,
31
+ scheduler = common.scheduler,
32
+ } = options;
33
+ const maxInputSize = archive.validateZipOptions(options);
34
+ common.validateQuery({ from, to });
35
+ if (!Array.isArray(files))
36
+ throw new TypeError('Bundle files must be an array');
37
+ for (const file of files) {
38
+ if (!file || !Array.isArray(file.areas))
39
+ throw new TypeError('Bundle file areas must be an array');
40
+ common.validateQuery({ areas: file.areas });
41
+ }
42
+ archive.validateFileNames([
43
+ 'manifest.json',
44
+ ...files.map(({ name }) => name),
45
+ ]);
46
+ const fileName =
47
+ options.fileName ??
48
+ `logs-${new Date(now()).toISOString().replaceAll(':', '-')}.zip`;
49
+ archive.validateFileNames([fileName]);
50
+ const areas = Array.from(new Set(files.flatMap((file) => file.areas)));
51
+ const records = await source.query({ areas, from, to });
52
+ const status = source.getStatus?.();
53
+ const contents = [];
54
+ const summaries = [];
55
+ const warnings = [];
56
+ const encoder = new TextEncoder();
57
+ const buffer = new Uint8Array(EXPORT_LIMITS.ENCODING_BUFFER_BYTES);
58
+ let remainingBytes = maxInputSize;
59
+
60
+ function chargeText(text) {
61
+ if (text.length > remainingBytes)
62
+ throw new RangeError(EXPORT_ERRORS.INPUT_LIMIT);
63
+ let offset = 0;
64
+ while (offset < text.length) {
65
+ const { read, written } = encoder.encodeInto(text.slice(offset), buffer);
66
+ if (written > remainingBytes)
67
+ throw new RangeError(EXPORT_ERRORS.INPUT_LIMIT);
68
+ remainingBytes -= written;
69
+ offset += read;
70
+ }
71
+ }
72
+
73
+ for (const file of files) {
74
+ const selected = records.filter((record) =>
75
+ file.areas.includes(record.area),
76
+ );
77
+ summaries.push({ name: file.name, records: selected.length });
78
+ if (!selected.length) continue;
79
+ let content;
80
+ if (file.render) {
81
+ const result = file.render(selected);
82
+ content = typeof result === 'string' ? result : result?.content;
83
+ if (typeof content !== 'string' || result?.then)
84
+ throw new TypeError('Bundle renderers must return text synchronously');
85
+ chargeText(content);
86
+ for (const warning of result?.warnings ?? []) {
87
+ if (warnings.length >= redactor.limits.maxArrayLength) break;
88
+ if (typeof warning !== 'string')
89
+ throw new TypeError('Renderer warnings must be strings');
90
+ warnings.push(conversion.ownJson(redactor.redactText(warning), redactor.limits));
91
+ }
92
+ } else {
93
+ const lines = [];
94
+ for (let index = 0; index < selected.length; index++) {
95
+ const line = `${format.formatRecord(selected[index])}\n`;
96
+ chargeText(line);
97
+ lines.push(line);
98
+ if ((index + 1) % EXPORT_LIMITS.YIELD_RECORDS === 0)
99
+ await new Promise((resolve) => scheduler.setTimeout(resolve, 0));
100
+ }
101
+ content = lines.join('');
102
+ }
103
+ contents.push({ name: file.name, content });
104
+ }
105
+ let earliest = null;
106
+ let latest = null;
107
+ for (const record of records) {
108
+ earliest = earliest === null ? record.at : Math.min(earliest, record.at);
109
+ latest = latest === null ? record.at : Math.max(latest, record.at);
110
+ }
111
+ const manifest = {
112
+ schemaVersion: 1,
113
+ builtAt: new Date(now()).toISOString(),
114
+ requestedRange: { from: from ?? null, to: to ?? null },
115
+ actualRange: { from: earliest, to: latest },
116
+ files: summaries,
117
+ truncatedRecords: records.filter((record) => record.truncated).length,
118
+ warnings,
119
+ ...(status ? { store: status } : {}),
120
+ redactionVersions: Array.from(
121
+ new Set(records.map((record) => record.redactionVersion)),
122
+ ),
123
+ application: conversion.ownJson(
124
+ redactor.redactValue(options.manifest ?? {}),
125
+ redactor.limits,
126
+ ),
127
+ };
128
+ const manifestText = JSON.stringify(manifest, null, 2);
129
+ chargeText(manifestText);
130
+ contents.push({ name: 'manifest.json', content: manifestText });
131
+ return Object.freeze({
132
+ blob: await archive.balingZip(contents, { maxInputSize }),
133
+ fileName,
134
+ files: Object.freeze(summaries.map(Object.freeze)),
135
+ });
136
+ }
137
+
138
+ exports.createLogBundle = createLogBundle;
139
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/export/index.js"],"sourcesContent":["import { scheduler as hostScheduler, validateQuery } from '../core/common.js';\nimport { ownJson } from '../core/conversion.js';\nimport { formatRecord } from '../core/format.js';\n\nconst EXPORT_LIMITS = /* @__PURE__ */ Object.freeze({\n YIELD_RECORDS: 100,\n ENCODING_BUFFER_BYTES: 4096,\n});\nconst EXPORT_ERRORS = /* @__PURE__ */ Object.freeze({\n INPUT_LIMIT: 'ZIP input limit exceeded',\n});\n\nexport async function createLogBundle(options, archive) {\n if (\n !archive ||\n typeof archive.balingZip !== 'function' ||\n typeof archive.validateFileNames !== 'function' ||\n typeof archive.validateZipOptions !== 'function'\n )\n throw new TypeError('Archive capabilities are required');\n const {\n source,\n redactor,\n files,\n from,\n to,\n now = Date.now,\n scheduler = hostScheduler,\n } = options;\n const maxInputSize = archive.validateZipOptions(options);\n validateQuery({ from, to });\n if (!Array.isArray(files))\n throw new TypeError('Bundle files must be an array');\n for (const file of files) {\n if (!file || !Array.isArray(file.areas))\n throw new TypeError('Bundle file areas must be an array');\n validateQuery({ areas: file.areas });\n }\n archive.validateFileNames([\n 'manifest.json',\n ...files.map(({ name }) => name),\n ]);\n const fileName =\n options.fileName ??\n `logs-${new Date(now()).toISOString().replaceAll(':', '-')}.zip`;\n archive.validateFileNames([fileName]);\n const areas = Array.from(new Set(files.flatMap((file) => file.areas)));\n const records = await source.query({ areas, from, to });\n const status = source.getStatus?.();\n const contents = [];\n const summaries = [];\n const warnings = [];\n const encoder = new TextEncoder();\n const buffer = new Uint8Array(EXPORT_LIMITS.ENCODING_BUFFER_BYTES);\n let remainingBytes = maxInputSize;\n\n function chargeText(text) {\n if (text.length > remainingBytes)\n throw new RangeError(EXPORT_ERRORS.INPUT_LIMIT);\n let offset = 0;\n while (offset < text.length) {\n const { read, written } = encoder.encodeInto(text.slice(offset), buffer);\n if (written > remainingBytes)\n throw new RangeError(EXPORT_ERRORS.INPUT_LIMIT);\n remainingBytes -= written;\n offset += read;\n }\n }\n\n for (const file of files) {\n const selected = records.filter((record) =>\n file.areas.includes(record.area),\n );\n summaries.push({ name: file.name, records: selected.length });\n if (!selected.length) continue;\n let content;\n if (file.render) {\n const result = file.render(selected);\n content = typeof result === 'string' ? result : result?.content;\n if (typeof content !== 'string' || result?.then)\n throw new TypeError('Bundle renderers must return text synchronously');\n chargeText(content);\n for (const warning of result?.warnings ?? []) {\n if (warnings.length >= redactor.limits.maxArrayLength) break;\n if (typeof warning !== 'string')\n throw new TypeError('Renderer warnings must be strings');\n warnings.push(ownJson(redactor.redactText(warning), redactor.limits));\n }\n } else {\n const lines = [];\n for (let index = 0; index < selected.length; index++) {\n const line = `${formatRecord(selected[index])}\\n`;\n chargeText(line);\n lines.push(line);\n if ((index + 1) % EXPORT_LIMITS.YIELD_RECORDS === 0)\n await new Promise((resolve) => scheduler.setTimeout(resolve, 0));\n }\n content = lines.join('');\n }\n contents.push({ name: file.name, content });\n }\n let earliest = null;\n let latest = null;\n for (const record of records) {\n earliest = earliest === null ? record.at : Math.min(earliest, record.at);\n latest = latest === null ? record.at : Math.max(latest, record.at);\n }\n const manifest = {\n schemaVersion: 1,\n builtAt: new Date(now()).toISOString(),\n requestedRange: { from: from ?? null, to: to ?? null },\n actualRange: { from: earliest, to: latest },\n files: summaries,\n truncatedRecords: records.filter((record) => record.truncated).length,\n warnings,\n ...(status ? { store: status } : {}),\n redactionVersions: Array.from(\n new Set(records.map((record) => record.redactionVersion)),\n ),\n application: ownJson(\n redactor.redactValue(options.manifest ?? {}),\n redactor.limits,\n ),\n };\n const manifestText = JSON.stringify(manifest, null, 2);\n chargeText(manifestText);\n contents.push({ name: 'manifest.json', content: manifestText });\n return Object.freeze({\n blob: await archive.balingZip(contents, { maxInputSize }),\n fileName,\n files: Object.freeze(summaries.map(Object.freeze)),\n });\n}\n"],"names":["hostScheduler","validateQuery","ownJson","formatRecord"],"mappings":";;;;;;;AAIA,MAAM,aAAa,mBAAmB,MAAM,CAAC,MAAM,CAAC;AACpD,EAAE,aAAa,EAAE,GAAG;AACpB,EAAE,qBAAqB,EAAE,IAAI;AAC7B,CAAC,CAAC;AACF,MAAM,aAAa,mBAAmB,MAAM,CAAC,MAAM,CAAC;AACpD,EAAE,WAAW,EAAE,0BAA0B;AACzC,CAAC,CAAC;;AAEK,eAAe,eAAe,CAAC,OAAO,EAAE,OAAO,EAAE;AACxD,EAAE;AACF,IAAI,CAAC,OAAO;AACZ,IAAI,OAAO,OAAO,CAAC,SAAS,KAAK,UAAU;AAC3C,IAAI,OAAO,OAAO,CAAC,iB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+ LogSource,
6
+ LogValue,
7
+ Redactor,
8
+ } from "../index.cjs";
9
+
10
+ export type BundleRenderResult =
11
+ | string
12
+ | Readonly<{ content: string; warnings?: readonly string[] }>;
13
+ export type BundleFile<TArea extends string = string> = Readonly<{
14
+ name: string;
15
+ areas: readonly TArea[];
16
+ render?: (records: readonly LogRecord[]) => BundleRenderResult;
17
+ }>;
18
+ export type CreateLogBundleOptions<TArea extends string = string> = Readonly<{
19
+ source: Readonly<{
20
+ query: (query: LogQuery) => Promise<readonly LogRecord[]>;
21
+ getStatus?: LogSource['getStatus'];
22
+ }>;
23
+ redactor: Redactor;
24
+ files: readonly BundleFile<TArea>[];
25
+ from?: number;
26
+ to?: number;
27
+ manifest?: Readonly<Record<string, LogValue>>;
28
+ fileName?: string;
29
+ maxInputSize?: number;
30
+ scheduler?: LoggingScheduler;
31
+ now?: () => number;
32
+ }>;
33
+ export type LogBundle = Readonly<{
34
+ blob: Blob;
35
+ fileName: string;
36
+ files: readonly Readonly<{ name: string; records: number }>[];
37
+ }>;
38
+ export type ArchiveCapabilities = Readonly<{
39
+ balingZip: (
40
+ files: readonly Readonly<{ name: string; content: string }>[],
41
+ options: Readonly<{ maxInputSize: number }>,
42
+ ) => Promise<Blob>;
43
+ validateFileNames: (names: readonly string[]) => void;
44
+ validateZipOptions: (options: CreateLogBundleOptions) => number;
45
+ }>;
46
+ export declare function createLogBundle<TArea extends string>(
47
+ options: CreateLogBundleOptions<TArea>,
48
+ archive: ArchiveCapabilities,
49
+ ): Promise<LogBundle>;
@@ -0,0 +1,49 @@
1
+ import type {
2
+ LoggingScheduler,
3
+ LogQuery,
4
+ LogRecord,
5
+ LogSource,
6
+ LogValue,
7
+ Redactor,
8
+ } from '../index.js';
9
+
10
+ export type BundleRenderResult =
11
+ | string
12
+ | Readonly<{ content: string; warnings?: readonly string[] }>;
13
+ export type BundleFile<TArea extends string = string> = Readonly<{
14
+ name: string;
15
+ areas: readonly TArea[];
16
+ render?: (records: readonly LogRecord[]) => BundleRenderResult;
17
+ }>;
18
+ export type CreateLogBundleOptions<TArea extends string = string> = Readonly<{
19
+ source: Readonly<{
20
+ query: (query: LogQuery) => Promise<readonly LogRecord[]>;
21
+ getStatus?: LogSource['getStatus'];
22
+ }>;
23
+ redactor: Redactor;
24
+ files: readonly BundleFile<TArea>[];
25
+ from?: number;
26
+ to?: number;
27
+ manifest?: Readonly<Record<string, LogValue>>;
28
+ fileName?: string;
29
+ maxInputSize?: number;
30
+ scheduler?: LoggingScheduler;
31
+ now?: () => number;
32
+ }>;
33
+ export type LogBundle = Readonly<{
34
+ blob: Blob;
35
+ fileName: string;
36
+ files: readonly Readonly<{ name: string; records: number }>[];
37
+ }>;
38
+ export type ArchiveCapabilities = Readonly<{
39
+ balingZip: (
40
+ files: readonly Readonly<{ name: string; content: string }>[],
41
+ options: Readonly<{ maxInputSize: number }>,
42
+ ) => Promise<Blob>;
43
+ validateFileNames: (names: readonly string[]) => void;
44
+ validateZipOptions: (options: CreateLogBundleOptions) => number;
45
+ }>;
46
+ export declare function createLogBundle<TArea extends string>(
47
+ options: CreateLogBundleOptions<TArea>,
48
+ archive: ArchiveCapabilities,
49
+ ): Promise<LogBundle>;
@@ -0,0 +1,137 @@
1
+ import { s as scheduler, v as validateQuery } from '../chunk-LRCHwVuE.js';
2
+ import { o as ownJson } from '../chunk-7ld72rnl.js';
3
+ import { f as formatRecord } from '../chunk-DYcNnkOV.js';
4
+ import '../chunk-CSS3f4_M.js';
5
+
6
+ const EXPORT_LIMITS = /* @__PURE__ */ Object.freeze({
7
+ YIELD_RECORDS: 100,
8
+ ENCODING_BUFFER_BYTES: 4096,
9
+ });
10
+ const EXPORT_ERRORS = /* @__PURE__ */ Object.freeze({
11
+ INPUT_LIMIT: 'ZIP input limit exceeded',
12
+ });
13
+
14
+ async function createLogBundle(options, archive) {
15
+ if (
16
+ !archive ||
17
+ typeof archive.balingZip !== 'function' ||
18
+ typeof archive.validateFileNames !== 'function' ||
19
+ typeof archive.validateZipOptions !== 'function'
20
+ )
21
+ throw new TypeError('Archive capabilities are required');
22
+ const {
23
+ source,
24
+ redactor,
25
+ files,
26
+ from,
27
+ to,
28
+ now = Date.now,
29
+ scheduler: scheduler$1 = scheduler,
30
+ } = options;
31
+ const maxInputSize = archive.validateZipOptions(options);
32
+ validateQuery({ from, to });
33
+ if (!Array.isArray(files))
34
+ throw new TypeError('Bundle files must be an array');
35
+ for (const file of files) {
36
+ if (!file || !Array.isArray(file.areas))
37
+ throw new TypeError('Bundle file areas must be an array');
38
+ validateQuery({ areas: file.areas });
39
+ }
40
+ archive.validateFileNames([
41
+ 'manifest.json',
42
+ ...files.map(({ name }) => name),
43
+ ]);
44
+ const fileName =
45
+ options.fileName ??
46
+ `logs-${new Date(now()).toISOString().replaceAll(':', '-')}.zip`;
47
+ archive.validateFileNames([fileName]);
48
+ const areas = Array.from(new Set(files.flatMap((file) => file.areas)));
49
+ const records = await source.query({ areas, from, to });
50
+ const status = source.getStatus?.();
51
+ const contents = [];
52
+ const summaries = [];
53
+ const warnings = [];
54
+ const encoder = new TextEncoder();
55
+ const buffer = new Uint8Array(EXPORT_LIMITS.ENCODING_BUFFER_BYTES);
56
+ let remainingBytes = maxInputSize;
57
+
58
+ function chargeText(text) {
59
+ if (text.length > remainingBytes)
60
+ throw new RangeError(EXPORT_ERRORS.INPUT_LIMIT);
61
+ let offset = 0;
62
+ while (offset < text.length) {
63
+ const { read, written } = encoder.encodeInto(text.slice(offset), buffer);
64
+ if (written > remainingBytes)
65
+ throw new RangeError(EXPORT_ERRORS.INPUT_LIMIT);
66
+ remainingBytes -= written;
67
+ offset += read;
68
+ }
69
+ }
70
+
71
+ for (const file of files) {
72
+ const selected = records.filter((record) =>
73
+ file.areas.includes(record.area),
74
+ );
75
+ summaries.push({ name: file.name, records: selected.length });
76
+ if (!selected.length) continue;
77
+ let content;
78
+ if (file.render) {
79
+ const result = file.render(selected);
80
+ content = typeof result === 'string' ? result : result?.content;
81
+ if (typeof content !== 'string' || result?.then)
82
+ throw new TypeError('Bundle renderers must return text synchronously');
83
+ chargeText(content);
84
+ for (const warning of result?.warnings ?? []) {
85
+ if (warnings.length >= redactor.limits.maxArrayLength) break;
86
+ if (typeof warning !== 'string')
87
+ throw new TypeError('Renderer warnings must be strings');
88
+ warnings.push(ownJson(redactor.redactText(warning), redactor.limits));
89
+ }
90
+ } else {
91
+ const lines = [];
92
+ for (let index = 0; index < selected.length; index++) {
93
+ const line = `${formatRecord(selected[index])}\n`;
94
+ chargeText(line);
95
+ lines.push(line);
96
+ if ((index + 1) % EXPORT_LIMITS.YIELD_RECORDS === 0)
97
+ await new Promise((resolve) => scheduler$1.setTimeout(resolve, 0));
98
+ }
99
+ content = lines.join('');
100
+ }
101
+ contents.push({ name: file.name, content });
102
+ }
103
+ let earliest = null;
104
+ let latest = null;
105
+ for (const record of records) {
106
+ earliest = earliest === null ? record.at : Math.min(earliest, record.at);
107
+ latest = latest === null ? record.at : Math.max(latest, record.at);
108
+ }
109
+ const manifest = {
110
+ schemaVersion: 1,
111
+ builtAt: new Date(now()).toISOString(),
112
+ requestedRange: { from: from ?? null, to: to ?? null },
113
+ actualRange: { from: earliest, to: latest },
114
+ files: summaries,
115
+ truncatedRecords: records.filter((record) => record.truncated).length,
116
+ warnings,
117
+ ...(status ? { store: status } : {}),
118
+ redactionVersions: Array.from(
119
+ new Set(records.map((record) => record.redactionVersion)),
120
+ ),
121
+ application: ownJson(
122
+ redactor.redactValue(options.manifest ?? {}),
123
+ redactor.limits,
124
+ ),
125
+ };
126
+ const manifestText = JSON.stringify(manifest, null, 2);
127
+ chargeText(manifestText);
128
+ contents.push({ name: 'manifest.json', content: manifestText });
129
+ return Object.freeze({
130
+ blob: await archive.balingZip(contents, { maxInputSize }),
131
+ fileName,
132
+ files: Object.freeze(summaries.map(Object.freeze)),
133
+ });
134
+ }
135
+
136
+ export { createLogBundle };
137
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/export/index.js"],"sourcesContent":["import { scheduler as hostScheduler, validateQuery } from '../core/common.js';\nimport { ownJson } from '../core/conversion.js';\nimport { formatRecord } from '../core/format.js';\n\nconst EXPORT_LIMITS = /* @__PURE__ */ Object.freeze({\n YIELD_RECORDS: 100,\n ENCODING_BUFFER_BYTES: 4096,\n});\nconst EXPORT_ERRORS = /* @__PURE__ */ Object.freeze({\n INPUT_LIMIT: 'ZIP input limit exceeded',\n});\n\nexport async function createLogBundle(options, archive) {\n if (\n !archive ||\n typeof archive.balingZip !== 'function' ||\n typeof archive.validateFileNames !== 'function' ||\n typeof archive.validateZipOptions !== 'function'\n )\n throw new TypeError('Archive capabilities are required');\n const {\n source,\n redactor,\n files,\n from,\n to,\n now = Date.now,\n scheduler = hostScheduler,\n } = options;\n const maxInputSize = archive.validateZipOptions(options);\n validateQuery({ from, to });\n if (!Array.isArray(files))\n throw new TypeError('Bundle files must be an array');\n for (const file of files) {\n if (!file || !Array.isArray(file.areas))\n throw new TypeError('Bundle file areas must be an array');\n validateQuery({ areas: file.areas });\n }\n archive.validateFileNames([\n 'manifest.json',\n ...files.map(({ name }) => name),\n ]);\n const fileName =\n options.fileName ??\n `logs-${new Date(now()).toISOString().replaceAll(':', '-')}.zip`;\n archive.validateFileNames([fileName]);\n const areas = Array.from(new Set(files.flatMap((file) => file.areas)));\n const records = await source.query({ areas, from, to });\n const status = source.getStatus?.();\n const contents = [];\n const summaries = [];\n const warnings = [];\n const encoder = new TextEncoder();\n const buffer = new Uint8Array(EXPORT_LIMITS.ENCODING_BUFFER_BYTES);\n let remainingBytes = maxInputSize;\n\n function chargeText(text) {\n if (text.length > remainingBytes)\n throw new RangeError(EXPORT_ERRORS.INPUT_LIMIT);\n let offset = 0;\n while (offset < text.length) {\n const { read, written } = encoder.encodeInto(text.slice(offset), buffer);\n if (written > remainingBytes)\n throw new RangeError(EXPORT_ERRORS.INPUT_LIMIT);\n remainingBytes -= written;\n offset += read;\n }\n }\n\n for (const file of files) {\n const selected = records.filter((record) =>\n file.areas.includes(record.area),\n );\n summaries.push({ name: file.name, records: selected.length });\n if (!selected.length) continue;\n let content;\n if (file.render) {\n const result = file.render(selected);\n content = typeof result === 'string' ? result : result?.content;\n if (typeof content !== 'string' || result?.then)\n throw new TypeError('Bundle renderers must return text synchronously');\n chargeText(content);\n for (const warning of result?.warnings ?? []) {\n if (warnings.length >= redactor.limits.maxArrayLength) break;\n if (typeof warning !== 'string')\n throw new TypeError('Renderer warnings must be strings');\n warnings.push(ownJson(redactor.redactText(warning), redactor.limits));\n }\n } else {\n const lines = [];\n for (let index = 0; index < selected.length; index++) {\n const line = `${formatRecord(selected[index])}\\n`;\n chargeText(line);\n lines.push(line);\n if ((index + 1) % EXPORT_LIMITS.YIELD_RECORDS === 0)\n await new Promise((resolve) => scheduler.setTimeout(resolve, 0));\n }\n content = lines.join('');\n }\n contents.push({ name: file.name, content });\n }\n let earliest = null;\n let latest = null;\n for (const record of records) {\n earliest = earliest === null ? record.at : Math.min(earliest, record.at);\n latest = latest === null ? record.at : Math.max(latest, record.at);\n }\n const manifest = {\n schemaVersion: 1,\n builtAt: new Date(now()).toISOString(),\n requestedRange: { from: from ?? null, to: to ?? null },\n actualRange: { from: earliest, to: latest },\n files: summaries,\n truncatedRecords: records.filter((record) => record.truncated).length,\n warnings,\n ...(status ? { store: status } : {}),\n redactionVersions: Array.from(\n new Set(records.map((record) => record.redactionVersion)),\n ),\n application: ownJson(\n redactor.redactValue(options.manifest ?? {}),\n redactor.limits,\n ),\n };\n const manifestText = JSON.stringify(manifest, null, 2);\n chargeText(manifestText);\n contents.push({ name: 'manifest.json', content: manifestText });\n return Object.freeze({\n blob: await archive.balingZip(contents, { maxInputSize }),\n fileName,\n files: Object.freeze(summaries.map(Object.freeze)),\n });\n}\n"],"names":["scheduler","hostScheduler"],"mappings":";;;;;AAIA,MAAM,aAAa,mBAAmB,MAAM,CAAC,MAAM,CAAC;AACpD,EAAE,aAAa,EAAE,GAAG;AACpB,EAAE,qBAAqB,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,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,YAAY,EAAE,CAAC;AAC7D,IAAI,QAAQ;AACZ,IAAI,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtD,GAAG,CAAC;AACJ;;"}
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ var coordination = require('@bazariodev/coordination');
4
+ var common = require('../chunk-CXZYNALm.cjs');
5
+ require('../chunk-BLf-eCDO.cjs');
6
+
7
+ function createMemoryHistory(options) {
8
+ if (!options || typeof options !== 'object' || Array.isArray(options))
9
+ throw new TypeError('Memory history options are required');
10
+ const { maxRecords } = options;
11
+ if (maxRecords === undefined) throw new TypeError('maxRecords is required');
12
+ if (Reflect.ownKeys(options).some((key) => key !== 'maxRecords'))
13
+ throw new TypeError('Only maxRecords is supported for memory history');
14
+ common.positive(maxRecords, 'maxRecords');
15
+ const queue = new coordination.Queue();
16
+ return Object.freeze({
17
+ write(record) {
18
+ if (queue.size === maxRecords) queue.dequeue();
19
+ queue.enqueue(record);
20
+ },
21
+ async query(query) {
22
+ const matches = common.validateQuery(query);
23
+ return queue.toArray().filter(matches);
24
+ },
25
+ clear: () => queue.clear(),
26
+ });
27
+ }
28
+
29
+ exports.createMemoryHistory = createMemoryHistory;
30
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/history/index.js"],"sourcesContent":["import { Queue } from '@bazariodev/coordination';\nimport { positive, validateQuery } from '../core/common.js';\n\nexport function createMemoryHistory(options) {\n if (!options || typeof options !== 'object' || Array.isArray(options))\n throw new TypeError('Memory history options are required');\n const { maxRecords } = options;\n if (maxRecords === undefined) throw new TypeError('maxRecords is required');\n if (Reflect.ownKeys(options).some((key) => key !== 'maxRecords'))\n throw new TypeError('Only maxRecords is supported for memory history');\n positive(maxRecords, 'maxRecords');\n const queue = new Queue();\n return Object.freeze({\n write(record) {\n if (queue.size === maxRecords) queue.dequeue();\n queue.enqueue(record);\n },\n async query(query) {\n const matches = validateQuery(query);\n return queue.toArray().filter(matches);\n },\n clear: () => queue.clear(),\n });\n}\n"],"names":["positive","Queue","validateQuery"],"mappings":";;;;;;AAGO,SAAS,mBAAmB,CAAC,OAAO,EAAE;AAC7C,EAAE,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;AACvE,IAAI,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC;AAC9D,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO;AAChC,EAAE,IAAI,UAAU,KAAK,SAAS,EAAE,MAAM,IAAI,SAAS,CAAC,wBAAwB,CAAC;AAC7E,EAAE,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,YAAY,CAAC;AAClE,IAAI,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC;AAC1E,EAAEA,eAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;AACpC,EAAE,MAAM,KAAK,GAAG,IAAIC,kBAAK,EAAE;AAC3B,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE;AACpD,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;AAC3B,IAAI,CAAC;AACL,IAAI,MAAM,KAAK,CAAC,KAAK,EAAE;AACvB,MAAM,MAAM,OAAO,GAAGC,oBAAa,CAAC,KAAK,CAAC;AAC1C,MAAM,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC;AAC5C,IAAI,CAAC;AACL,IAAI,KAAK,EAAE,MAAM,KAAK,CAAC,KAAK,EAAE;AAC9B,GAAG,CAAC;AACJ;;"}
@@ -0,0 +1,11 @@
1
+ import type { LogQuery, LogRecord } from "../index.cjs";
2
+
3
+ export type MemoryHistoryOptions = Readonly<{ maxRecords: number }>;
4
+ export type MemoryHistory = Readonly<{
5
+ write(record: LogRecord): void;
6
+ query(query?: LogQuery): Promise<readonly LogRecord[]>;
7
+ clear(): void;
8
+ }>;
9
+ export declare function createMemoryHistory(
10
+ options: MemoryHistoryOptions,
11
+ ): MemoryHistory;
@@ -0,0 +1,11 @@
1
+ import type { LogQuery, LogRecord } from '../index.js';
2
+
3
+ export type MemoryHistoryOptions = Readonly<{ maxRecords: number }>;
4
+ export type MemoryHistory = Readonly<{
5
+ write(record: LogRecord): void;
6
+ query(query?: LogQuery): Promise<readonly LogRecord[]>;
7
+ clear(): void;
8
+ }>;
9
+ export declare function createMemoryHistory(
10
+ options: MemoryHistoryOptions,
11
+ ): MemoryHistory;
@@ -0,0 +1,28 @@
1
+ import { Queue } from '@bazariodev/coordination';
2
+ import { p as positive, v as validateQuery } from '../chunk-LRCHwVuE.js';
3
+ import '../chunk-CSS3f4_M.js';
4
+
5
+ function createMemoryHistory(options) {
6
+ if (!options || typeof options !== 'object' || Array.isArray(options))
7
+ throw new TypeError('Memory history options are required');
8
+ const { maxRecords } = options;
9
+ if (maxRecords === undefined) throw new TypeError('maxRecords is required');
10
+ if (Reflect.ownKeys(options).some((key) => key !== 'maxRecords'))
11
+ throw new TypeError('Only maxRecords is supported for memory history');
12
+ positive(maxRecords, 'maxRecords');
13
+ const queue = new Queue();
14
+ return Object.freeze({
15
+ write(record) {
16
+ if (queue.size === maxRecords) queue.dequeue();
17
+ queue.enqueue(record);
18
+ },
19
+ async query(query) {
20
+ const matches = validateQuery(query);
21
+ return queue.toArray().filter(matches);
22
+ },
23
+ clear: () => queue.clear(),
24
+ });
25
+ }
26
+
27
+ export { createMemoryHistory };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/history/index.js"],"sourcesContent":["import { Queue } from '@bazariodev/coordination';\nimport { positive, validateQuery } from '../core/common.js';\n\nexport function createMemoryHistory(options) {\n if (!options || typeof options !== 'object' || Array.isArray(options))\n throw new TypeError('Memory history options are required');\n const { maxRecords } = options;\n if (maxRecords === undefined) throw new TypeError('maxRecords is required');\n if (Reflect.ownKeys(options).some((key) => key !== 'maxRecords'))\n throw new TypeError('Only maxRecords is supported for memory history');\n positive(maxRecords, 'maxRecords');\n const queue = new Queue();\n return Object.freeze({\n write(record) {\n if (queue.size === maxRecords) queue.dequeue();\n queue.enqueue(record);\n },\n async query(query) {\n const matches = validateQuery(query);\n return queue.toArray().filter(matches);\n },\n clear: () => queue.clear(),\n });\n}\n"],"names":[],"mappings":";;;;AAGO,SAAS,mBAAmB,CAAC,OAAO,EAAE;AAC7C,EAAE,IAAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;AACvE,IAAI,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC;AAC9D,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO;AAChC,EAAE,IAAI,UAAU,KAAK,SAAS,EAAE,MAAM,IAAI,SAAS,CAAC,wBAAwB,CAAC;AAC7E,EAAE,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,YAAY,CAAC;AAClE,IAAI,MAAM,IAAI,SAAS,CAAC,iDAAiD,CAAC;AAC1E,EAAE,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC;AACpC,EAAE,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE;AAC3B,EAAE,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,IAAI,KAAK,CAAC,MAAM,EAAE;AAClB,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE;AACpD,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;AAC3B,IAAI,CAAC;AACL,IAAI,MAAM,KAAK,CAAC,KAAK,EAAE;AACvB,MAAM,MAAM,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC;AAC1C,MAAM,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC;AAC5C,IAAI,CAAC;AACL,IAAI,KAAK,EAAE,MAAM,KAAK,CAAC,KAAK,EAAE;AAC9B,GAAG,CAAC;AACJ;;"}
package/dist/index.cjs ADDED
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var format = require('./chunk-DqK_3eFr.cjs');
4
+ var hub = require('./chunk-ieB8yTEn.cjs');
5
+ require('./chunk-CXZYNALm.cjs');
6
+ require('./chunk-BLf-eCDO.cjs');
7
+ require('./chunk-CEhpwtwJ.cjs');
8
+
9
+
10
+
11
+ exports.createConsoleSink = format.createConsoleSink;
12
+ exports.formatRecord = format.formatRecord;
13
+ exports.createLogging = hub.createLogging;
14
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}