@ucdjs/ucd-store 0.0.1 → 1.0.1-beta.2
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 +3 -0
- package/dist/context-DfX5D4Fb.mjs +201 -0
- package/dist/index.d.mts +747 -0
- package/dist/index.mjs +1356 -0
- package/package.json +36 -13
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -7
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[![npm version][npm-version-src]][npm-version-href]
|
|
4
4
|
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![codecov][codecov-src]][codecov-href]
|
|
5
6
|
|
|
6
7
|
A simple, lightweight store for managing Unicode Character Database Files.
|
|
7
8
|
|
|
@@ -19,3 +20,5 @@ Published under [MIT License](./LICENSE).
|
|
|
19
20
|
[npm-version-href]: https://npmjs.com/package/@ucdjs/ucd-store
|
|
20
21
|
[npm-downloads-src]: https://img.shields.io/npm/dm/@ucdjs/ucd-store?style=flat&colorA=18181B&colorB=4169E1
|
|
21
22
|
[npm-downloads-href]: https://npmjs.com/package/@ucdjs/ucd-store
|
|
23
|
+
[codecov-src]: https://img.shields.io/codecov/c/gh/ucdjs/ucd?style=flat&colorA=18181B&colorB=4169E1
|
|
24
|
+
[codecov-href]: https://codecov.io/gh/ucdjs/ucd
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { createDebugger } from "@ucdjs-internal/shared";
|
|
2
|
+
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __exportAll = (all, no_symbols) => {
|
|
6
|
+
let target = {};
|
|
7
|
+
for (var name in all) {
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (!no_symbols) {
|
|
14
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/errors.ts
|
|
21
|
+
var UCDStoreBaseError = class extends Error {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "UCDStoreBaseError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var UCDStoreGenericError = class extends UCDStoreBaseError {
|
|
28
|
+
data;
|
|
29
|
+
constructor(message, data) {
|
|
30
|
+
super(message);
|
|
31
|
+
this.name = "UCDStoreGenericError";
|
|
32
|
+
this.data = data;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var UCDStoreFileNotFoundError = class extends UCDStoreBaseError {
|
|
36
|
+
filePath;
|
|
37
|
+
version;
|
|
38
|
+
constructor(filePath, version) {
|
|
39
|
+
super(`File not found: ${filePath}${version ? ` in version ${version}` : ""}`);
|
|
40
|
+
this.name = "UCDStoreFileNotFoundError";
|
|
41
|
+
this.filePath = filePath;
|
|
42
|
+
this.version = version;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var UCDStoreVersionNotFoundError = class extends UCDStoreBaseError {
|
|
46
|
+
version;
|
|
47
|
+
constructor(version) {
|
|
48
|
+
super(`Version '${version}' does not exist in the store.`);
|
|
49
|
+
this.name = "UCDStoreVersionNotFoundError";
|
|
50
|
+
this.version = version;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var UCDStoreBridgeUnsupportedOperation = class extends UCDStoreBaseError {
|
|
54
|
+
operation;
|
|
55
|
+
requiredCapabilities;
|
|
56
|
+
availableCapabilities;
|
|
57
|
+
constructor(operation, requiredCapabilities, availableCapabilities) {
|
|
58
|
+
let message = `Operation "${operation}" is not supported.`;
|
|
59
|
+
if (requiredCapabilities.length > 0 || availableCapabilities.length > 0) message += ` Required capabilities: ${requiredCapabilities.join(", ")}. Available capabilities: ${availableCapabilities.join(", ")}`;
|
|
60
|
+
super(message);
|
|
61
|
+
this.name = "UCDStoreBridgeUnsupportedOperation";
|
|
62
|
+
this.operation = operation;
|
|
63
|
+
this.requiredCapabilities = requiredCapabilities;
|
|
64
|
+
this.availableCapabilities = availableCapabilities;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
var UCDStoreFilterError = class extends UCDStoreBaseError {
|
|
68
|
+
excludePattern = [];
|
|
69
|
+
includePattern = [];
|
|
70
|
+
filePath;
|
|
71
|
+
constructor(message, { excludePattern, includePattern, filePath }) {
|
|
72
|
+
super(message);
|
|
73
|
+
this.name = "UCDStoreFilterError";
|
|
74
|
+
this.excludePattern = excludePattern;
|
|
75
|
+
this.includePattern = includePattern;
|
|
76
|
+
this.filePath = filePath;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var UCDStoreApiFallbackError = class extends UCDStoreBaseError {
|
|
80
|
+
version;
|
|
81
|
+
filePath;
|
|
82
|
+
status;
|
|
83
|
+
reason;
|
|
84
|
+
constructor({ version, filePath, status, reason, message }) {
|
|
85
|
+
const defaultMessage = reason === "fetch-failed" ? `Failed to fetch file '${filePath}' from API${status ? ` (status: ${status})` : ""}` : `API returned no data for file '${filePath}'`;
|
|
86
|
+
super(message ?? defaultMessage);
|
|
87
|
+
this.name = "UCDStoreApiFallbackError";
|
|
88
|
+
this.version = version;
|
|
89
|
+
this.filePath = filePath;
|
|
90
|
+
this.status = status;
|
|
91
|
+
this.reason = reason;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/context.ts
|
|
97
|
+
var context_exports = /* @__PURE__ */ __exportAll({
|
|
98
|
+
createInternalContext: () => createInternalContext,
|
|
99
|
+
createPublicContext: () => createPublicContext,
|
|
100
|
+
extractFilterPatterns: () => extractFilterPatterns,
|
|
101
|
+
isUCDStoreInternalContext: () => isUCDStoreInternalContext
|
|
102
|
+
});
|
|
103
|
+
const debug = createDebugger("ucdjs:ucd-store:context");
|
|
104
|
+
/**
|
|
105
|
+
* Creates an internal store context object.
|
|
106
|
+
* This context is used internally by store methods and operations.
|
|
107
|
+
*
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
function createInternalContext(options) {
|
|
111
|
+
let apiVersionsCache = null;
|
|
112
|
+
return {
|
|
113
|
+
client: options.client,
|
|
114
|
+
filter: options.filter,
|
|
115
|
+
fs: options.fs,
|
|
116
|
+
lockfile: {
|
|
117
|
+
supports: options.lockfile.supports,
|
|
118
|
+
exists: options.lockfile.exists,
|
|
119
|
+
path: options.lockfile.path
|
|
120
|
+
},
|
|
121
|
+
versions: {
|
|
122
|
+
userProvided: Object.freeze([...options.versions.userProvided]),
|
|
123
|
+
configFile: Object.freeze([...options.versions.configFile]),
|
|
124
|
+
resolved: options.versions.resolved ? [...options.versions.resolved] : [],
|
|
125
|
+
async apiVersions() {
|
|
126
|
+
if (apiVersionsCache !== null) {
|
|
127
|
+
debug?.("Using cached API versions");
|
|
128
|
+
return apiVersionsCache;
|
|
129
|
+
}
|
|
130
|
+
debug?.("Fetching API versions");
|
|
131
|
+
const result = await options.client.versions.list();
|
|
132
|
+
if (result.error || !result.data) {
|
|
133
|
+
debug?.("Failed to fetch API versions:", result.error);
|
|
134
|
+
apiVersionsCache = Object.freeze([]);
|
|
135
|
+
return apiVersionsCache;
|
|
136
|
+
}
|
|
137
|
+
const versionStrings = result.data.map((v) => v.version);
|
|
138
|
+
apiVersionsCache = Object.freeze(versionStrings);
|
|
139
|
+
debug?.("Cached API versions:", apiVersionsCache);
|
|
140
|
+
return apiVersionsCache;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
async getExpectedFilePaths(version) {
|
|
144
|
+
debug?.("Fetching expected files for version:", version);
|
|
145
|
+
const result = await options.client.manifest.get(version);
|
|
146
|
+
if (result.error) throw new UCDStoreGenericError(`Failed to fetch expected files for version '${version}': ${result.error.message}`, {
|
|
147
|
+
version,
|
|
148
|
+
status: result.error.status
|
|
149
|
+
});
|
|
150
|
+
if (!result.data) throw new UCDStoreGenericError(`Failed to fetch expected files for version '${version}': empty response`, { version });
|
|
151
|
+
if (!Array.isArray(result.data.expectedFiles)) throw new UCDStoreGenericError(`Failed to fetch expected files for version '${version}': invalid response (missing expectedFiles)`, { version });
|
|
152
|
+
return result.data.expectedFiles;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function isUCDStoreInternalContext(obj) {
|
|
157
|
+
return !!obj && typeof obj === "object" && "versions" in obj && typeof obj.versions === "object" && obj.versions != null && "resolved" in obj.versions && Array.isArray(obj.versions?.resolved);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Extracts filter patterns from a PathFilter for storage in the lockfile.
|
|
161
|
+
*
|
|
162
|
+
* @param {PathFilter} filter - The path filter to extract patterns from
|
|
163
|
+
* @returns {PathFilterOptions | undefined} The filter options, or undefined if no filters are configured
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
function extractFilterPatterns(filter) {
|
|
167
|
+
const patterns = filter.patterns();
|
|
168
|
+
const hasInclude = patterns.include && patterns.include.length > 0;
|
|
169
|
+
const hasExclude = patterns.exclude && patterns.exclude.length > 0;
|
|
170
|
+
const hasDisableDefault = patterns.disableDefaultExclusions === true;
|
|
171
|
+
if (!hasInclude && !hasExclude && !hasDisableDefault) return;
|
|
172
|
+
function ensureArray(value) {
|
|
173
|
+
if (!value) return [];
|
|
174
|
+
return Array.isArray(value) ? value : [value];
|
|
175
|
+
}
|
|
176
|
+
debug?.(`Extracting filter patterns: include=${hasInclude}, exclude=${hasExclude}, disableDefaultExclusions=${hasDisableDefault}`);
|
|
177
|
+
return {
|
|
178
|
+
include: ensureArray(patterns.include),
|
|
179
|
+
exclude: ensureArray(patterns.exclude),
|
|
180
|
+
disableDefaultExclusions: patterns.disableDefaultExclusions
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Creates the public-facing context properties from internal context.
|
|
185
|
+
* This includes only the properties that should be exposed in the public API.
|
|
186
|
+
*
|
|
187
|
+
* @internal
|
|
188
|
+
*/
|
|
189
|
+
function createPublicContext(context) {
|
|
190
|
+
return {
|
|
191
|
+
get versions() {
|
|
192
|
+
return Object.freeze([...context.versions.resolved]);
|
|
193
|
+
},
|
|
194
|
+
get fs() {
|
|
195
|
+
return context.fs;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
//#endregion
|
|
201
|
+
export { isUCDStoreInternalContext as a, UCDStoreBridgeUnsupportedOperation as c, UCDStoreGenericError as d, UCDStoreVersionNotFoundError as f, extractFilterPatterns as i, UCDStoreFileNotFoundError as l, createInternalContext as n, UCDStoreApiFallbackError as o, createPublicContext as r, UCDStoreBaseError as s, context_exports as t, UCDStoreFilterError as u };
|