@wemush/wols 0.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/compact-url.js +64 -0
- package/dist/cjs/compact-url.js.map +1 -1
- package/dist/cjs/crypto/decrypt.js +16 -5
- package/dist/cjs/crypto/decrypt.js.map +1 -1
- package/dist/cjs/crypto/encrypt.js +111 -9
- package/dist/cjs/crypto/encrypt.js.map +1 -1
- package/dist/cjs/index.js +53 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/parser.js +3 -0
- package/dist/cjs/parser.js.map +1 -1
- package/dist/cjs/specimen.js +14 -1
- package/dist/cjs/specimen.js.map +1 -1
- package/dist/cjs/types.js +267 -3
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/utils/environment.js +206 -0
- package/dist/cjs/utils/environment.js.map +1 -0
- package/dist/cjs/utils/migration.js +248 -0
- package/dist/cjs/utils/migration.js.map +1 -0
- package/dist/cjs/validator.js +62 -9
- package/dist/cjs/validator.js.map +1 -1
- package/dist/esm/compact-url.js +62 -0
- package/dist/esm/compact-url.js.map +1 -1
- package/dist/esm/crypto/decrypt.js +16 -5
- package/dist/esm/crypto/decrypt.js.map +1 -1
- package/dist/esm/crypto/encrypt.js +111 -9
- package/dist/esm/crypto/encrypt.js.map +1 -1
- package/dist/esm/index.js +21 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/parser.js +3 -0
- package/dist/esm/parser.js.map +1 -1
- package/dist/esm/specimen.js +15 -2
- package/dist/esm/specimen.js.map +1 -1
- package/dist/esm/types.js +258 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils/environment.js +193 -0
- package/dist/esm/utils/environment.js.map +1 -0
- package/dist/esm/utils/migration.js +237 -0
- package/dist/esm/utils/migration.js.map +1 -0
- package/dist/esm/validator.js +62 -9
- package/dist/esm/validator.js.map +1 -1
- package/dist/types/compact-url.d.ts +46 -0
- package/dist/types/compact-url.d.ts.map +1 -1
- package/dist/types/crypto/decrypt.d.ts +6 -0
- package/dist/types/crypto/decrypt.d.ts.map +1 -1
- package/dist/types/crypto/encrypt.d.ts +56 -1
- package/dist/types/crypto/encrypt.d.ts.map +1 -1
- package/dist/types/index.d.ts +10 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/parser.d.ts.map +1 -1
- package/dist/types/specimen.d.ts.map +1 -1
- package/dist/types/types.d.ts +246 -5
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils/environment.d.ts +137 -0
- package/dist/types/utils/environment.d.ts.map +1 -0
- package/dist/types/utils/migration.d.ts +162 -0
- package/dist/types/utils/migration.d.ts.map +1 -0
- package/dist/types/validator.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/types.js
CHANGED
|
@@ -3,14 +3,22 @@
|
|
|
3
3
|
* WOLS TypeScript Library - Core Types
|
|
4
4
|
*
|
|
5
5
|
* This module defines all the core types, interfaces, and enums
|
|
6
|
-
* for the WeMush Open Labeling Standard (WOLS) v1.
|
|
6
|
+
* for the WeMush Open Labeling Standard (WOLS) v1.2.0.
|
|
7
7
|
*
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
* @module @wemush/wols
|
|
10
10
|
*/
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.GROWTH_STAGES = exports.SPECIMEN_TYPES = exports.WOLS_CONTEXT = exports.WOLS_VERSION = void 0;
|
|
12
|
+
exports.GROWTH_STAGES = exports.WOLS_TO_PLATFORM_MAP = exports.SPECIMEN_TYPES = exports.WOLS_CONTEXT = exports.WOLS_VERSION = void 0;
|
|
13
13
|
exports.asSpecimenId = asSpecimenId;
|
|
14
|
+
exports.registerTypeAlias = registerTypeAlias;
|
|
15
|
+
exports.resolveTypeAlias = resolveTypeAlias;
|
|
16
|
+
exports.getTypeAliases = getTypeAliases;
|
|
17
|
+
exports.mapToWolsType = mapToWolsType;
|
|
18
|
+
exports.mapFromWolsType = mapFromWolsType;
|
|
19
|
+
exports.registerPlatformType = registerPlatformType;
|
|
20
|
+
exports.normalizeGeneration = normalizeGeneration;
|
|
21
|
+
exports.isValidGeneration = isValidGeneration;
|
|
14
22
|
exports.isSpecimenType = isSpecimenType;
|
|
15
23
|
exports.isGrowthStage = isGrowthStage;
|
|
16
24
|
exports.isStrain = isStrain;
|
|
@@ -20,7 +28,7 @@ exports.isStrain = isStrain;
|
|
|
20
28
|
/**
|
|
21
29
|
* WOLS specification version implemented by this library.
|
|
22
30
|
*/
|
|
23
|
-
exports.WOLS_VERSION = '1.
|
|
31
|
+
exports.WOLS_VERSION = '1.2.0';
|
|
24
32
|
/**
|
|
25
33
|
* JSON-LD context URL for WOLS specimens.
|
|
26
34
|
*/
|
|
@@ -42,15 +50,271 @@ exports.SPECIMEN_TYPES = [
|
|
|
42
50
|
'FRUITING',
|
|
43
51
|
'HARVEST',
|
|
44
52
|
];
|
|
53
|
+
// =============================================================================
|
|
54
|
+
// TYPE ALIAS SYSTEM (v1.2.0)
|
|
55
|
+
// =============================================================================
|
|
56
|
+
/**
|
|
57
|
+
* Type alias registry for mapping platform-specific types to WOLS types.
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
const TYPE_ALIAS_REGISTRY = new Map([
|
|
61
|
+
// Culture aliases
|
|
62
|
+
['LIQUID_CULTURE', 'CULTURE'],
|
|
63
|
+
['LC', 'CULTURE'],
|
|
64
|
+
['AGAR', 'CULTURE'],
|
|
65
|
+
['PETRI', 'CULTURE'],
|
|
66
|
+
['SLANT', 'CULTURE'],
|
|
67
|
+
['CULTURE_PLATE', 'CULTURE'],
|
|
68
|
+
// Spawn aliases
|
|
69
|
+
['GRAIN_SPAWN', 'SPAWN'],
|
|
70
|
+
['SAWDUST_SPAWN', 'SPAWN'],
|
|
71
|
+
['PLUG_SPAWN', 'SPAWN'],
|
|
72
|
+
['DOWEL', 'SPAWN'],
|
|
73
|
+
// Substrate aliases
|
|
74
|
+
['BLOCK', 'SUBSTRATE'],
|
|
75
|
+
['BAG', 'SUBSTRATE'],
|
|
76
|
+
['BED', 'SUBSTRATE'],
|
|
77
|
+
['LOG', 'SUBSTRATE'],
|
|
78
|
+
['BUCKET', 'SUBSTRATE'],
|
|
79
|
+
// Fruiting aliases
|
|
80
|
+
['FLUSH', 'FRUITING'],
|
|
81
|
+
['PINNING', 'FRUITING'],
|
|
82
|
+
['PRIMORDIA', 'FRUITING'], // Scientifically precise term for pin initiation stage
|
|
83
|
+
['FRUIT', 'FRUITING'],
|
|
84
|
+
['FIRST_FLUSH', 'FRUITING'],
|
|
85
|
+
// Harvest aliases
|
|
86
|
+
['FRESH', 'HARVEST'],
|
|
87
|
+
['DRIED', 'HARVEST'],
|
|
88
|
+
['PROCESSED', 'HARVEST'],
|
|
89
|
+
['EXTRACT', 'HARVEST'],
|
|
90
|
+
]);
|
|
91
|
+
/**
|
|
92
|
+
* Register a custom type alias.
|
|
93
|
+
*
|
|
94
|
+
* @param alias - The alias string (case-insensitive, stored uppercase)
|
|
95
|
+
* @param wolsType - The canonical WOLS SpecimenType
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* registerTypeAlias('MYCELIUM_BLOCK', 'SUBSTRATE');
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
function registerTypeAlias(alias, wolsType) {
|
|
103
|
+
TYPE_ALIAS_REGISTRY.set(alias.toUpperCase(), wolsType);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Resolve a type alias to its canonical WOLS type.
|
|
107
|
+
* Returns the input if it's already a valid SpecimenType or no alias exists.
|
|
108
|
+
*
|
|
109
|
+
* @param typeOrAlias - Type string or alias to resolve
|
|
110
|
+
* @returns Canonical SpecimenType or original string if not found
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* resolveTypeAlias('LIQUID_CULTURE') // Returns 'CULTURE'
|
|
115
|
+
* resolveTypeAlias('CULTURE') // Returns 'CULTURE'
|
|
116
|
+
* resolveTypeAlias('unknown') // Returns 'unknown'
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
function resolveTypeAlias(typeOrAlias) {
|
|
120
|
+
const upper = typeOrAlias.toUpperCase();
|
|
121
|
+
// Already a valid type?
|
|
122
|
+
if (exports.SPECIMEN_TYPES.includes(upper)) {
|
|
123
|
+
return upper;
|
|
124
|
+
}
|
|
125
|
+
// Check alias registry
|
|
126
|
+
const resolved = TYPE_ALIAS_REGISTRY.get(upper);
|
|
127
|
+
return resolved ?? typeOrAlias;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Get all registered type aliases.
|
|
131
|
+
*
|
|
132
|
+
* @returns ReadonlyMap of alias -> SpecimenType mappings
|
|
133
|
+
*/
|
|
134
|
+
function getTypeAliases() {
|
|
135
|
+
return TYPE_ALIAS_REGISTRY;
|
|
136
|
+
}
|
|
137
|
+
// =============================================================================
|
|
138
|
+
// TYPE MAPPING EXPORTS (v1.2.0)
|
|
139
|
+
// =============================================================================
|
|
140
|
+
/**
|
|
141
|
+
* Mapping from WOLS types to common platform type names.
|
|
142
|
+
*
|
|
143
|
+
* This provides a centralized lookup for integrations that need to
|
|
144
|
+
* display user-friendly type names or map to platform-specific values.
|
|
145
|
+
*
|
|
146
|
+
* @since 1.2.0
|
|
147
|
+
*/
|
|
148
|
+
exports.WOLS_TO_PLATFORM_MAP = {
|
|
149
|
+
CULTURE: ['Liquid Culture', 'LC', 'Agar', 'Petri', 'Slant', 'Culture Plate'],
|
|
150
|
+
SPAWN: ['Grain Spawn', 'Sawdust Spawn', 'Plug Spawn', 'Dowel'],
|
|
151
|
+
SUBSTRATE: ['Block', 'Bag', 'Bed', 'Log', 'Bucket'],
|
|
152
|
+
FRUITING: ['Pinning', 'Primordia', 'Fruiting', 'Flush', 'First Flush'],
|
|
153
|
+
HARVEST: ['Fresh', 'Dried', 'Processed', 'Extract'],
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Map a platform-specific type to a WOLS SpecimenType.
|
|
157
|
+
*
|
|
158
|
+
* First checks registered aliases, then falls back to direct lookup.
|
|
159
|
+
*
|
|
160
|
+
* @param platformType - Platform-specific type name
|
|
161
|
+
* @returns Matching SpecimenType or null if not found
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* mapToWolsType('Liquid Culture') // Returns 'CULTURE'
|
|
166
|
+
* mapToWolsType('LC') // Returns 'CULTURE'
|
|
167
|
+
* mapToWolsType('Unknown Type') // Returns null
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @since 1.2.0
|
|
171
|
+
*/
|
|
172
|
+
function mapToWolsType(platformType) {
|
|
173
|
+
// First try the alias registry
|
|
174
|
+
const resolved = resolveTypeAlias(platformType);
|
|
175
|
+
if (isSpecimenType(resolved)) {
|
|
176
|
+
return resolved;
|
|
177
|
+
}
|
|
178
|
+
// Fall back to searching WOLS_TO_PLATFORM_MAP
|
|
179
|
+
const normalized = platformType.toUpperCase().replace(/\s+/g, '_');
|
|
180
|
+
for (const [wolsType, platformTypes] of Object.entries(exports.WOLS_TO_PLATFORM_MAP)) {
|
|
181
|
+
for (const pt of platformTypes) {
|
|
182
|
+
if (pt.toUpperCase().replace(/\s+/g, '_') === normalized) {
|
|
183
|
+
return wolsType;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get all platform type names for a WOLS SpecimenType.
|
|
191
|
+
*
|
|
192
|
+
* @param wolsType - WOLS SpecimenType
|
|
193
|
+
* @returns Array of platform type names
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* mapFromWolsType('CULTURE')
|
|
198
|
+
* // Returns ['Liquid Culture', 'LC', 'Agar', 'Petri', 'Slant', 'Culture Plate']
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @since 1.2.0
|
|
202
|
+
*/
|
|
203
|
+
function mapFromWolsType(wolsType) {
|
|
204
|
+
return exports.WOLS_TO_PLATFORM_MAP[wolsType] ?? [];
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Register a custom platform type mapping.
|
|
208
|
+
*
|
|
209
|
+
* This adds to both the alias registry (for resolveTypeAlias) and
|
|
210
|
+
* can be used for custom platform integrations.
|
|
211
|
+
*
|
|
212
|
+
* @param platformType - Platform-specific type name
|
|
213
|
+
* @param wolsType - WOLS SpecimenType to map to
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* registerPlatformType('Mycelium Block', 'SUBSTRATE');
|
|
218
|
+
* mapToWolsType('Mycelium Block') // Returns 'SUBSTRATE'
|
|
219
|
+
* ```
|
|
220
|
+
*
|
|
221
|
+
* @since 1.2.0
|
|
222
|
+
*/
|
|
223
|
+
function registerPlatformType(platformType, wolsType) {
|
|
224
|
+
// Add to alias registry for resolveTypeAlias support
|
|
225
|
+
registerTypeAlias(platformType, wolsType);
|
|
226
|
+
}
|
|
45
227
|
/**
|
|
46
228
|
* Array of valid growth stages for validation.
|
|
229
|
+
* Ordered by typical lifecycle progression.
|
|
47
230
|
*/
|
|
48
231
|
exports.GROWTH_STAGES = [
|
|
49
232
|
'INOCULATION',
|
|
233
|
+
'INCUBATION',
|
|
50
234
|
'COLONIZATION',
|
|
235
|
+
'PRIMORDIA',
|
|
51
236
|
'FRUITING',
|
|
237
|
+
'SENESCENCE',
|
|
52
238
|
'HARVEST',
|
|
53
239
|
];
|
|
240
|
+
/**
|
|
241
|
+
* Pattern for parsing generation strings.
|
|
242
|
+
* Matches: P, P1, F{n}, G{n}, or plain numbers.
|
|
243
|
+
*/
|
|
244
|
+
const GENERATION_PARSE_PATTERN = /^(P|P1|F(\d+)|G(\d+)|(\d+))$/i;
|
|
245
|
+
/**
|
|
246
|
+
* Normalize a generation string to the specified format.
|
|
247
|
+
*
|
|
248
|
+
* Accepts multiple input formats:
|
|
249
|
+
* - Filial: F1, F2, F3, etc.
|
|
250
|
+
* - Parental: P or P1
|
|
251
|
+
* - Generational: G1, G2, G3, etc.
|
|
252
|
+
* - Numeric: 1, 2, 3, etc.
|
|
253
|
+
*
|
|
254
|
+
* @param generation - The generation string to normalize
|
|
255
|
+
* @param format - Target format (default: 'preserve')
|
|
256
|
+
* @returns Normalized generation string, or original if not parseable
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* normalizeGeneration('G2', 'filial') // Returns 'F2'
|
|
261
|
+
* normalizeGeneration('3', 'filial') // Returns 'F3'
|
|
262
|
+
* normalizeGeneration('F1', 'numeric') // Returns '1'
|
|
263
|
+
* normalizeGeneration('P', 'filial') // Returns 'P'
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @since 1.2.0
|
|
267
|
+
*/
|
|
268
|
+
function normalizeGeneration(generation, format = 'preserve') {
|
|
269
|
+
const trimmed = generation.trim().toUpperCase();
|
|
270
|
+
// Handle parental generation specially
|
|
271
|
+
if (trimmed === 'P' || trimmed === 'P1') {
|
|
272
|
+
return format === 'numeric' ? '0' : 'P';
|
|
273
|
+
}
|
|
274
|
+
const match = GENERATION_PARSE_PATTERN.exec(trimmed);
|
|
275
|
+
if (!match) {
|
|
276
|
+
return generation; // Return original if not parseable
|
|
277
|
+
}
|
|
278
|
+
// Extract the numeric value
|
|
279
|
+
let numericValue;
|
|
280
|
+
if (match[2] !== undefined) {
|
|
281
|
+
// F{n} format
|
|
282
|
+
numericValue = parseInt(match[2], 10);
|
|
283
|
+
}
|
|
284
|
+
else if (match[3] !== undefined) {
|
|
285
|
+
// G{n} format
|
|
286
|
+
numericValue = parseInt(match[3], 10);
|
|
287
|
+
}
|
|
288
|
+
else if (match[4] !== undefined) {
|
|
289
|
+
// Plain number
|
|
290
|
+
numericValue = parseInt(match[4], 10);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
return generation; // Shouldn't reach here
|
|
294
|
+
}
|
|
295
|
+
switch (format) {
|
|
296
|
+
case 'preserve':
|
|
297
|
+
return trimmed;
|
|
298
|
+
case 'filial':
|
|
299
|
+
return `F${numericValue}`;
|
|
300
|
+
case 'numeric':
|
|
301
|
+
return String(numericValue);
|
|
302
|
+
default:
|
|
303
|
+
return generation;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Check if a generation string is valid.
|
|
308
|
+
*
|
|
309
|
+
* @param generation - The generation string to validate
|
|
310
|
+
* @returns True if valid, false otherwise
|
|
311
|
+
*
|
|
312
|
+
* @since 1.2.0
|
|
313
|
+
*/
|
|
314
|
+
function isValidGeneration(generation) {
|
|
315
|
+
const trimmed = generation.trim().toUpperCase();
|
|
316
|
+
return GENERATION_PARSE_PATTERN.test(trimmed);
|
|
317
|
+
}
|
|
54
318
|
// =============================================================================
|
|
55
319
|
// TYPE GUARDS
|
|
56
320
|
// =============================================================================
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAoCH,oCAEC;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAoCH,oCAEC;AAyED,8CAEC;AAgBD,4CAWC;AAOD,wCAEC;AAuCD,sCAkBC;AAgBD,0CAEC;AAmBD,oDAGC;AAiFD,kDAyCC;AAUD,8CAGC;AAiWD,wCAEC;AAKD,sCAEC;AAKD,4BAOC;AAjvBD,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF;;GAEG;AACU,QAAA,YAAY,GAAG,OAAO,CAAC;AAEpC;;GAEG;AACU,QAAA,YAAY,GAAG,4BAA4B,CAAC;AAkBzD;;;GAGG;AACH,SAAgB,Y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C,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAChD,OAAO,wBAAwB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC;AA0VD,gFAAgF;AAChF,cAAc;AACd,gFAAgF;AAEhF;;GAEG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,sBAAc,CAAC,QAAQ,CAAC,KAAqB,CAAC,CAAC;AACrF,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,qBAAa,CAAC,QAAQ,CAAC,KAAoB,CAAC,CAAC;AACnF,CAAC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,MAAM,IAAI,KAAK;QACf,OAAQ,KAAgB,CAAC,IAAI,KAAK,QAAQ,CAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Environment Detection Utilities
|
|
4
|
+
*
|
|
5
|
+
* This module provides runtime environment detection for selecting
|
|
6
|
+
* appropriate crypto implementations and other environment-specific behavior.
|
|
7
|
+
*
|
|
8
|
+
* @module utils/environment
|
|
9
|
+
* @since 1.2.0
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.isServer = isServer;
|
|
13
|
+
exports.isBrowser = isBrowser;
|
|
14
|
+
exports.isWebWorker = isWebWorker;
|
|
15
|
+
exports.isDeno = isDeno;
|
|
16
|
+
exports.isBun = isBun;
|
|
17
|
+
exports.getRuntimeEnvironment = getRuntimeEnvironment;
|
|
18
|
+
exports.supportsWebCrypto = supportsWebCrypto;
|
|
19
|
+
exports.supportsNodeCrypto = supportsNodeCrypto;
|
|
20
|
+
exports.isCryptoSupported = isCryptoSupported;
|
|
21
|
+
exports.supportsTextEncoding = supportsTextEncoding;
|
|
22
|
+
exports.supportsURLAPIs = supportsURLAPIs;
|
|
23
|
+
// =============================================================================
|
|
24
|
+
// ENVIRONMENT DETECTION
|
|
25
|
+
// =============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Check if running in a server-side Node.js environment.
|
|
28
|
+
*
|
|
29
|
+
* @returns True if running in Node.js, false otherwise
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* if (isServer()) {
|
|
34
|
+
* // Use Node.js crypto module
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @since 1.2.0
|
|
39
|
+
*/
|
|
40
|
+
function isServer() {
|
|
41
|
+
return (typeof globalThis !== 'undefined' &&
|
|
42
|
+
typeof globalThis.process
|
|
43
|
+
?.versions?.node === 'string');
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Check if running in a browser environment.
|
|
47
|
+
*
|
|
48
|
+
* @returns True if running in a browser, false otherwise
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* if (isBrowser()) {
|
|
53
|
+
* // Use Web Crypto API
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @since 1.2.0
|
|
58
|
+
*/
|
|
59
|
+
function isBrowser() {
|
|
60
|
+
return (typeof globalThis !== 'undefined' &&
|
|
61
|
+
typeof globalThis.window !== 'undefined' &&
|
|
62
|
+
typeof globalThis.document !== 'undefined');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if running in a Web Worker environment.
|
|
66
|
+
*
|
|
67
|
+
* @returns True if running in a Web Worker, false otherwise
|
|
68
|
+
*
|
|
69
|
+
* @since 1.2.0
|
|
70
|
+
*/
|
|
71
|
+
function isWebWorker() {
|
|
72
|
+
// Check if WorkerGlobalScope exists and if self is an instance of it
|
|
73
|
+
// In a Web Worker, self instanceof WorkerGlobalScope is true
|
|
74
|
+
// In the main thread, WorkerGlobalScope doesn't exist or self is not an instance
|
|
75
|
+
if (typeof globalThis === 'undefined') {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
const global = globalThis;
|
|
79
|
+
return (typeof global.WorkerGlobalScope !== 'undefined' &&
|
|
80
|
+
typeof global.self !== 'undefined' &&
|
|
81
|
+
global.self instanceof global.WorkerGlobalScope);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check if running in Deno environment.
|
|
85
|
+
*
|
|
86
|
+
* @returns True if running in Deno, false otherwise
|
|
87
|
+
*
|
|
88
|
+
* @since 1.2.0
|
|
89
|
+
*/
|
|
90
|
+
function isDeno() {
|
|
91
|
+
return (typeof globalThis !== 'undefined' &&
|
|
92
|
+
typeof globalThis.Deno !== 'undefined');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if running in Bun environment.
|
|
96
|
+
*
|
|
97
|
+
* @returns True if running in Bun, false otherwise
|
|
98
|
+
*
|
|
99
|
+
* @since 1.2.0
|
|
100
|
+
*/
|
|
101
|
+
function isBun() {
|
|
102
|
+
return (typeof globalThis !== 'undefined' &&
|
|
103
|
+
typeof globalThis.Bun !== 'undefined');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the current runtime environment.
|
|
107
|
+
*
|
|
108
|
+
* @returns The detected runtime environment
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const env = getRuntimeEnvironment();
|
|
113
|
+
* console.log(`Running in: ${env}`);
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @since 1.2.0
|
|
117
|
+
*/
|
|
118
|
+
function getRuntimeEnvironment() {
|
|
119
|
+
if (isBun())
|
|
120
|
+
return 'bun';
|
|
121
|
+
if (isDeno())
|
|
122
|
+
return 'deno';
|
|
123
|
+
if (isServer())
|
|
124
|
+
return 'node';
|
|
125
|
+
if (isWebWorker())
|
|
126
|
+
return 'webworker';
|
|
127
|
+
if (isBrowser())
|
|
128
|
+
return 'browser';
|
|
129
|
+
return 'unknown';
|
|
130
|
+
}
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// CRYPTO SUPPORT DETECTION
|
|
133
|
+
// =============================================================================
|
|
134
|
+
/**
|
|
135
|
+
* Check if Web Crypto API is available.
|
|
136
|
+
*
|
|
137
|
+
* @returns True if Web Crypto API is available, false otherwise
|
|
138
|
+
*
|
|
139
|
+
* @since 1.2.0
|
|
140
|
+
*/
|
|
141
|
+
function supportsWebCrypto() {
|
|
142
|
+
return (typeof globalThis !== 'undefined' &&
|
|
143
|
+
typeof globalThis.crypto?.subtle !==
|
|
144
|
+
'undefined');
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Check if Node.js crypto module is available.
|
|
148
|
+
*
|
|
149
|
+
* Note: This performs a synchronous check and does not actually import the module.
|
|
150
|
+
*
|
|
151
|
+
* @returns True if likely running in Node.js with crypto support, false otherwise
|
|
152
|
+
*
|
|
153
|
+
* @since 1.2.0
|
|
154
|
+
*/
|
|
155
|
+
function supportsNodeCrypto() {
|
|
156
|
+
return isServer() || isBun();
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check if any cryptographic support is available.
|
|
160
|
+
*
|
|
161
|
+
* This is useful for determining if encryption/decryption features can be used.
|
|
162
|
+
*
|
|
163
|
+
* @returns True if crypto is supported, false otherwise
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* if (isCryptoSupported()) {
|
|
168
|
+
* const encrypted = await encryptSpecimen(specimen, { key: password });
|
|
169
|
+
* } else {
|
|
170
|
+
* console.warn('Crypto not supported in this environment');
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* @since 1.2.0
|
|
175
|
+
*/
|
|
176
|
+
function isCryptoSupported() {
|
|
177
|
+
return supportsWebCrypto() || supportsNodeCrypto();
|
|
178
|
+
}
|
|
179
|
+
// =============================================================================
|
|
180
|
+
// FEATURE DETECTION
|
|
181
|
+
// =============================================================================
|
|
182
|
+
/**
|
|
183
|
+
* Check if TextEncoder/TextDecoder are available.
|
|
184
|
+
*
|
|
185
|
+
* @returns True if text encoding is supported, false otherwise
|
|
186
|
+
*
|
|
187
|
+
* @since 1.2.0
|
|
188
|
+
*/
|
|
189
|
+
function supportsTextEncoding() {
|
|
190
|
+
return (typeof globalThis !== 'undefined' &&
|
|
191
|
+
typeof globalThis.TextEncoder !== 'undefined' &&
|
|
192
|
+
typeof globalThis.TextDecoder !== 'undefined');
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Check if URL and URLSearchParams are available.
|
|
196
|
+
*
|
|
197
|
+
* @returns True if URL APIs are supported, false otherwise
|
|
198
|
+
*
|
|
199
|
+
* @since 1.2.0
|
|
200
|
+
*/
|
|
201
|
+
function supportsURLAPIs() {
|
|
202
|
+
return (typeof globalThis !== 'undefined' &&
|
|
203
|
+
typeof globalThis.URL !== 'undefined' &&
|
|
204
|
+
typeof globalThis.URLSearchParams !== 'undefined');
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../src/utils/environment.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AA+BH,4BAMC;AAgBD,8BAMC;AASD,kCAkBC;AASD,wBAKC;AASD,sBAKC;AAeD,sDAOC;AAaD,8CAMC;AAWD,gDAEC;AAoBD,8CAEC;AAaD,oDAMC;AASD,0CAMC;AAnND,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEhF;;;;;;;;;;;;;GAaG;AACH,SAAgB,QAAQ;IACtB,OAAO,CACL,OAAO,UAAU,KAAK,WAAW;QACjC,OAAQ,UAAwE,CAAC,OAAO;YACtF,EAAE,QAAQ,EA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