@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.
Files changed (58) hide show
  1. package/dist/cjs/compact-url.js +64 -0
  2. package/dist/cjs/compact-url.js.map +1 -1
  3. package/dist/cjs/crypto/decrypt.js +16 -5
  4. package/dist/cjs/crypto/decrypt.js.map +1 -1
  5. package/dist/cjs/crypto/encrypt.js +111 -9
  6. package/dist/cjs/crypto/encrypt.js.map +1 -1
  7. package/dist/cjs/index.js +53 -1
  8. package/dist/cjs/index.js.map +1 -1
  9. package/dist/cjs/parser.js +3 -0
  10. package/dist/cjs/parser.js.map +1 -1
  11. package/dist/cjs/specimen.js +14 -1
  12. package/dist/cjs/specimen.js.map +1 -1
  13. package/dist/cjs/types.js +267 -3
  14. package/dist/cjs/types.js.map +1 -1
  15. package/dist/cjs/utils/environment.js +206 -0
  16. package/dist/cjs/utils/environment.js.map +1 -0
  17. package/dist/cjs/utils/migration.js +248 -0
  18. package/dist/cjs/utils/migration.js.map +1 -0
  19. package/dist/cjs/validator.js +62 -9
  20. package/dist/cjs/validator.js.map +1 -1
  21. package/dist/esm/compact-url.js +62 -0
  22. package/dist/esm/compact-url.js.map +1 -1
  23. package/dist/esm/crypto/decrypt.js +16 -5
  24. package/dist/esm/crypto/decrypt.js.map +1 -1
  25. package/dist/esm/crypto/encrypt.js +111 -9
  26. package/dist/esm/crypto/encrypt.js.map +1 -1
  27. package/dist/esm/index.js +21 -1
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/parser.js +3 -0
  30. package/dist/esm/parser.js.map +1 -1
  31. package/dist/esm/specimen.js +15 -2
  32. package/dist/esm/specimen.js.map +1 -1
  33. package/dist/esm/types.js +258 -2
  34. package/dist/esm/types.js.map +1 -1
  35. package/dist/esm/utils/environment.js +193 -0
  36. package/dist/esm/utils/environment.js.map +1 -0
  37. package/dist/esm/utils/migration.js +237 -0
  38. package/dist/esm/utils/migration.js.map +1 -0
  39. package/dist/esm/validator.js +62 -9
  40. package/dist/esm/validator.js.map +1 -1
  41. package/dist/types/compact-url.d.ts +46 -0
  42. package/dist/types/compact-url.d.ts.map +1 -1
  43. package/dist/types/crypto/decrypt.d.ts +6 -0
  44. package/dist/types/crypto/decrypt.d.ts.map +1 -1
  45. package/dist/types/crypto/encrypt.d.ts +56 -1
  46. package/dist/types/crypto/encrypt.d.ts.map +1 -1
  47. package/dist/types/index.d.ts +10 -2
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/parser.d.ts.map +1 -1
  50. package/dist/types/specimen.d.ts.map +1 -1
  51. package/dist/types/types.d.ts +246 -5
  52. package/dist/types/types.d.ts.map +1 -1
  53. package/dist/types/utils/environment.d.ts +137 -0
  54. package/dist/types/utils/environment.d.ts.map +1 -0
  55. package/dist/types/utils/migration.d.ts +162 -0
  56. package/dist/types/utils/migration.d.ts.map +1 -0
  57. package/dist/types/validator.d.ts.map +1 -1
  58. package/package.json +1 -1
@@ -0,0 +1,162 @@
1
+ /**
2
+ * Version Migration Utilities
3
+ *
4
+ * This module provides utilities for comparing WOLS versions and
5
+ * migrating specimens between versions.
6
+ *
7
+ * @module utils/migration
8
+ * @since 1.2.0
9
+ */
10
+ import type { Specimen } from '../types.js';
11
+ /**
12
+ * Version comparison result.
13
+ *
14
+ * - `-1`: First version is older than second
15
+ * - `0`: Versions are equal
16
+ * - `1`: First version is newer than second
17
+ *
18
+ * @since 1.2.0
19
+ */
20
+ export type VersionComparison = -1 | 0 | 1;
21
+ /**
22
+ * Migration handler function signature.
23
+ *
24
+ * @since 1.2.0
25
+ */
26
+ export type MigrationHandler = (specimen: Specimen) => Specimen;
27
+ /**
28
+ * Migration definition.
29
+ *
30
+ * @since 1.2.0
31
+ */
32
+ interface MigrationDefinition {
33
+ from: string;
34
+ to: string;
35
+ handler: MigrationHandler;
36
+ }
37
+ /**
38
+ * Compare two semantic versions.
39
+ *
40
+ * @param a - First version string
41
+ * @param b - Second version string
42
+ * @returns -1 if a < b, 0 if a === b, 1 if a > b
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * compareVersions('1.0.0', '1.1.0') // Returns -1
47
+ * compareVersions('1.1.0', '1.1.0') // Returns 0
48
+ * compareVersions('2.0.0', '1.9.0') // Returns 1
49
+ * ```
50
+ *
51
+ * @since 1.2.0
52
+ */
53
+ export declare function compareVersions(a: string, b: string): VersionComparison;
54
+ /**
55
+ * Check if a specimen is using an outdated WOLS version.
56
+ *
57
+ * @param specimen - Specimen object or version string
58
+ * @returns True if the specimen version is older than current library version
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * isOutdated(specimen) // True if specimen.version < WOLS_VERSION
63
+ * isOutdated('1.0.0') // True (older than current)
64
+ * ```
65
+ *
66
+ * @since 1.2.0
67
+ */
68
+ export declare function isOutdated(specimen: Specimen | string): boolean;
69
+ /**
70
+ * Check if a specimen is using a newer WOLS version than this library.
71
+ *
72
+ * This can happen when specimens are created by a newer library version.
73
+ *
74
+ * @param specimen - Specimen object or version string
75
+ * @returns True if the specimen version is newer than current library version
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * isNewer(specimen) // True if specimen.version > WOLS_VERSION
80
+ * isNewer('2.0.0') // True if library is 1.x
81
+ * ```
82
+ *
83
+ * @since 1.2.0
84
+ */
85
+ export declare function isNewer(specimen: Specimen | string): boolean;
86
+ /**
87
+ * Get the current library WOLS version.
88
+ *
89
+ * @returns The WOLS version this library implements
90
+ *
91
+ * @since 1.2.0
92
+ */
93
+ export declare function getCurrentVersion(): string;
94
+ /**
95
+ * Register a migration handler for upgrading specimens between versions.
96
+ *
97
+ * Migrations are applied in order from oldest to newest when calling `migrate()`.
98
+ *
99
+ * @param from - Source version (e.g., "1.0.0")
100
+ * @param to - Target version (e.g., "1.1.0")
101
+ * @param handler - Function to transform the specimen
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * registerMigration('1.0.0', '1.1.0', (specimen) => {
106
+ * // Add new required field with default value
107
+ * return { ...specimen, newField: 'default' };
108
+ * });
109
+ * ```
110
+ *
111
+ * @since 1.2.0
112
+ */
113
+ export declare function registerMigration(from: string, to: string, handler: MigrationHandler): void;
114
+ /**
115
+ * Check if a specimen can be migrated to the current version.
116
+ *
117
+ * @param specimen - Specimen to check
118
+ * @returns True if migration path exists, false otherwise
119
+ *
120
+ * @since 1.2.0
121
+ */
122
+ export declare function canMigrate(specimen: Specimen): boolean;
123
+ /**
124
+ * Migrate a specimen to the current WOLS version.
125
+ *
126
+ * Applies all registered migrations in order from the specimen's version
127
+ * to the current library version.
128
+ *
129
+ * @param specimen - Specimen to migrate
130
+ * @returns Migrated specimen with updated version
131
+ * @throws Error if no migration path exists
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const oldSpecimen = parseSpecimen(oldJson);
136
+ * if (isOutdated(oldSpecimen)) {
137
+ * const updated = migrate(oldSpecimen);
138
+ * console.log('Migrated to:', updated.version);
139
+ * }
140
+ * ```
141
+ *
142
+ * @since 1.2.0
143
+ */
144
+ export declare function migrate(specimen: Specimen): Specimen;
145
+ /**
146
+ * Get all registered migrations.
147
+ *
148
+ * @returns Array of migration definitions
149
+ *
150
+ * @since 1.2.0
151
+ */
152
+ export declare function getMigrations(): readonly MigrationDefinition[];
153
+ /**
154
+ * Clear all registered migrations.
155
+ *
156
+ * Primarily useful for testing.
157
+ *
158
+ * @since 1.2.0
159
+ */
160
+ export declare function clearMigrations(): void;
161
+ export {};
162
+ //# sourceMappingURL=migration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/utils/migration.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAO5C;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE3C;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAA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ZpB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,GAAG,OAAO,EAC5B,OAAO,GAAE,iBAAsB,GAC9B,gBAAgB,CA+ClB"}
1
+ {"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../src/validator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAGL,KAAK,QAAQ,EAGb,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAGtB,MAAM,YAAY,CAAC;AAkepB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,QAAQ,GAAG,OAAO,EAC5B,OAAO,GAAE,iBAAsB,GAC9B,gBAAgB,CAgDlB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wemush/wols",
3
- "version": "0.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Official WOLS (WeMush Open Labeling Standard) library for specimen labeling and traceability",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",