Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sanity/core-loader

Package Overview
Dependencies
Maintainers
61
Versions
208
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sanity/core-loader - npm Package Compare versions

Comparing version 1.7.0 to 1.7.1-canary.0

298

dist/_chunks-es/transformSanityNodeData.js

@@ -1,1 +0,297 @@

import{getPublishedId as e,studioPath as t}from"@sanity/client/csm";function n(e,t,n,s,r){const i=r&&"input"in r?r.input:n.value,u=r?.expected??e.expects,a=r?.received??function(e){let t=typeof e;return"object"===t&&(t=(e&&Object.getPrototypeOf(e)?.constructor?.name)??"null"),"string"===t?`"${e}"`:"number"===t||"bigint"===t||"boolean"===t?`${e}`:t}(i),o={kind:e.kind,type:e.type,input:i,expected:u,received:a,message:`Invalid ${t}: ${u?`Expected ${u} but r`:"R"}eceived ${a}`,requirement:e.requirement,path:r?.path,issues:r?.issues,lang:s.lang,abortEarly:s.abortEarly,abortPipeEarly:s.abortPipeEarly,skipPipe:s.skipPipe},p="schema"===e.kind,c=e.message??(e.reference,void o.lang)??(p?void o.lang:null)??s.message??void o.lang;c&&(o.message="function"==typeof c?c(o):c),p&&(n.typed=!1),n.issues?n.issues.push(o):n.issues=[o]}function s(e){return"__proto__"!==e&&"prototype"!==e&&"constructor"!==e}function r(e,t){return{kind:"schema",type:"object",reference:r,expects:"Object",async:!1,entries:e,message:t,_run(e,t){const s=e.value;if(s&&"object"==typeof s){e.typed=!0,e.value={};for(const n in this.entries){const r=s[n],i=this.entries[n]._run({typed:!1,value:r},t);if(i.issues){const u={type:"object",origin:"value",input:s,key:n,value:r};for(const t of i.issues)t.path?t.path.unshift(u):t.path=[u],e.issues?.push(t);if(e.issues||(e.issues=i.issues),t.abortEarly){e.typed=!1;break}}i.typed||(e.typed=!1),(void 0!==i.value||n in s)&&(e.value[n]=i.value)}}else n(this,"type",e,t);return e}}}function i(e,...t){const n={kind:"schema",type:"optional",reference:i,expects:`${e.expects} | undefined`,async:!1,wrapped:e,_run(e,t){return void 0===e.value&&("default"in this&&(e.value=function(e,t,n){return"function"==typeof e.default?e.default(t,n):e.default}(this,e,t)),void 0===e.value)?(e.typed=!0,e):this.wrapped._run(e,t)}};return 0 in t&&(n.default=t[0]),n}function u(e){return{kind:"schema",type:"string",reference:u,expects:"string",async:!1,message:e,_run(e,t){return"string"==typeof e.value?e.typed=!0:n(this,"type",e,t),e}}}function a(e){return null!==e&&Array.isArray(e)}function o(e){let t="";for(const n of e)"string"!=typeof n?"number"!=typeof n?a(n)?(t&&(t+=":"),t+=`${n.join(",")}}`):n._key&&(t&&(t+=":"),t+=`${n._key}`):(t&&(t+=":"),t+=`${n}`):(t&&(t+="."),t+=n);return t}const p=function(...e){return{...e[0],pipe:e,_run(t,n){for(let s=0;s<e.length;s++){t=e[s]._run(t,n);const r=e[s+1];if(n.skipPipe||t.issues&&(n.abortEarly||n.abortPipeEarly||"schema"===r?.kind||"transformation"===r?.kind)){t.typed=!1;break}}return t}}}(u(),function e(t,s){return{kind:"validation",type:"min_length",reference:e,async:!1,expects:`>=${t}`,requirement:t,message:s,_run(e,t){return e.typed&&e.value.length<this.requirement&&n(this,"length",e,t,{received:`${e.value.length}`}),e}}}(1)),c=i(p),l=r({baseUrl:p,dataset:c,id:p,path:p,projectId:c,tool:c,type:c,workspace:c,isDraft:i(u())});function y(n){const{id:s,path:r,baseUrl:i,tool:u,workspace:a,type:p}=n;return c=n,l._run({typed:!1,value:c},{abortEarly:!0}).issues?void 0:[["id",e(s)],["type",p],["path",o(t.fromString(r))],["base",encodeURIComponent(i)],["workspace",a],["tool",u],["isDraft",s.startsWith("drafts.")]].filter((([,e])=>!!e)).map((e=>{const[t,n]=e;return!0===n?t:e.join("=")})).join(";");var c}r({origin:p,href:p,data:i(function e(t,r,i){return{kind:"schema",type:"record",reference:e,expects:"Object",async:!1,key:t,value:r,message:i,_run(e,t){const r=e.value;if(r&&"object"==typeof r){e.typed=!0,e.value={};for(const n in r)if(s(n)){const s=r[n],i=this.key._run({typed:!1,value:n},t);if(i.issues){const u={type:"record",origin:"key",input:r,key:n,value:s};for(const t of i.issues)t.path=[u],e.issues?.push(t);if(e.issues||(e.issues=i.issues),t.abortEarly){e.typed=!1;break}}const u=this.value._run({typed:!1,value:s},t);if(u.issues){const i={type:"record",origin:"value",input:r,key:n,value:s};for(const t of u.issues)t.path?t.path.unshift(i):t.path=[i],e.issues?.push(t);if(e.issues||(e.issues=u.issues),t.abortEarly){e.typed=!1;break}}(!i.typed||!u.typed)&&(e.typed=!1),i.typed&&(e.value[i.value]=u.value)}}else n(this,"type",e,t);return e}}}(u(),function e(){return{kind:"schema",type:"unknown",reference:e,expects:"unknown",async:!1,_run:e=>(e.typed=!0,e)}}()))});export{y as z};//# sourceMappingURL=transformSanityNodeData.js.map
import { getPublishedId, studioPath } from "@sanity/client/csm";
var store2;
function getGlobalMessage(lang) {
return store2?.get(lang);
}
var store3;
function getSchemaMessage(lang) {
return store3?.get(lang);
}
var store4;
function getSpecificMessage(reference, lang) {
return store4?.get(reference)?.get(lang);
}
function _stringify(input) {
let type = typeof input;
return type === "object" && (type = (input && Object.getPrototypeOf(input)?.constructor?.name) ?? "null"), type === "string" ? `"${input}"` : type === "number" || type === "bigint" || type === "boolean" ? `${input}` : type;
}
function _addIssue(context, label, dataset, config2, other) {
const input = other && "input" in other ? other.input : dataset.value, expected = other?.expected ?? context.expects, received = other?.received ?? _stringify(input), issue = {
kind: context.kind,
type: context.type,
input,
expected,
received,
message: `Invalid ${label}: ${expected ? `Expected ${expected} but r` : "R"}eceived ${received}`,
// @ts-expect-error
requirement: context.requirement,
path: other?.path,
issues: other?.issues,
lang: config2.lang,
abortEarly: config2.abortEarly,
abortPipeEarly: config2.abortPipeEarly,
skipPipe: config2.skipPipe
}, isSchema = context.kind === "schema", message = (
// @ts-expect-error
context.message ?? getSpecificMessage(context.reference, issue.lang) ?? (isSchema ? getSchemaMessage(issue.lang) : null) ?? config2.message ?? getGlobalMessage(issue.lang)
);
message && (issue.message = typeof message == "function" ? message(issue) : message), isSchema && (dataset.typed = !1), dataset.issues ? dataset.issues.push(issue) : dataset.issues = [issue];
}
function _isAllowedObjectKey(key) {
return key !== "__proto__" && key !== "prototype" && key !== "constructor";
}
function minLength(requirement, message) {
return {
kind: "validation",
type: "min_length",
reference: minLength,
async: !1,
expects: `>=${requirement}`,
requirement,
message,
_run(dataset, config2) {
return dataset.typed && dataset.value.length < this.requirement && _addIssue(this, "length", dataset, config2, {
received: `${dataset.value.length}`
}), dataset;
}
};
}
function getDefault(schema, dataset, config2) {
return typeof schema.default == "function" ? (
// @ts-expect-error
schema.default(dataset, config2)
) : (
// @ts-expect-error
schema.default
);
}
function is(schema, input) {
return !schema._run({ typed: !1, value: input }, { abortEarly: !0 }).issues;
}
function object(entries, message) {
return {
kind: "schema",
type: "object",
reference: object,
expects: "Object",
async: !1,
entries,
message,
_run(dataset, config2) {
const input = dataset.value;
if (input && typeof input == "object") {
dataset.typed = !0, dataset.value = {};
for (const key in this.entries) {
const value2 = input[key], valueDataset = this.entries[key]._run(
{ typed: !1, value: value2 },
config2
);
if (valueDataset.issues) {
const pathItem = {
type: "object",
origin: "value",
input,
key,
value: value2
};
for (const issue of valueDataset.issues)
issue.path ? issue.path.unshift(pathItem) : issue.path = [pathItem], dataset.issues?.push(issue);
if (dataset.issues || (dataset.issues = valueDataset.issues), config2.abortEarly) {
dataset.typed = !1;
break;
}
}
valueDataset.typed || (dataset.typed = !1), (valueDataset.value !== void 0 || key in input) && (dataset.value[key] = valueDataset.value);
}
} else
_addIssue(this, "type", dataset, config2);
return dataset;
}
};
}
function optional(wrapped, ...args) {
const schema = {
kind: "schema",
type: "optional",
reference: optional,
expects: `${wrapped.expects} | undefined`,
async: !1,
wrapped,
_run(dataset, config2) {
return dataset.value === void 0 && ("default" in this && (dataset.value = getDefault(
this,
dataset,
config2
)), dataset.value === void 0) ? (dataset.typed = !0, dataset) : this.wrapped._run(dataset, config2);
}
};
return 0 in args && (schema.default = args[0]), schema;
}
function record(key, value2, message) {
return {
kind: "schema",
type: "record",
reference: record,
expects: "Object",
async: !1,
key,
value: value2,
message,
_run(dataset, config2) {
const input = dataset.value;
if (input && typeof input == "object") {
dataset.typed = !0, dataset.value = {};
for (const entryKey in input)
if (_isAllowedObjectKey(entryKey)) {
const entryValue = input[entryKey], keyDataset = this.key._run(
{ typed: !1, value: entryKey },
config2
);
if (keyDataset.issues) {
const pathItem = {
type: "record",
origin: "key",
input,
key: entryKey,
value: entryValue
};
for (const issue of keyDataset.issues)
issue.path = [pathItem], dataset.issues?.push(issue);
if (dataset.issues || (dataset.issues = keyDataset.issues), config2.abortEarly) {
dataset.typed = !1;
break;
}
}
const valueDataset = this.value._run(
{ typed: !1, value: entryValue },
config2
);
if (valueDataset.issues) {
const pathItem = {
type: "record",
origin: "value",
input,
key: entryKey,
value: entryValue
};
for (const issue of valueDataset.issues)
issue.path ? issue.path.unshift(pathItem) : issue.path = [pathItem], dataset.issues?.push(issue);
if (dataset.issues || (dataset.issues = valueDataset.issues), config2.abortEarly) {
dataset.typed = !1;
break;
}
}
(!keyDataset.typed || !valueDataset.typed) && (dataset.typed = !1), keyDataset.typed && (dataset.value[keyDataset.value] = valueDataset.value);
}
} else
_addIssue(this, "type", dataset, config2);
return dataset;
}
};
}
function string(message) {
return {
kind: "schema",
type: "string",
reference: string,
expects: "string",
async: !1,
message,
_run(dataset, config2) {
return typeof dataset.value == "string" ? dataset.typed = !0 : _addIssue(this, "type", dataset, config2), dataset;
}
};
}
function unknown() {
return {
kind: "schema",
type: "unknown",
reference: unknown,
expects: "unknown",
async: !1,
_run(dataset) {
return dataset.typed = !0, dataset;
}
};
}
function pipe(...pipe2) {
return {
...pipe2[0],
pipe: pipe2,
_run(dataset, config2) {
for (let index = 0; index < pipe2.length; index++) {
dataset = pipe2[index]._run(dataset, config2);
const nextAction = pipe2[index + 1];
if (config2.skipPipe || dataset.issues && (config2.abortEarly || config2.abortPipeEarly || // TODO: This behavior must be documented!
nextAction?.kind === "schema" || nextAction?.kind === "transformation")) {
dataset.typed = !1;
break;
}
}
return dataset;
}
};
}
function isArray(value) {
return value !== null && Array.isArray(value);
}
function pathToUrlString(path) {
let str = "";
for (const segment of path) {
if (typeof segment == "string") {
str && (str += "."), str += segment;
continue;
}
if (typeof segment == "number") {
str && (str += ":"), str += `${segment}`;
continue;
}
if (isArray(segment)) {
str && (str += ":"), str += `${segment.join(",")}}`;
continue;
}
if (segment._key) {
str && (str += ":"), str += `${segment._key}`;
continue;
}
}
return str;
}
const DRAFTS_PREFIX = "drafts.", lengthyStr = pipe(string(), minLength(1)), optionalLengthyStr = optional(lengthyStr), sanityNodeSchema = object({
baseUrl: lengthyStr,
dataset: optionalLengthyStr,
id: lengthyStr,
path: lengthyStr,
projectId: optionalLengthyStr,
tool: optionalLengthyStr,
type: optionalLengthyStr,
workspace: optionalLengthyStr,
isDraft: optional(string())
});
object({
origin: lengthyStr,
href: lengthyStr,
data: optional(record(string(), unknown()))
});
function isValidSanityNode(node) {
return is(sanityNodeSchema, node);
}
function encodeSanityNodeData(node) {
const { id: _id, path, baseUrl, tool, workspace, type } = node;
return isValidSanityNode(node) ? [
["id", getPublishedId(_id)],
["type", type],
["path", pathToUrlString(studioPath.fromString(path))],
["base", encodeURIComponent(baseUrl)],
["workspace", workspace],
["tool", tool],
["isDraft", _id.startsWith(DRAFTS_PREFIX)]
].filter(([, value]) => !!value).map((part) => {
const [key, value] = part;
return value === !0 ? key : part.join("=");
}).join(";") : void 0;
}
export {
encodeSanityNodeData
};
//# sourceMappingURL=transformSanityNodeData.js.map

@@ -1,1 +0,5 @@

import{I as t}from"./_chunks-es/createDataAttribute.js";export{t as createDataAttribute};//# sourceMappingURL=create-data-attribute.js.map
import { createDataAttribute } from "./_chunks-es/createDataAttribute.js";
export {
createDataAttribute
};
//# sourceMappingURL=create-data-attribute.js.map

@@ -1,1 +0,38 @@

import{studioPathToJsonPath as t,resolveEditInfo as r,studioPath as o,jsonPathToStudioPath as s}from"@sanity/client/csm";import{z as e}from"./_chunks-es/transformSanityNodeData.js";const n=(n,a,i,p)=>{if(!a||!i)return;const c=t(p),u=r({resultPath:c,resultSourceMap:a,studioUrl:i});return u?e({baseUrl:u.baseUrl,workspace:u.workspace,tool:u.tool,type:u.type,id:u.id,path:"string"==typeof u.path?u.path:o.toString(s(u.path))}):void 0};function a(t,r,s,e){const i=t=>t?"string"==typeof t?o.fromString(t):t:[],p=i(e);return Object.assign((t=>n(0,r,s,[...p,...i(t)])),{scope:o=>a(t,r,s,[...p,...i(o)])})}export{a as defineEncodeDataAttribute,n as encodeDataAttribute};//# sourceMappingURL=encode-data-attribute.js.map
import { studioPathToJsonPath, resolveEditInfo, studioPath, jsonPathToStudioPath } from "@sanity/client/csm";
import { encodeSanityNodeData } from "./_chunks-es/transformSanityNodeData.js";
const encodeDataAttribute = (result, sourceMap, studioUrl, studioPathLike) => {
if (!sourceMap || !studioUrl)
return;
const resultPath = studioPathToJsonPath(studioPathLike), editInfo = resolveEditInfo({
resultPath,
resultSourceMap: sourceMap,
studioUrl
});
if (editInfo)
return encodeSanityNodeData({
baseUrl: editInfo.baseUrl,
workspace: editInfo.workspace,
tool: editInfo.tool,
type: editInfo.type,
id: editInfo.id,
path: typeof editInfo.path == "string" ? editInfo.path : studioPath.toString(jsonPathToStudioPath(editInfo.path))
});
};
function defineEncodeDataAttribute(result, sourceMap, studioUrl, basePath) {
const parse = (path) => path ? typeof path == "string" ? studioPath.fromString(path) : path : [], parsedBasePath = parse(basePath);
return Object.assign(
(path) => encodeDataAttribute(result, sourceMap, studioUrl, [...parsedBasePath, ...parse(path)]),
// The scope method creates a scoped version of encodeDataAttribute
{
scope: (scope) => defineEncodeDataAttribute(result, sourceMap, studioUrl, [
...parsedBasePath,
...parse(scope)
])
}
);
}
export {
defineEncodeDataAttribute,
encodeDataAttribute
};
//# sourceMappingURL=encode-data-attribute.js.map

@@ -1,1 +0,6 @@

import{c as e,r}from"./_chunks-es/index.js";export{e as createQueryStore,r as runtime};//# sourceMappingURL=index.js.map
import { createQueryStore, runtime } from "./_chunks-es/index.js";
export {
createQueryStore,
runtime
};
//# sourceMappingURL=index.js.map

6

package.json
{
"name": "@sanity/core-loader",
"version": "1.7.0",
"version": "1.7.1-canary.0",
"homepage": "https://github.com/sanity-io/visual-editing/tree/main/packages/core-loader#readme",

@@ -74,7 +74,7 @@ "bugs": {

"vitest": "^2.1.3",
"@repo/package.config": "0.0.0",
"@repo/eslint-config": "0.0.0",
"@repo/package.config": "0.0.0",
"@repo/prettier-config": "0.0.0",
"@repo/visual-editing-helpers": "0.6.22",
"@sanity/comlink": "1.0.0"
"@sanity/comlink": "1.0.1-canary.0"
},

@@ -81,0 +81,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc