@symbo.ls/utils 3.14.707 → 3.14.736
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/CHANGELOG.md +6 -0
- package/dist/cjs/sharedLibraries.js +1 -1
- package/dist/esm/sharedLibraries.js +1 -1
- package/package.json +1 -1
- package/sharedLibraries.js +44 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=Object.defineProperty;var
|
|
1
|
+
"use strict";var u=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var S=(n,t)=>{for(var e in t)u(n,e,{get:t[e],enumerable:!0})},E=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of R(t))!U.call(n,o)&&o!==e&&u(n,o,{get:()=>t[o],enumerable:!(r=j(t,o))||r.enumerable});return n};var O=n=>E(u({},"__esModule",{value:!0}),n);var N={};S(N,{deepDefaults:()=>d,fetchLibraryData:()=>k,isWrappedLibrary:()=>y,mergeSharedLibraries:()=>F,normalizeIgnoreList:()=>p,normalizeLibraryKey:()=>l,resolveSharedLibraries:()=>K,sharedLibrary:()=>C});module.exports=O(N);var a=require("./types.js");const b="system",_="https://smbls-kv.nika-980.workers.dev",P="https://api.symbols.app";function l(n){const t=String(n||"").trim();if(!t)return{owner:b,key:"",full:""};let e=null,r=t;if(t.includes("/")){const s=t.indexOf("/");e=t.slice(0,s),r=t.slice(s+1)}r=r.replace(/\.symbo\.ls$/iu,""),e||(e=b);const o=r?`${e}/${r}`:"";return{owner:e,key:r,full:o}}const d=(n,t,e,r)=>{for(const o in t){const s=r?`${r}/${o}`:o;e&&e.has(s)||(o in n?(0,a.isObject)(n[o])&&(0,a.isObject)(t[o])&&d(n[o],t[o],e,s):n[o]=t[o])}},w=(n,t,e)=>{if(!(0,a.isObject)(n)||!t.size)return n;const r=`${e}/`;let o=!1;for(const i of t)if(i.startsWith(r)){o=!0;break}if(!o)return n;const s={};for(const i in n){if(!Object.prototype.hasOwnProperty.call(n,i))continue;const f=`${e}/${i}`;t.has(f)||(s[i]=w(n[i],t,f))}return s},B=new Set,x=n=>n.replace(/\.js$/iu,""),p=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const e of n){if(!(0,a.isString)(e))continue;const r=e.split("/").map(o=>x(o.trim())).filter(Boolean).join("/");r&&t.add(r)}return t},C=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),y=n=>(0,a.isObject)(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),T=n=>n.library!==void 0?n.library:n.key??n.name,z=(n,t,e)=>{const r=p(t.sharedLibIgnore);t.sharePages===!1&&r.add("pages");const o=r.size?new Set([...e,...r]):e;for(const s in t)if(Object.prototype.hasOwnProperty.call(t,s)&&!(s==="sharePages"||s==="sharedLibIgnore")&&!o.has(s))if((0,a.isObject)(t[s])&&(0,a.isObject)(n[s]))if(s==="designSystem")d(n[s],t[s],o,s);else for(const i in t[s])o.has(`${s}/${i}`)||i in n[s]||(n[s][i]=t[s][i]);else s in n||(n[s]=w(t[s],o,s))},F=(n,t)=>{if(!(!t||!t.length))for(let e=0;e<t.length;e++){let r=t[e],o=B;y(r)&&(o=p(r.ignoreList),r=r.library),(0,a.isObject)(r)&&z(n,r,o)}};async function k(n,t={}){if((t.provider||"kv")==="api")return $(n,t);const r=await G(n,t);return r||$(n,t)}async function G(n,t={}){const e=t.kvBaseUrl||_,r=t.env||"production",o=`${e}/kv/${encodeURIComponent(n)}?env=${r}`;try{const s=await fetch(o,{method:"GET"});return s.ok&&(await s.json())?.value||null}catch{return null}}async function $(n,t={}){const e=t.apiBaseUrl||P,{key:r}=l(n);try{const o=`${e}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,s=await fetch(o,{method:"GET"});if(!s.ok)return null;const i=await s.json(),c=(i?.items||i?.data||(Array.isArray(i)?i:[])).find(v=>{const{key:I}=l(v?.key);return I.toLowerCase()===r.toLowerCase()});if(!c?.id&&!c?._id)return null;const L=c.id||c._id,A=`${e}/core/projects/${encodeURIComponent(L)}/data?branch=main`,h=await fetch(A,{method:"GET"});if(!h.ok)return null;const m=await h.json();return m?.data||m||null}catch{return null}}async function g(n,t={}){if((0,a.isObject)(n))return n;if((0,a.isString)(n)){const{full:e}=l(n);if(!e)return null;try{const r=await k(e,t);return r||console.warn(`[smbls] Shared library "${e}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${e}":`,r.message),null}}return null}async function K(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(y(r)){const o=await g(T(r),t);return o?{library:o,ignoreList:r.ignoreList}:null}return g(r,t)}))).filter(Boolean)}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as a,isString as
|
|
1
|
+
import{isObject as a,isString as p}from"./types.js";const y="system",I="https://smbls-kv.nika-980.workers.dev",j="https://api.symbols.app";function f(n){const t=String(n||"").trim();if(!t)return{owner:y,key:"",full:""};let e=null,r=t;if(t.includes("/")){const o=t.indexOf("/");e=t.slice(0,o),r=t.slice(o+1)}r=r.replace(/\.symbo\.ls$/iu,""),e||(e=y);const s=r?`${e}/${r}`:"";return{owner:e,key:r,full:s}}const h=(n,t,e,r)=>{for(const s in t){const o=r?`${r}/${s}`:s;e&&e.has(o)||(s in n?a(n[s])&&a(t[s])&&h(n[s],t[s],e,o):n[s]=t[s])}},m=(n,t,e)=>{if(!a(n)||!t.size)return n;const r=`${e}/`;let s=!1;for(const i of t)if(i.startsWith(r)){s=!0;break}if(!s)return n;const o={};for(const i in n){if(!Object.prototype.hasOwnProperty.call(n,i))continue;const l=`${e}/${i}`;t.has(l)||(o[i]=m(n[i],t,l))}return o},R=new Set,U=n=>n.replace(/\.js$/iu,""),b=n=>{const t=new Set;if(!Array.isArray(n))return t;for(const e of n){if(!p(e))continue;const r=e.split("/").map(s=>U(s.trim())).filter(Boolean).join("/");r&&t.add(r)}return t},B=(n,t={})=>({library:n,ignoreList:Array.isArray(t.ignoreList)?t.ignoreList:[]}),w=n=>a(n)&&Array.isArray(n.ignoreList)&&("library"in n||"key"in n||"name"in n),S=n=>n.library!==void 0?n.library:n.key??n.name,E=(n,t,e)=>{const r=b(t.sharedLibIgnore);t.sharePages===!1&&r.add("pages");const s=r.size?new Set([...e,...r]):e;for(const o in t)if(Object.prototype.hasOwnProperty.call(t,o)&&!(o==="sharePages"||o==="sharedLibIgnore")&&!s.has(o))if(a(t[o])&&a(n[o]))if(o==="designSystem")h(n[o],t[o],s,o);else for(const i in t[o])s.has(`${o}/${i}`)||i in n[o]||(n[o][i]=t[o][i]);else o in n||(n[o]=m(t[o],s,o))},x=(n,t)=>{if(!(!t||!t.length))for(let e=0;e<t.length;e++){let r=t[e],s=R;w(r)&&(s=b(r.ignoreList),r=r.library),a(r)&&E(n,r,s)}};async function O(n,t={}){if((t.provider||"kv")==="api")return $(n,t);const r=await _(n,t);return r||$(n,t)}async function _(n,t={}){const e=t.kvBaseUrl||I,r=t.env||"production",s=`${e}/kv/${encodeURIComponent(n)}?env=${r}`;try{const o=await fetch(s,{method:"GET"});return o.ok&&(await o.json())?.value||null}catch{return null}}async function $(n,t={}){const e=t.apiBaseUrl||j,{key:r}=f(n);try{const s=`${e}/core/projects/libraries/available?search=${encodeURIComponent(r)}&limit=10`,o=await fetch(s,{method:"GET"});if(!o.ok)return null;const i=await o.json(),c=(i?.items||i?.data||(Array.isArray(i)?i:[])).find(A=>{const{key:v}=f(A?.key);return v.toLowerCase()===r.toLowerCase()});if(!c?.id&&!c?._id)return null;const k=c.id||c._id,L=`${e}/core/projects/${encodeURIComponent(k)}/data?branch=main`,u=await fetch(L,{method:"GET"});if(!u.ok)return null;const d=await u.json();return d?.data||d||null}catch{return null}}async function g(n,t={}){if(a(n))return n;if(p(n)){const{full:e}=f(n);if(!e)return null;try{const r=await O(e,t);return r||console.warn(`[smbls] Shared library "${e}" not found`),r}catch(r){return console.warn(`[smbls] Failed to fetch shared library "${e}":`,r.message),null}}return null}async function C(n,t={}){return!n||!n.length?[]:(await Promise.all(n.map(async r=>{if(w(r)){const s=await g(S(r),t);return s?{library:s,ignoreList:r.ignoreList}:null}return g(r,t)}))).filter(Boolean)}export{h as deepDefaults,O as fetchLibraryData,w as isWrappedLibrary,x as mergeSharedLibraries,b as normalizeIgnoreList,f as normalizeLibraryKey,C as resolveSharedLibraries,B as sharedLibrary};
|
package/package.json
CHANGED
package/sharedLibraries.js
CHANGED
|
@@ -60,6 +60,49 @@ export const deepDefaults = (target, source, ignore, prefix) => {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Recursively drop any subtree of `value` whose '/'-joined path (relative to
|
|
65
|
+
* `prefix`) is in `skip`. Used by `mergeOneLibrary`'s wholesale-copy branch:
|
|
66
|
+
* when the consumer has NO object at all at a top-level key, the whole
|
|
67
|
+
* section is copied in one shot — a nested `sharedLibIgnore` path declared
|
|
68
|
+
* under that key (e.g. 'functions/router') must be honored there too, not
|
|
69
|
+
* only in the per-key defaults-fill branch below. Recurses to whatever depth
|
|
70
|
+
* the ignore path names — `normalizeIgnoreList` has no depth cap, so a
|
|
71
|
+
* library author's declaration stays private regardless of which merge
|
|
72
|
+
* branch a given consumer happens to hit.
|
|
73
|
+
*
|
|
74
|
+
* Returns `value` unchanged (same reference) whenever nothing under `prefix`
|
|
75
|
+
* is ignored — the common case — so this never allocates when there is
|
|
76
|
+
* nothing to filter.
|
|
77
|
+
*
|
|
78
|
+
* @param {*} value - the subtree being wholesale-copied
|
|
79
|
+
* @param {Set<string>} skip - normalized '/'-joined ignore paths (whole-key
|
|
80
|
+
* entries already short-circuited by the caller before this runs)
|
|
81
|
+
* @param {string} prefix - the top-level key this subtree lives under
|
|
82
|
+
*/
|
|
83
|
+
const copyWithNestedIgnores = (value, skip, prefix) => {
|
|
84
|
+
if (!isObject(value) || !skip.size) return value
|
|
85
|
+
|
|
86
|
+
const branchPrefix = `${prefix}/`
|
|
87
|
+
let hasNestedIgnore = false
|
|
88
|
+
for (const path of skip) {
|
|
89
|
+
if (path.startsWith(branchPrefix)) {
|
|
90
|
+
hasNestedIgnore = true
|
|
91
|
+
break
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (!hasNestedIgnore) return value
|
|
95
|
+
|
|
96
|
+
const copy = {}
|
|
97
|
+
for (const k in value) {
|
|
98
|
+
if (!Object.prototype.hasOwnProperty.call(value, k)) continue
|
|
99
|
+
const path = `${prefix}/${k}`
|
|
100
|
+
if (skip.has(path)) continue
|
|
101
|
+
copy[k] = copyWithNestedIgnores(value[k], skip, path)
|
|
102
|
+
}
|
|
103
|
+
return copy
|
|
104
|
+
}
|
|
105
|
+
|
|
63
106
|
const EMPTY_IGNORE = new Set()
|
|
64
107
|
|
|
65
108
|
const stripJsExt = (segment) => segment.replace(/\.js$/iu, '')
|
|
@@ -151,7 +194,7 @@ const mergeOneLibrary = (context, sharedLib, ignore) => {
|
|
|
151
194
|
}
|
|
152
195
|
}
|
|
153
196
|
} else if (!(key in context)) {
|
|
154
|
-
context[key] = sharedLib[key]
|
|
197
|
+
context[key] = copyWithNestedIgnores(sharedLib[key], skip, key)
|
|
155
198
|
}
|
|
156
199
|
}
|
|
157
200
|
}
|