@bleedingdev/modern-js-surface-resolution 0.0.0 → 3.9.0-ultramodern.6

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 (28) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/surface-resolution/env-static-provider.js +318 -0
  3. package/dist/cjs/surface-resolution/index.js +69 -0
  4. package/dist/cjs/surface-resolution/surface-ref.js +132 -0
  5. package/dist/cjs/surface-resolution/types.js +18 -0
  6. package/dist/cjs/surface-resolution/validation.js +202 -0
  7. package/dist/esm/surface-resolution/env-static-provider.mjs +274 -0
  8. package/dist/esm/surface-resolution/index.mjs +3 -0
  9. package/dist/esm/surface-resolution/surface-ref.mjs +88 -0
  10. package/dist/esm/surface-resolution/types.mjs +0 -0
  11. package/dist/esm/surface-resolution/validation.mjs +155 -0
  12. package/dist/esm-node/surface-resolution/env-static-provider.mjs +275 -0
  13. package/dist/esm-node/surface-resolution/index.mjs +4 -0
  14. package/dist/esm-node/surface-resolution/surface-ref.mjs +89 -0
  15. package/dist/esm-node/surface-resolution/types.mjs +1 -0
  16. package/dist/esm-node/surface-resolution/validation.mjs +156 -0
  17. package/dist/types/surface-resolution/env-static-provider.d.ts +107 -0
  18. package/dist/types/surface-resolution/index.d.ts +4 -0
  19. package/dist/types/surface-resolution/surface-ref.d.ts +72 -0
  20. package/dist/types/surface-resolution/types.d.ts +102 -0
  21. package/dist/types/surface-resolution/validation.d.ts +53 -0
  22. package/package.json +40 -4
  23. package/src/surface-resolution/env-static-provider.ts +596 -0
  24. package/src/surface-resolution/index.ts +43 -0
  25. package/src/surface-resolution/surface-ref.ts +145 -0
  26. package/src/surface-resolution/types.ts +136 -0
  27. package/src/surface-resolution/validation.ts +337 -0
  28. package/README.md +0 -3
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021-present Modern.js
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,318 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ DEFAULT_LOCAL_ENVIRONMENTS: ()=>DEFAULT_LOCAL_ENVIRONMENTS,
32
+ ENV_STATIC_PROVIDER_NAME: ()=>ENV_STATIC_PROVIDER_NAME,
33
+ createEnvStaticSurfaceResolutionProvider: ()=>createEnvStaticSurfaceResolutionProvider
34
+ });
35
+ const external_surface_ref_js_namespaceObject = require("./surface-ref.js");
36
+ const external_validation_js_namespaceObject = require("./validation.js");
37
+ const DEFAULT_LOCAL_ENVIRONMENTS = [
38
+ 'development',
39
+ 'local'
40
+ ];
41
+ const ENV_STATIC_PROVIDER_NAME = 'env-static';
42
+ function trimTrailingSlashes(value) {
43
+ return value.replace(/\/+$/u, '');
44
+ }
45
+ function envValue(env, name) {
46
+ const value = env[name]?.trim();
47
+ return void 0 !== value && value.length > 0 ? value : void 0;
48
+ }
49
+ function stripMfNamePrefix(value, mfName) {
50
+ return value.startsWith(`${mfName}@`) ? value.slice(mfName.length + 1) : value;
51
+ }
52
+ function createEnvContext(env, allowLocalFallback) {
53
+ return {
54
+ env,
55
+ allowLocalFallback,
56
+ cloudflareDeployEnabled: 'cloudflare' === env.MODERNJS_DEPLOY,
57
+ workersDevSubdomain: envValue(env, 'ULTRAMODERN_CLOUDFLARE_WORKERS_DEV_SUBDOMAIN'),
58
+ requireCloudflarePublicUrls: 'true' === env.ULTRAMODERN_CLOUDFLARE_REQUIRE_PUBLIC_URLS
59
+ };
60
+ }
61
+ function resolveBaseUrl(context, unit) {
62
+ const publicUrlEnv = `ULTRAMODERN_PUBLIC_URL_${unit.envSegment}`;
63
+ const configuredPublicUrl = envValue(context.env, publicUrlEnv);
64
+ if (void 0 !== configuredPublicUrl) return {
65
+ ok: true,
66
+ baseUrl: trimTrailingSlashes(configuredPublicUrl)
67
+ };
68
+ if (context.cloudflareDeployEnabled && void 0 !== context.workersDevSubdomain && void 0 !== unit.workerName) return {
69
+ ok: true,
70
+ baseUrl: `https://${unit.workerName}.${context.workersDevSubdomain}.workers.dev`
71
+ };
72
+ if (context.cloudflareDeployEnabled && context.requireCloudflarePublicUrls) return {
73
+ ok: false,
74
+ reason: `Cloudflare deploy requires ${publicUrlEnv} (or a configured manifest env / ULTRAMODERN_CLOUDFLARE_WORKERS_DEV_SUBDOMAIN with a worker name)`,
75
+ details: {
76
+ publicUrlEnv
77
+ }
78
+ };
79
+ if (void 0 !== unit.port && context.allowLocalFallback) return {
80
+ ok: true,
81
+ baseUrl: `http://localhost:${unit.port}`
82
+ };
83
+ if (void 0 !== unit.port) return {
84
+ ok: false,
85
+ reason: `No base URL available: set ${publicUrlEnv} (localhost fallback is disabled outside designated local environments)`,
86
+ details: {
87
+ publicUrlEnv
88
+ }
89
+ };
90
+ return {
91
+ ok: false,
92
+ reason: `No base URL available: set ${publicUrlEnv} or configure a localhost port`,
93
+ details: {
94
+ publicUrlEnv
95
+ }
96
+ };
97
+ }
98
+ function resolveBrowserMfManifest(context, unit) {
99
+ const manifestEnv = `VERTICAL_${unit.envSegment}_MF_MANIFEST`;
100
+ const configuredManifest = envValue(context.env, manifestEnv);
101
+ if (void 0 !== configuredManifest) return {
102
+ ok: true,
103
+ location: {
104
+ platform: 'browser-mf-manifest',
105
+ manifestUrl: stripMfNamePrefix(configuredManifest, unit.mfName)
106
+ }
107
+ };
108
+ const base = resolveBaseUrl(context, unit);
109
+ if (!base.ok) return {
110
+ ok: false,
111
+ reason: `browser-mf-manifest unavailable (${manifestEnv} unset; ${base.reason})`,
112
+ details: {
113
+ manifestEnv,
114
+ ...base.details
115
+ }
116
+ };
117
+ return {
118
+ ok: true,
119
+ location: {
120
+ platform: 'browser-mf-manifest',
121
+ manifestUrl: `${base.baseUrl}/mf-manifest.json`
122
+ }
123
+ };
124
+ }
125
+ function resolveNodeMfManifest(context, unit) {
126
+ const manifestEnv = `VERTICAL_${unit.envSegment}_BACKEND_MF_MANIFEST`;
127
+ const configuredManifest = envValue(context.env, manifestEnv);
128
+ if (void 0 !== configuredManifest) return {
129
+ ok: true,
130
+ location: {
131
+ platform: 'node-mf-manifest',
132
+ manifestRef: configuredManifest
133
+ }
134
+ };
135
+ if (void 0 !== unit.port && context.allowLocalFallback) return {
136
+ ok: true,
137
+ location: {
138
+ platform: 'node-mf-manifest',
139
+ manifestRef: `http://localhost:${unit.port}/backend-mf-manifest.json`
140
+ }
141
+ };
142
+ if (void 0 !== unit.port) return {
143
+ ok: false,
144
+ reason: `node-mf-manifest unavailable: set ${manifestEnv} (localhost fallback is disabled outside designated local environments)`,
145
+ details: {
146
+ manifestEnv
147
+ }
148
+ };
149
+ return {
150
+ ok: false,
151
+ reason: `node-mf-manifest unavailable: set ${manifestEnv} or configure a localhost port`,
152
+ details: {
153
+ manifestEnv
154
+ }
155
+ };
156
+ }
157
+ function resolveHttpApi(context, unit, config) {
158
+ const base = resolveBaseUrl(context, unit);
159
+ if (!base.ok) return {
160
+ ok: false,
161
+ reason: `http-api unavailable (${base.reason})`,
162
+ details: base.details
163
+ };
164
+ return {
165
+ ok: true,
166
+ location: {
167
+ platform: 'http-api',
168
+ baseUrl: base.baseUrl,
169
+ prefix: config.prefix
170
+ }
171
+ };
172
+ }
173
+ function resolveCloudflareServiceBinding(config) {
174
+ if (0 === config.serviceBinding.length) return {
175
+ ok: false,
176
+ reason: 'cloudflare-service-binding unavailable: empty serviceBinding'
177
+ };
178
+ return {
179
+ ok: true,
180
+ location: {
181
+ platform: 'cloudflare-service-binding',
182
+ serviceBinding: config.serviceBinding,
183
+ ...void 0 === config.dispatchNamespace ? {} : {
184
+ dispatchNamespace: config.dispatchNamespace
185
+ }
186
+ }
187
+ };
188
+ }
189
+ function resolveSurfaceLocations(context, unit, surface) {
190
+ const outcomes = [];
191
+ if (surface.platforms.browserMfManifest) outcomes.push(resolveBrowserMfManifest(context, unit));
192
+ if (surface.platforms.nodeMfManifest) outcomes.push(resolveNodeMfManifest(context, unit));
193
+ if (void 0 !== surface.platforms.httpApi) outcomes.push(resolveHttpApi(context, unit, surface.platforms.httpApi));
194
+ if (void 0 !== surface.platforms.cloudflareServiceBinding) outcomes.push(resolveCloudflareServiceBinding(surface.platforms.cloudflareServiceBinding));
195
+ const failure = outcomes.find((outcome)=>!outcome.ok);
196
+ if (void 0 !== failure && !failure.ok) return {
197
+ ok: false,
198
+ reason: `surface ${surface.surfaceId}: ${failure.reason}`,
199
+ details: failure.details
200
+ };
201
+ const locations = outcomes.flatMap((outcome)=>outcome.ok ? [
202
+ outcome.location
203
+ ] : []);
204
+ if (0 === locations.length) return {
205
+ ok: false,
206
+ reason: `surface ${surface.surfaceId} declares no platform locations`
207
+ };
208
+ return {
209
+ ok: true,
210
+ surface: {
211
+ surfaceId: surface.surfaceId,
212
+ kind: surface.kind,
213
+ locations
214
+ }
215
+ };
216
+ }
217
+ function createEnvStaticSurfaceResolutionProvider(options) {
218
+ const env = options.env ?? {};
219
+ const localEnvironments = new Set(options.localEnvironments ?? DEFAULT_LOCAL_ENVIRONMENTS);
220
+ const identityVerification = options.identityVerification ?? 'static-trust';
221
+ const unitsById = new Map(options.units.map((unit)=>[
222
+ unit.unitId,
223
+ unit
224
+ ]));
225
+ return {
226
+ name: ENV_STATIC_PROVIDER_NAME,
227
+ resolve (ref, environment) {
228
+ const refString = (0, external_surface_ref_js_namespaceObject.formatSurfaceRef)(ref);
229
+ const unit = unitsById.get(ref.unitId);
230
+ if (void 0 === unit) return {
231
+ ok: false,
232
+ error: (0, external_validation_js_namespaceObject.createDiscoveryError)('unknown-unit', refString, `No statically configured delivery unit ${ref.unitId}.`, {
233
+ environment,
234
+ knownUnits: [
235
+ ...unitsById.keys()
236
+ ]
237
+ })
238
+ };
239
+ if (!unit.surfaces.some((surface)=>surface.surfaceId === ref.surfaceId)) return {
240
+ ok: false,
241
+ error: (0, external_validation_js_namespaceObject.createDiscoveryError)('unknown-surface', refString, `Unit ${unit.unitId} does not declare surface ${ref.surfaceId}.`, {
242
+ environment,
243
+ availableSurfaces: unit.surfaces.map((surface)=>surface.surfaceId)
244
+ })
245
+ };
246
+ let effectiveUnit = unit;
247
+ if (void 0 !== ref.major) {
248
+ const majorConfig = (unit.majors ?? []).find((candidate)=>candidate.major === ref.major);
249
+ if (void 0 === majorConfig) return {
250
+ ok: false,
251
+ error: (0, external_validation_js_namespaceObject.createDiscoveryError)('major-not-published', refString, `Unit ${unit.unitId} has no materialization for external major v${ref.major}.`, {
252
+ environment,
253
+ publishedMajors: (unit.majors ?? []).map((candidate)=>candidate.major)
254
+ })
255
+ };
256
+ effectiveUnit = {
257
+ ...unit,
258
+ envSegment: majorConfig.envSegment ?? `${unit.envSegment}_V${majorConfig.major}`,
259
+ port: majorConfig.port,
260
+ workerName: majorConfig.workerName
261
+ };
262
+ }
263
+ const context = createEnvContext(env, localEnvironments.has(environment));
264
+ const surfaces = [];
265
+ for (const surfaceConfig of unit.surfaces){
266
+ const resolved = resolveSurfaceLocations(context, effectiveUnit, surfaceConfig);
267
+ if (!resolved.ok) return {
268
+ ok: false,
269
+ error: (0, external_validation_js_namespaceObject.createDiscoveryError)('provider-unavailable', refString, `env-static provider cannot assemble a complete record for ${unit.unitId}: ${resolved.reason}.`, {
270
+ environment,
271
+ ...resolved.details
272
+ })
273
+ };
274
+ surfaces.push(void 0 === ref.major ? resolved.surface : {
275
+ ...resolved.surface,
276
+ servedMajor: ref.major
277
+ });
278
+ }
279
+ const record = {
280
+ unitId: unit.unitId,
281
+ buildMarker: unit.buildMarker,
282
+ sourceRevision: unit.sourceRevision,
283
+ baselineCohortId: unit.baselineCohortId,
284
+ surfaces,
285
+ compatibility: {
286
+ status: 'compatible',
287
+ baselineCohortId: unit.baselineCohortId,
288
+ ...'static-trust' === identityVerification ? {
289
+ reason: 'static-identity-unverified'
290
+ } : {}
291
+ }
292
+ };
293
+ const validation = (0, external_validation_js_namespaceObject.validateResolvedDeliveryUnit)(record);
294
+ if (!validation.ok) return {
295
+ ok: false,
296
+ error: (0, external_validation_js_namespaceObject.createDiscoveryError)('provider-unavailable', refString, `env-static provider assembled an invalid record for ${unit.unitId}.`, {
297
+ environment,
298
+ issues: validation.issues
299
+ })
300
+ };
301
+ return {
302
+ ok: true,
303
+ unit: record
304
+ };
305
+ }
306
+ };
307
+ }
308
+ exports.DEFAULT_LOCAL_ENVIRONMENTS = __webpack_exports__.DEFAULT_LOCAL_ENVIRONMENTS;
309
+ exports.ENV_STATIC_PROVIDER_NAME = __webpack_exports__.ENV_STATIC_PROVIDER_NAME;
310
+ exports.createEnvStaticSurfaceResolutionProvider = __webpack_exports__.createEnvStaticSurfaceResolutionProvider;
311
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
312
+ "DEFAULT_LOCAL_ENVIRONMENTS",
313
+ "ENV_STATIC_PROVIDER_NAME",
314
+ "createEnvStaticSurfaceResolutionProvider"
315
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
316
+ Object.defineProperty(exports, '__esModule', {
317
+ value: true
318
+ });
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ DEFAULT_LOCAL_ENVIRONMENTS: ()=>external_env_static_provider_js_namespaceObject.DEFAULT_LOCAL_ENVIRONMENTS,
32
+ ENV_STATIC_PROVIDER_NAME: ()=>external_env_static_provider_js_namespaceObject.ENV_STATIC_PROVIDER_NAME,
33
+ createDiscoveryError: ()=>external_validation_js_namespaceObject.createDiscoveryError,
34
+ createEnvStaticSurfaceResolutionProvider: ()=>external_env_static_provider_js_namespaceObject.createEnvStaticSurfaceResolutionProvider,
35
+ formatSurfaceRef: ()=>external_surface_ref_js_namespaceObject.formatSurfaceRef,
36
+ matchDeliveryUnitIdentity: ()=>external_validation_js_namespaceObject.matchDeliveryUnitIdentity,
37
+ parseSurfaceRef: ()=>external_surface_ref_js_namespaceObject.parseSurfaceRef,
38
+ selectResolvedSurface: ()=>external_validation_js_namespaceObject.selectResolvedSurface,
39
+ validateResolvedDeliveryUnit: ()=>external_validation_js_namespaceObject.validateResolvedDeliveryUnit,
40
+ validateSurfaceRef: ()=>external_surface_ref_js_namespaceObject.validateSurfaceRef
41
+ });
42
+ const external_env_static_provider_js_namespaceObject = require("./env-static-provider.js");
43
+ const external_surface_ref_js_namespaceObject = require("./surface-ref.js");
44
+ const external_validation_js_namespaceObject = require("./validation.js");
45
+ exports.DEFAULT_LOCAL_ENVIRONMENTS = __webpack_exports__.DEFAULT_LOCAL_ENVIRONMENTS;
46
+ exports.ENV_STATIC_PROVIDER_NAME = __webpack_exports__.ENV_STATIC_PROVIDER_NAME;
47
+ exports.createDiscoveryError = __webpack_exports__.createDiscoveryError;
48
+ exports.createEnvStaticSurfaceResolutionProvider = __webpack_exports__.createEnvStaticSurfaceResolutionProvider;
49
+ exports.formatSurfaceRef = __webpack_exports__.formatSurfaceRef;
50
+ exports.matchDeliveryUnitIdentity = __webpack_exports__.matchDeliveryUnitIdentity;
51
+ exports.parseSurfaceRef = __webpack_exports__.parseSurfaceRef;
52
+ exports.selectResolvedSurface = __webpack_exports__.selectResolvedSurface;
53
+ exports.validateResolvedDeliveryUnit = __webpack_exports__.validateResolvedDeliveryUnit;
54
+ exports.validateSurfaceRef = __webpack_exports__.validateSurfaceRef;
55
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
56
+ "DEFAULT_LOCAL_ENVIRONMENTS",
57
+ "ENV_STATIC_PROVIDER_NAME",
58
+ "createDiscoveryError",
59
+ "createEnvStaticSurfaceResolutionProvider",
60
+ "formatSurfaceRef",
61
+ "matchDeliveryUnitIdentity",
62
+ "parseSurfaceRef",
63
+ "selectResolvedSurface",
64
+ "validateResolvedDeliveryUnit",
65
+ "validateSurfaceRef"
66
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
67
+ Object.defineProperty(exports, '__esModule', {
68
+ value: true
69
+ });
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ const SEGMENT_PATTERN = /^[A-Za-z0-9._-]+$/;
31
+ const MAJOR_PATTERN = /^v[1-9][0-9]*$/;
32
+ function parseSurfaceRef(input) {
33
+ if ('' === input) return {
34
+ ok: false,
35
+ error: {
36
+ code: 'empty'
37
+ }
38
+ };
39
+ const hashCount = countChar(input, '#');
40
+ if (0 === hashCount) return {
41
+ ok: false,
42
+ error: {
43
+ code: 'missing-surface-separator'
44
+ }
45
+ };
46
+ if (hashCount > 1) return {
47
+ ok: false,
48
+ error: {
49
+ code: 'multiple-surface-separators'
50
+ }
51
+ };
52
+ const hashIndex = input.indexOf('#');
53
+ const unitPart = input.slice(0, hashIndex);
54
+ const rest = input.slice(hashIndex + 1);
55
+ const atIndex = rest.indexOf('@');
56
+ const surfaceId = -1 === atIndex ? rest : rest.slice(0, atIndex);
57
+ const ref = {
58
+ unitId: unitPart,
59
+ surfaceId
60
+ };
61
+ if (-1 !== atIndex) {
62
+ const majorPart = rest.slice(atIndex + 1);
63
+ if ('' === majorPart) return {
64
+ ok: false,
65
+ error: {
66
+ code: 'empty-major'
67
+ }
68
+ };
69
+ if (!MAJOR_PATTERN.test(majorPart)) return {
70
+ ok: false,
71
+ error: {
72
+ code: 'invalid-major',
73
+ value: majorPart
74
+ }
75
+ };
76
+ ref.major = Number(majorPart.slice(1));
77
+ }
78
+ const error = validateSurfaceRef(ref);
79
+ return void 0 === error ? {
80
+ ok: true,
81
+ ref
82
+ } : {
83
+ ok: false,
84
+ error
85
+ };
86
+ }
87
+ function formatSurfaceRef(ref) {
88
+ const error = validateSurfaceRef(ref);
89
+ if (void 0 !== error) throw new TypeError(`Cannot format invalid SurfaceRef: ${error.code}.`);
90
+ const base = `${ref.unitId}#${ref.surfaceId}`;
91
+ return void 0 === ref.major ? base : `${base}@v${ref.major}`;
92
+ }
93
+ function validateSurfaceRef(ref) {
94
+ if ('' === ref.unitId) return {
95
+ code: 'empty-unit-id'
96
+ };
97
+ for (const segment of ref.unitId.split('/'))if (!SEGMENT_PATTERN.test(segment)) return {
98
+ code: 'invalid-unit-id',
99
+ segment
100
+ };
101
+ if ('' === ref.surfaceId) return {
102
+ code: 'empty-surface-id'
103
+ };
104
+ if (!SEGMENT_PATTERN.test(ref.surfaceId)) return {
105
+ code: 'invalid-surface-id'
106
+ };
107
+ if (void 0 !== ref.major && (!Number.isSafeInteger(ref.major) || ref.major < 1)) return {
108
+ code: 'invalid-major',
109
+ value: String(ref.major)
110
+ };
111
+ }
112
+ function countChar(input, char) {
113
+ let count = 0;
114
+ for (const current of input)if (current === char) count += 1;
115
+ return count;
116
+ }
117
+ __webpack_require__.d(__webpack_exports__, {
118
+ formatSurfaceRef: ()=>formatSurfaceRef,
119
+ parseSurfaceRef: ()=>parseSurfaceRef,
120
+ validateSurfaceRef: ()=>validateSurfaceRef
121
+ });
122
+ exports.formatSurfaceRef = __webpack_exports__.formatSurfaceRef;
123
+ exports.parseSurfaceRef = __webpack_exports__.parseSurfaceRef;
124
+ exports.validateSurfaceRef = __webpack_exports__.validateSurfaceRef;
125
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
126
+ "formatSurfaceRef",
127
+ "parseSurfaceRef",
128
+ "validateSurfaceRef"
129
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
130
+ Object.defineProperty(exports, '__esModule', {
131
+ value: true
132
+ });
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });