@sanity/client 6.7.0 → 6.7.1-canary.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/csm.cjs +177 -0
- package/dist/csm.cjs.map +1 -0
- package/dist/csm.d.ts +129 -0
- package/dist/csm.js +168 -0
- package/dist/csm.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +28 -14
- package/src/csm/editIntent.ts +42 -0
- package/src/csm/index.ts +20 -0
- package/src/csm/jsonpath.test.ts +40 -0
- package/src/csm/jsonpath.ts +89 -0
- package/src/csm/mapToEditLinks.test.ts +103 -0
- package/src/csm/mapToEditLinks.ts +11 -0
- package/src/csm/sourcemap.test.ts +212 -0
- package/src/csm/sourcemap.ts +127 -0
- package/src/csm/types.ts +8 -0
- package/umd/sanityClient.js +5 -42
- package/umd/sanityClient.min.js +3 -3
package/dist/csm.cjs
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
const ESCAPE = {
|
|
7
|
+
"\f": "\\f",
|
|
8
|
+
"\n": "\\n",
|
|
9
|
+
"\r": "\\r",
|
|
10
|
+
" ": "\\t",
|
|
11
|
+
"'": "\\'",
|
|
12
|
+
"\\": "\\\\"
|
|
13
|
+
};
|
|
14
|
+
const UNESCAPE = {
|
|
15
|
+
"\\f": "\f",
|
|
16
|
+
"\\n": "\n",
|
|
17
|
+
"\\r": "\r",
|
|
18
|
+
"\\t": " ",
|
|
19
|
+
"\\'": "'",
|
|
20
|
+
"\\\\": "\\"
|
|
21
|
+
};
|
|
22
|
+
function jsonPath(path, opts) {
|
|
23
|
+
return "$".concat(path.map(segment => {
|
|
24
|
+
if (typeof segment === "string") {
|
|
25
|
+
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, match => {
|
|
26
|
+
return ESCAPE[match];
|
|
27
|
+
});
|
|
28
|
+
return "['".concat(escapedKey, "']");
|
|
29
|
+
}
|
|
30
|
+
if (typeof segment === "number") {
|
|
31
|
+
return "[".concat(segment, "]");
|
|
32
|
+
}
|
|
33
|
+
if ((opts == null ? void 0 : opts.keyArraySelectors) && segment.key !== "") {
|
|
34
|
+
const escapedKey = segment.key.replace(/['\\]/g, match => {
|
|
35
|
+
return ESCAPE[match];
|
|
36
|
+
});
|
|
37
|
+
return "[?(@._key=='".concat(escapedKey, "')]");
|
|
38
|
+
}
|
|
39
|
+
return "[".concat(segment.index, "]");
|
|
40
|
+
}).join(""));
|
|
41
|
+
}
|
|
42
|
+
function parseJsonPath(path) {
|
|
43
|
+
const parsed = [];
|
|
44
|
+
const parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
|
|
45
|
+
let match;
|
|
46
|
+
while ((match = parseRe.exec(path)) !== null) {
|
|
47
|
+
if (match[1] !== void 0) {
|
|
48
|
+
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, m => {
|
|
49
|
+
return UNESCAPE[m];
|
|
50
|
+
});
|
|
51
|
+
parsed.push(key);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (match[2] !== void 0) {
|
|
55
|
+
parsed.push(parseInt(match[2], 10));
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (match[3] !== void 0) {
|
|
59
|
+
const key = match[3].replace(/\\(\\')/g, m => {
|
|
60
|
+
return UNESCAPE[m];
|
|
61
|
+
});
|
|
62
|
+
parsed.push({
|
|
63
|
+
key,
|
|
64
|
+
index: -1
|
|
65
|
+
});
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
function defineEditLink(_studioUrl) {
|
|
72
|
+
const studioUrl = _studioUrl.replace(/\/$/, "");
|
|
73
|
+
return (_ref, path) => {
|
|
74
|
+
let {
|
|
75
|
+
_id,
|
|
76
|
+
_type
|
|
77
|
+
} = _ref;
|
|
78
|
+
return "".concat(studioUrl, "/intent/edit/id=").concat(_id, ";type=").concat(_type, ";path=").concat(encodeJsonPathToUriComponent(path));
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function encodeJsonPathToUriComponent(path) {
|
|
82
|
+
const sourcePath = Array.isArray(path) ? path : parseJsonPath(path);
|
|
83
|
+
return encodeURIComponent(sourcePath.map((key, i) =>
|
|
84
|
+
// eslint-disable-next-line no-nested-ternary
|
|
85
|
+
typeof key === "number" ? "[".concat(key, "]") : i > 0 ? ".".concat(key) : key).join(""));
|
|
86
|
+
}
|
|
87
|
+
function isRecord(value) {
|
|
88
|
+
return typeof value === "object" && value !== null;
|
|
89
|
+
}
|
|
90
|
+
function isArray(value) {
|
|
91
|
+
return value !== null && Array.isArray(value);
|
|
92
|
+
}
|
|
93
|
+
function encodeIntoResult(result, csm, encoder, options) {
|
|
94
|
+
return walkMap(result, (value, path) => {
|
|
95
|
+
if (typeof value !== "string") {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
const resolveMappingResult = resolveMapping(path, csm);
|
|
99
|
+
if (!resolveMappingResult) {
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
const [mapping, matchedPath, pathSuffix] = resolveMappingResult;
|
|
103
|
+
if (mapping.type !== "value") {
|
|
104
|
+
return value;
|
|
105
|
+
}
|
|
106
|
+
if (mapping.source.type !== "documentValue") {
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
const sourceDocument =
|
|
110
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
111
|
+
csm.documents[mapping.source.document];
|
|
112
|
+
const sourcePath = csm.paths[mapping.source.path];
|
|
113
|
+
if (options == null ? void 0 : options.keyArraySelectors) {
|
|
114
|
+
const matchPathSegments = parseJsonPath(matchedPath);
|
|
115
|
+
const sourcePathSegments = parseJsonPath(sourcePath);
|
|
116
|
+
const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length));
|
|
117
|
+
return encoder(value, sourceDocument, fullSourceSegments);
|
|
118
|
+
}
|
|
119
|
+
return encoder(value, sourceDocument, parseJsonPath(sourcePath + pathSuffix));
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function walkMap(value, mappingFn) {
|
|
123
|
+
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
124
|
+
if (isArray(value)) {
|
|
125
|
+
return value.map((v, idx) => {
|
|
126
|
+
if (isRecord(v)) {
|
|
127
|
+
const key = v["_key"];
|
|
128
|
+
if (typeof key === "string") {
|
|
129
|
+
return walkMap(v, mappingFn, path.concat({
|
|
130
|
+
key,
|
|
131
|
+
index: idx
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return walkMap(v, mappingFn, path.concat(idx));
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
if (isRecord(value)) {
|
|
139
|
+
return Object.fromEntries(Object.entries(value).map(_ref2 => {
|
|
140
|
+
let [k, v] = _ref2;
|
|
141
|
+
return [k, walkMap(v, mappingFn, path.concat(k))];
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
return mappingFn(value, path);
|
|
145
|
+
}
|
|
146
|
+
function resolveMapping(resultPath, csm) {
|
|
147
|
+
const resultJsonPath = jsonPath(resultPath);
|
|
148
|
+
if (csm.mappings[resultJsonPath] !== void 0) {
|
|
149
|
+
return [csm.mappings[resultJsonPath], resultJsonPath, ""];
|
|
150
|
+
}
|
|
151
|
+
const mappings = Object.entries(csm.mappings).filter(_ref3 => {
|
|
152
|
+
let [key] = _ref3;
|
|
153
|
+
return resultJsonPath.startsWith(key);
|
|
154
|
+
}).sort((_ref4, _ref5) => {
|
|
155
|
+
let [key1] = _ref4;
|
|
156
|
+
let [key2] = _ref5;
|
|
157
|
+
return key2.length - key1.length;
|
|
158
|
+
});
|
|
159
|
+
if (mappings.length == 0) {
|
|
160
|
+
return void 0;
|
|
161
|
+
}
|
|
162
|
+
const [matchedPath, mapping] = mappings[0];
|
|
163
|
+
const pathSuffix = resultJsonPath.substring(matchedPath.length);
|
|
164
|
+
return [mapping, matchedPath, pathSuffix];
|
|
165
|
+
}
|
|
166
|
+
function mapToEditLinks(result, csm, studioUrl) {
|
|
167
|
+
const createEditLink = defineEditLink(studioUrl);
|
|
168
|
+
return encodeIntoResult(result, csm, (_, sourceDocument, path) => {
|
|
169
|
+
return createEditLink(sourceDocument, path);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
exports.encodeJsonPathToUriComponent = encodeJsonPathToUriComponent;
|
|
173
|
+
exports.jsonPath = jsonPath;
|
|
174
|
+
exports.mapToEditLinks = mapToEditLinks;
|
|
175
|
+
exports.resolveMapping = resolveMapping;
|
|
176
|
+
exports.walkMap = walkMap;
|
|
177
|
+
//# sourceMappingURL=csm.cjs.map
|
package/dist/csm.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csm.cjs","sources":["../src/csm/jsonpath.ts","../src/csm/editIntent.ts","../src/csm/sourcemap.ts","../src/csm/mapToEditLinks.ts"],"sourcesContent":["import type { PathSegment } from './types'\n\nconst ESCAPE: Record<string, string> = {\n '\\f': '\\\\f',\n '\\n': '\\\\n',\n '\\r': '\\\\r',\n '\\t': '\\\\t',\n \"'\": \"\\\\'\",\n '\\\\': '\\\\\\\\',\n}\n\nconst UNESCAPE: Record<string, string> = {\n '\\\\f': '\\f',\n '\\\\n': '\\n',\n '\\\\r': '\\r',\n '\\\\t': '\\t',\n \"\\\\'\": \"'\",\n '\\\\\\\\': '\\\\',\n}\n\n/** @internal */\nexport function jsonPath(\n path: PathSegment[],\n opts?: {\n keyArraySelectors: boolean\n },\n): string {\n return `$${path\n .map((segment) => {\n if (typeof segment === 'string') {\n const escapedKey = segment.replace(/[\\f\\n\\r\\t'\\\\]/g, (match) => {\n return ESCAPE[match]\n })\n return `['${escapedKey}']`\n }\n\n if (typeof segment === 'number') {\n return `[${segment}]`\n }\n\n if (opts?.keyArraySelectors && segment.key !== '') {\n const escapedKey = segment.key.replace(/['\\\\]/g, (match) => {\n return ESCAPE[match]\n })\n return `[?(@._key=='${escapedKey}')]`\n }\n\n return `[${segment.index}]`\n })\n .join('')}`\n}\n\n/** @internal */\nexport function parseJsonPath(path: string): PathSegment[] {\n const parsed: PathSegment[] = []\n\n const parseRe = /\\['(.*?)'\\]|\\[(\\d+)\\]|\\[\\?\\(@\\._key=='(.*?)'\\)\\]/g\n let match: RegExpExecArray | null\n\n while ((match = parseRe.exec(path)) !== null) {\n if (match[1] !== undefined) {\n const key = match[1].replace(/\\\\(\\\\|f|n|r|t|')/g, (m) => {\n return UNESCAPE[m]\n })\n\n parsed.push(key)\n continue\n }\n\n if (match[2] !== undefined) {\n parsed.push(parseInt(match[2], 10))\n continue\n }\n\n if (match[3] !== undefined) {\n const key = match[3].replace(/\\\\(\\\\')/g, (m) => {\n return UNESCAPE[m]\n })\n\n parsed.push({\n key,\n index: -1,\n })\n continue\n }\n }\n\n return parsed\n}\n","import {ContentSourceMapDocument, ContentSourceMapDocuments} from '../types'\nimport {parseJsonPath} from './jsonpath'\nimport type {PathSegment, StudioUrl} from './types'\n\n/** @alpha */\nexport type EditLink = `/intent/edit/id=${string};type=${string};path=${string}`\n\n/** @alpha */\nexport interface EditLinkProps {\n studioUrl: StudioUrl\n document: ContentSourceMapDocument\n}\n\n/** @alpha */\nexport type DefineEditLink = (\n studioUrl: StudioUrl,\n) => (sourceDocument: ContentSourceMapDocuments[number]) => `${StudioUrl}${EditLink}`\n\n/** @alpha */\nexport function defineEditLink(\n _studioUrl: StudioUrl,\n): (\n sourceDocument: ContentSourceMapDocuments[number],\n path: string | PathSegment[],\n) => `${StudioUrl}${EditLink}` {\n const studioUrl = _studioUrl.replace(/\\/$/, '')\n return ({_id, _type}, path) =>\n `${studioUrl}/intent/edit/id=${_id};type=${_type};path=${encodeJsonPathToUriComponent(path)}`\n}\n\n/** @alpha */\nexport function encodeJsonPathToUriComponent(path: string | PathSegment[]): string {\n const sourcePath = Array.isArray(path) ? path : parseJsonPath(path)\n return encodeURIComponent(\n sourcePath\n .map((key, i) =>\n // eslint-disable-next-line no-nested-ternary\n typeof key === 'number' ? `[${key}]` : i > 0 ? `.${key}` : key,\n )\n .join(''),\n )\n}\n","import type {ContentSourceMap, ContentSourceMapDocuments, ContentSourceMapMapping} from '../types'\nimport {jsonPath, parseJsonPath} from './jsonpath'\nimport type {PathSegment} from './types'\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\n}\n\nfunction isArray(value: unknown): value is Array<unknown> {\n return value !== null && Array.isArray(value)\n}\n\n/** @alpha */\nexport type Encoder<E> = (\n value: string,\n sourceDocument: ContentSourceMapDocuments[number],\n path: PathSegment[],\n) => E\n\n/** @alpha */\nexport function encode<R, E>(\n result: R,\n csm: ContentSourceMap,\n encoder: Encoder<E>,\n options?: {keyArraySelectors: boolean},\n): R {\n return encodeIntoResult(result, csm, encoder, options) as R\n}\n\n/** @alpha */\nexport function encodeIntoResult<R>(\n result: R,\n csm: ContentSourceMap,\n encoder: Encoder<unknown>,\n options?: {keyArraySelectors: boolean},\n): ReturnType<Encoder<unknown>> {\n return walkMap(result, (value, path) => {\n // Only map strings, we could extend this in the future to support other types like integers...\n if (typeof value !== 'string') {\n return value\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const resolveMappingResult = resolveMapping(path, csm)\n if (!resolveMappingResult) {\n return value\n }\n\n const [mapping, matchedPath, pathSuffix] = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n csm.documents[mapping.source.document!]\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const sourcePath = csm.paths[mapping.source.path]\n\n if (options?.keyArraySelectors) {\n const matchPathSegments = parseJsonPath(matchedPath)\n const sourcePathSegments = parseJsonPath(sourcePath)\n const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length))\n\n return encoder(value, sourceDocument, fullSourceSegments)\n }\n\n return encoder(value, sourceDocument, parseJsonPath(sourcePath + pathSuffix))\n })\n}\n\n/** @alpha */\nexport type WalkMapFn = (value: unknown, path: PathSegment[]) => unknown\n\n/** generic way to walk a nested object or array and apply a mapping function to each value\n * @alpha\n */\nexport function walkMap(value: unknown, mappingFn: WalkMapFn, path: PathSegment[] = []): unknown {\n if (isArray(value)) {\n return value.map((v, idx) => {\n if (isRecord(v)) {\n const key = v['_key']\n if (typeof key === 'string') {\n return walkMap(v, mappingFn, path.concat({key, index: idx}))\n }\n }\n\n return walkMap(v, mappingFn, path.concat(idx))\n })\n }\n\n if (isRecord(value)) {\n return Object.fromEntries(\n Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))]),\n )\n }\n\n return mappingFn(value, path)\n}\n\n/** @alpha */\nexport function resolveMapping(\n resultPath: PathSegment[],\n csm: ContentSourceMap,\n): [ContentSourceMapMapping, string, string] | undefined {\n const resultJsonPath = jsonPath(resultPath)\n\n if (csm.mappings[resultJsonPath] !== undefined) {\n return [csm.mappings[resultJsonPath], resultJsonPath, '']\n }\n\n const mappings = Object.entries(csm.mappings)\n .filter(([key]) => resultJsonPath.startsWith(key))\n .sort(([key1], [key2]) => key2.length - key1.length)\n\n if (mappings.length == 0) {\n return undefined\n }\n\n const [matchedPath, mapping] = mappings[0]\n const pathSuffix = resultJsonPath.substring(matchedPath.length)\n return [mapping, matchedPath, pathSuffix]\n}\n","import type {ContentSourceMap} from '../types'\nimport {defineEditLink} from './editIntent'\nimport {encodeIntoResult} from './sourcemap'\n\n/** @alpha */\nexport function mapToEditLinks<R>(result: R, csm: ContentSourceMap, studioUrl: string): R {\n const createEditLink = defineEditLink(studioUrl)\n return encodeIntoResult(result, csm, (_, sourceDocument, path) => {\n return createEditLink(sourceDocument, path)\n }) as R\n}\n"],"names":["ESCAPE","UNESCAPE","jsonPath","path","opts","concat","map","segment","escapedKey","replace","match","keyArraySelectors","key","index","join","parseJsonPath","parsed","parseRe","exec","m","push","parseInt","defineEditLink","_studioUrl","studioUrl","_ref","_id","_type","encodeJsonPathToUriComponent","sourcePath","Array","isArray","encodeURIComponent","i","isRecord","value","encodeIntoResult","result","csm","encoder","options","walkMap","resolveMappingResult","resolveMapping","mapping","matchedPath","pathSuffix","type","source","sourceDocument","documents","document","paths","matchPathSegments","sourcePathSegments","fullSourceSegments","slice","length","mappingFn","arguments","undefined","v","idx","Object","fromEntries","entries","_ref2","k","resultPath","resultJsonPath","mappings","filter","_ref3","startsWith","sort","_ref4","_ref5","key1","key2","substring","mapToEditLinks","createEditLink","_"],"mappings":";;;;;AAEA,MAAMA,MAAiC,GAAA;EACrC,IAAM,EAAA,KAAA;EACN,IAAM,EAAA,KAAA;EACN,IAAM,EAAA,KAAA;EACN,GAAM,EAAA,KAAA;EACN,GAAK,EAAA,KAAA;EACL,IAAM,EAAA;AACR,CAAA;AAEA,MAAMC,QAAmC,GAAA;EACvC,KAAO,EAAA,IAAA;EACP,KAAO,EAAA,IAAA;EACP,KAAO,EAAA,IAAA;EACP,KAAO,EAAA,GAAA;EACP,KAAO,EAAA,GAAA;EACP,MAAQ,EAAA;AACV,CAAA;AAGgB,SAAAC,QAAAA,CACdC,MACAC,IAGQ,EAAA;EACR,OAAO,GAAI,CAAAC,MAAA,CAAAF,IAAA,CACRG,GAAI,CAACC,OAAY,IAAA;IACZ,IAAA,OAAOA,YAAY,QAAU,EAAA;MAC/B,MAAMC,UAAa,GAAAD,OAAA,CAAQE,OAAQ,CAAA,gBAAA,EAAmBC,KAAU,IAAA;QAC9D,OAAOV,OAAOU,KAAK,CAAA;MAAA,CACpB,CAAA;MACD,OAAO,KAAKL,MAAU,CAAAG,UAAA,EAAA,IAAA,CAAA;IACxB;IAEI,IAAA,OAAOD,YAAY,QAA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
|
4
|
+
export declare interface ContentSourceMap {
|
|
5
|
+
mappings: ContentSourceMapMappings
|
|
6
|
+
documents: ContentSourceMapDocuments
|
|
7
|
+
paths: ContentSourceMapPaths
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** @public */
|
|
11
|
+
export declare interface ContentSourceMapDocument extends ContentSourceMapDocumentBase {
|
|
12
|
+
_projectId?: undefined
|
|
13
|
+
_dataset?: undefined
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** @public */
|
|
17
|
+
export declare interface ContentSourceMapDocumentBase {
|
|
18
|
+
_id: string
|
|
19
|
+
_type: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** @public */
|
|
23
|
+
export declare type ContentSourceMapDocuments = (
|
|
24
|
+
| ContentSourceMapDocument
|
|
25
|
+
| ContentSourceMapRemoteDocument
|
|
26
|
+
)[]
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* DocumentValueSource is a path to a value within a document
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
export declare interface ContentSourceMapDocumentValueSource {
|
|
33
|
+
type: 'documentValue'
|
|
34
|
+
document: number
|
|
35
|
+
path: number
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* When a value is not from a source, its a literal
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare interface ContentSourceMapLiteralSource {
|
|
43
|
+
type: 'literal'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @public */
|
|
47
|
+
export declare type ContentSourceMapMapping = ContentSourceMapValueMapping
|
|
48
|
+
|
|
49
|
+
/** @public */
|
|
50
|
+
export declare type ContentSourceMapMappings = Record<string, ContentSourceMapMapping>
|
|
51
|
+
|
|
52
|
+
/** @public */
|
|
53
|
+
export declare type ContentSourceMapPaths = string[]
|
|
54
|
+
|
|
55
|
+
/** @public */
|
|
56
|
+
export declare interface ContentSourceMapRemoteDocument extends ContentSourceMapDocumentBase {
|
|
57
|
+
_projectId: string
|
|
58
|
+
_dataset: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @public */
|
|
62
|
+
export declare type ContentSourceMapSource =
|
|
63
|
+
| ContentSourceMapDocumentValueSource
|
|
64
|
+
| ContentSourceMapLiteralSource
|
|
65
|
+
| ContentSourceMapUnknownSource
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* When a field source is unknown
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export declare interface ContentSourceMapUnknownSource {
|
|
72
|
+
type: 'unknown'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* ValueMapping is a mapping when for value that is from a single source value
|
|
77
|
+
* It may refer to a field within a document or a literal value
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
export declare interface ContentSourceMapValueMapping {
|
|
81
|
+
type: 'value'
|
|
82
|
+
source: ContentSourceMapSource
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** @alpha */
|
|
86
|
+
export declare function encodeJsonPathToUriComponent(path: string | PathSegment[]): string
|
|
87
|
+
|
|
88
|
+
/** @internal */
|
|
89
|
+
export declare function jsonPath(
|
|
90
|
+
path: PathSegment[],
|
|
91
|
+
opts?: {
|
|
92
|
+
keyArraySelectors: boolean
|
|
93
|
+
},
|
|
94
|
+
): string
|
|
95
|
+
|
|
96
|
+
/** @public */
|
|
97
|
+
export declare type KeyedSegment = {
|
|
98
|
+
key: string
|
|
99
|
+
index: number
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** @alpha */
|
|
103
|
+
export declare function mapToEditLinks<R>(result: R, csm: ContentSourceMap, studioUrl: string): R
|
|
104
|
+
|
|
105
|
+
/** @public */
|
|
106
|
+
export declare type PathSegment = string | number | KeyedSegment
|
|
107
|
+
|
|
108
|
+
/** @alpha */
|
|
109
|
+
export declare function resolveMapping(
|
|
110
|
+
resultPath: PathSegment[],
|
|
111
|
+
csm: ContentSourceMap,
|
|
112
|
+
): [ContentSourceMapMapping, string, string] | undefined
|
|
113
|
+
|
|
114
|
+
/** @public */
|
|
115
|
+
export declare type StudioUrl =
|
|
116
|
+
| `/${string}`
|
|
117
|
+
| `${string}.sanity.studio`
|
|
118
|
+
| `https://${string}`
|
|
119
|
+
| string
|
|
120
|
+
|
|
121
|
+
/** generic way to walk a nested object or array and apply a mapping function to each value
|
|
122
|
+
* @alpha
|
|
123
|
+
*/
|
|
124
|
+
export declare function walkMap(value: unknown, mappingFn: WalkMapFn, path?: PathSegment[]): unknown
|
|
125
|
+
|
|
126
|
+
/** @alpha */
|
|
127
|
+
export declare type WalkMapFn = (value: unknown, path: PathSegment[]) => unknown
|
|
128
|
+
|
|
129
|
+
export {}
|
package/dist/csm.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
const ESCAPE = {
|
|
2
|
+
"\f": "\\f",
|
|
3
|
+
"\n": "\\n",
|
|
4
|
+
"\r": "\\r",
|
|
5
|
+
" ": "\\t",
|
|
6
|
+
"'": "\\'",
|
|
7
|
+
"\\": "\\\\"
|
|
8
|
+
};
|
|
9
|
+
const UNESCAPE = {
|
|
10
|
+
"\\f": "\f",
|
|
11
|
+
"\\n": "\n",
|
|
12
|
+
"\\r": "\r",
|
|
13
|
+
"\\t": " ",
|
|
14
|
+
"\\'": "'",
|
|
15
|
+
"\\\\": "\\"
|
|
16
|
+
};
|
|
17
|
+
function jsonPath(path, opts) {
|
|
18
|
+
return "$".concat(path.map(segment => {
|
|
19
|
+
if (typeof segment === "string") {
|
|
20
|
+
const escapedKey = segment.replace(/[\f\n\r\t'\\]/g, match => {
|
|
21
|
+
return ESCAPE[match];
|
|
22
|
+
});
|
|
23
|
+
return "['".concat(escapedKey, "']");
|
|
24
|
+
}
|
|
25
|
+
if (typeof segment === "number") {
|
|
26
|
+
return "[".concat(segment, "]");
|
|
27
|
+
}
|
|
28
|
+
if ((opts == null ? void 0 : opts.keyArraySelectors) && segment.key !== "") {
|
|
29
|
+
const escapedKey = segment.key.replace(/['\\]/g, match => {
|
|
30
|
+
return ESCAPE[match];
|
|
31
|
+
});
|
|
32
|
+
return "[?(@._key=='".concat(escapedKey, "')]");
|
|
33
|
+
}
|
|
34
|
+
return "[".concat(segment.index, "]");
|
|
35
|
+
}).join(""));
|
|
36
|
+
}
|
|
37
|
+
function parseJsonPath(path) {
|
|
38
|
+
const parsed = [];
|
|
39
|
+
const parseRe = /\['(.*?)'\]|\[(\d+)\]|\[\?\(@\._key=='(.*?)'\)\]/g;
|
|
40
|
+
let match;
|
|
41
|
+
while ((match = parseRe.exec(path)) !== null) {
|
|
42
|
+
if (match[1] !== void 0) {
|
|
43
|
+
const key = match[1].replace(/\\(\\|f|n|r|t|')/g, m => {
|
|
44
|
+
return UNESCAPE[m];
|
|
45
|
+
});
|
|
46
|
+
parsed.push(key);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (match[2] !== void 0) {
|
|
50
|
+
parsed.push(parseInt(match[2], 10));
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (match[3] !== void 0) {
|
|
54
|
+
const key = match[3].replace(/\\(\\')/g, m => {
|
|
55
|
+
return UNESCAPE[m];
|
|
56
|
+
});
|
|
57
|
+
parsed.push({
|
|
58
|
+
key,
|
|
59
|
+
index: -1
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return parsed;
|
|
65
|
+
}
|
|
66
|
+
function defineEditLink(_studioUrl) {
|
|
67
|
+
const studioUrl = _studioUrl.replace(/\/$/, "");
|
|
68
|
+
return (_ref, path) => {
|
|
69
|
+
let {
|
|
70
|
+
_id,
|
|
71
|
+
_type
|
|
72
|
+
} = _ref;
|
|
73
|
+
return "".concat(studioUrl, "/intent/edit/id=").concat(_id, ";type=").concat(_type, ";path=").concat(encodeJsonPathToUriComponent(path));
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function encodeJsonPathToUriComponent(path) {
|
|
77
|
+
const sourcePath = Array.isArray(path) ? path : parseJsonPath(path);
|
|
78
|
+
return encodeURIComponent(sourcePath.map((key, i) =>
|
|
79
|
+
// eslint-disable-next-line no-nested-ternary
|
|
80
|
+
typeof key === "number" ? "[".concat(key, "]") : i > 0 ? ".".concat(key) : key).join(""));
|
|
81
|
+
}
|
|
82
|
+
function isRecord(value) {
|
|
83
|
+
return typeof value === "object" && value !== null;
|
|
84
|
+
}
|
|
85
|
+
function isArray(value) {
|
|
86
|
+
return value !== null && Array.isArray(value);
|
|
87
|
+
}
|
|
88
|
+
function encodeIntoResult(result, csm, encoder, options) {
|
|
89
|
+
return walkMap(result, (value, path) => {
|
|
90
|
+
if (typeof value !== "string") {
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
const resolveMappingResult = resolveMapping(path, csm);
|
|
94
|
+
if (!resolveMappingResult) {
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
const [mapping, matchedPath, pathSuffix] = resolveMappingResult;
|
|
98
|
+
if (mapping.type !== "value") {
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
if (mapping.source.type !== "documentValue") {
|
|
102
|
+
return value;
|
|
103
|
+
}
|
|
104
|
+
const sourceDocument =
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
106
|
+
csm.documents[mapping.source.document];
|
|
107
|
+
const sourcePath = csm.paths[mapping.source.path];
|
|
108
|
+
if (options == null ? void 0 : options.keyArraySelectors) {
|
|
109
|
+
const matchPathSegments = parseJsonPath(matchedPath);
|
|
110
|
+
const sourcePathSegments = parseJsonPath(sourcePath);
|
|
111
|
+
const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length));
|
|
112
|
+
return encoder(value, sourceDocument, fullSourceSegments);
|
|
113
|
+
}
|
|
114
|
+
return encoder(value, sourceDocument, parseJsonPath(sourcePath + pathSuffix));
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function walkMap(value, mappingFn) {
|
|
118
|
+
let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
119
|
+
if (isArray(value)) {
|
|
120
|
+
return value.map((v, idx) => {
|
|
121
|
+
if (isRecord(v)) {
|
|
122
|
+
const key = v["_key"];
|
|
123
|
+
if (typeof key === "string") {
|
|
124
|
+
return walkMap(v, mappingFn, path.concat({
|
|
125
|
+
key,
|
|
126
|
+
index: idx
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return walkMap(v, mappingFn, path.concat(idx));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
if (isRecord(value)) {
|
|
134
|
+
return Object.fromEntries(Object.entries(value).map(_ref2 => {
|
|
135
|
+
let [k, v] = _ref2;
|
|
136
|
+
return [k, walkMap(v, mappingFn, path.concat(k))];
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
return mappingFn(value, path);
|
|
140
|
+
}
|
|
141
|
+
function resolveMapping(resultPath, csm) {
|
|
142
|
+
const resultJsonPath = jsonPath(resultPath);
|
|
143
|
+
if (csm.mappings[resultJsonPath] !== void 0) {
|
|
144
|
+
return [csm.mappings[resultJsonPath], resultJsonPath, ""];
|
|
145
|
+
}
|
|
146
|
+
const mappings = Object.entries(csm.mappings).filter(_ref3 => {
|
|
147
|
+
let [key] = _ref3;
|
|
148
|
+
return resultJsonPath.startsWith(key);
|
|
149
|
+
}).sort((_ref4, _ref5) => {
|
|
150
|
+
let [key1] = _ref4;
|
|
151
|
+
let [key2] = _ref5;
|
|
152
|
+
return key2.length - key1.length;
|
|
153
|
+
});
|
|
154
|
+
if (mappings.length == 0) {
|
|
155
|
+
return void 0;
|
|
156
|
+
}
|
|
157
|
+
const [matchedPath, mapping] = mappings[0];
|
|
158
|
+
const pathSuffix = resultJsonPath.substring(matchedPath.length);
|
|
159
|
+
return [mapping, matchedPath, pathSuffix];
|
|
160
|
+
}
|
|
161
|
+
function mapToEditLinks(result, csm, studioUrl) {
|
|
162
|
+
const createEditLink = defineEditLink(studioUrl);
|
|
163
|
+
return encodeIntoResult(result, csm, (_, sourceDocument, path) => {
|
|
164
|
+
return createEditLink(sourceDocument, path);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
export { encodeJsonPathToUriComponent, jsonPath, mapToEditLinks, resolveMapping, walkMap };
|
|
168
|
+
//# sourceMappingURL=csm.js.map
|
package/dist/csm.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csm.js","sources":["../src/csm/jsonpath.ts","../src/csm/editIntent.ts","../src/csm/sourcemap.ts","../src/csm/mapToEditLinks.ts"],"sourcesContent":["import type { PathSegment } from './types'\n\nconst ESCAPE: Record<string, string> = {\n '\\f': '\\\\f',\n '\\n': '\\\\n',\n '\\r': '\\\\r',\n '\\t': '\\\\t',\n \"'\": \"\\\\'\",\n '\\\\': '\\\\\\\\',\n}\n\nconst UNESCAPE: Record<string, string> = {\n '\\\\f': '\\f',\n '\\\\n': '\\n',\n '\\\\r': '\\r',\n '\\\\t': '\\t',\n \"\\\\'\": \"'\",\n '\\\\\\\\': '\\\\',\n}\n\n/** @internal */\nexport function jsonPath(\n path: PathSegment[],\n opts?: {\n keyArraySelectors: boolean\n },\n): string {\n return `$${path\n .map((segment) => {\n if (typeof segment === 'string') {\n const escapedKey = segment.replace(/[\\f\\n\\r\\t'\\\\]/g, (match) => {\n return ESCAPE[match]\n })\n return `['${escapedKey}']`\n }\n\n if (typeof segment === 'number') {\n return `[${segment}]`\n }\n\n if (opts?.keyArraySelectors && segment.key !== '') {\n const escapedKey = segment.key.replace(/['\\\\]/g, (match) => {\n return ESCAPE[match]\n })\n return `[?(@._key=='${escapedKey}')]`\n }\n\n return `[${segment.index}]`\n })\n .join('')}`\n}\n\n/** @internal */\nexport function parseJsonPath(path: string): PathSegment[] {\n const parsed: PathSegment[] = []\n\n const parseRe = /\\['(.*?)'\\]|\\[(\\d+)\\]|\\[\\?\\(@\\._key=='(.*?)'\\)\\]/g\n let match: RegExpExecArray | null\n\n while ((match = parseRe.exec(path)) !== null) {\n if (match[1] !== undefined) {\n const key = match[1].replace(/\\\\(\\\\|f|n|r|t|')/g, (m) => {\n return UNESCAPE[m]\n })\n\n parsed.push(key)\n continue\n }\n\n if (match[2] !== undefined) {\n parsed.push(parseInt(match[2], 10))\n continue\n }\n\n if (match[3] !== undefined) {\n const key = match[3].replace(/\\\\(\\\\')/g, (m) => {\n return UNESCAPE[m]\n })\n\n parsed.push({\n key,\n index: -1,\n })\n continue\n }\n }\n\n return parsed\n}\n","import {ContentSourceMapDocument, ContentSourceMapDocuments} from '../types'\nimport {parseJsonPath} from './jsonpath'\nimport type {PathSegment, StudioUrl} from './types'\n\n/** @alpha */\nexport type EditLink = `/intent/edit/id=${string};type=${string};path=${string}`\n\n/** @alpha */\nexport interface EditLinkProps {\n studioUrl: StudioUrl\n document: ContentSourceMapDocument\n}\n\n/** @alpha */\nexport type DefineEditLink = (\n studioUrl: StudioUrl,\n) => (sourceDocument: ContentSourceMapDocuments[number]) => `${StudioUrl}${EditLink}`\n\n/** @alpha */\nexport function defineEditLink(\n _studioUrl: StudioUrl,\n): (\n sourceDocument: ContentSourceMapDocuments[number],\n path: string | PathSegment[],\n) => `${StudioUrl}${EditLink}` {\n const studioUrl = _studioUrl.replace(/\\/$/, '')\n return ({_id, _type}, path) =>\n `${studioUrl}/intent/edit/id=${_id};type=${_type};path=${encodeJsonPathToUriComponent(path)}`\n}\n\n/** @alpha */\nexport function encodeJsonPathToUriComponent(path: string | PathSegment[]): string {\n const sourcePath = Array.isArray(path) ? path : parseJsonPath(path)\n return encodeURIComponent(\n sourcePath\n .map((key, i) =>\n // eslint-disable-next-line no-nested-ternary\n typeof key === 'number' ? `[${key}]` : i > 0 ? `.${key}` : key,\n )\n .join(''),\n )\n}\n","import type {ContentSourceMap, ContentSourceMapDocuments, ContentSourceMapMapping} from '../types'\nimport {jsonPath, parseJsonPath} from './jsonpath'\nimport type {PathSegment} from './types'\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\n}\n\nfunction isArray(value: unknown): value is Array<unknown> {\n return value !== null && Array.isArray(value)\n}\n\n/** @alpha */\nexport type Encoder<E> = (\n value: string,\n sourceDocument: ContentSourceMapDocuments[number],\n path: PathSegment[],\n) => E\n\n/** @alpha */\nexport function encode<R, E>(\n result: R,\n csm: ContentSourceMap,\n encoder: Encoder<E>,\n options?: {keyArraySelectors: boolean},\n): R {\n return encodeIntoResult(result, csm, encoder, options) as R\n}\n\n/** @alpha */\nexport function encodeIntoResult<R>(\n result: R,\n csm: ContentSourceMap,\n encoder: Encoder<unknown>,\n options?: {keyArraySelectors: boolean},\n): ReturnType<Encoder<unknown>> {\n return walkMap(result, (value, path) => {\n // Only map strings, we could extend this in the future to support other types like integers...\n if (typeof value !== 'string') {\n return value\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const resolveMappingResult = resolveMapping(path, csm)\n if (!resolveMappingResult) {\n return value\n }\n\n const [mapping, matchedPath, pathSuffix] = resolveMappingResult\n if (mapping.type !== 'value') {\n return value\n }\n\n if (mapping.source.type !== 'documentValue') {\n return value\n }\n\n const sourceDocument =\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n csm.documents[mapping.source.document!]\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const sourcePath = csm.paths[mapping.source.path]\n\n if (options?.keyArraySelectors) {\n const matchPathSegments = parseJsonPath(matchedPath)\n const sourcePathSegments = parseJsonPath(sourcePath)\n const fullSourceSegments = sourcePathSegments.concat(path.slice(matchPathSegments.length))\n\n return encoder(value, sourceDocument, fullSourceSegments)\n }\n\n return encoder(value, sourceDocument, parseJsonPath(sourcePath + pathSuffix))\n })\n}\n\n/** @alpha */\nexport type WalkMapFn = (value: unknown, path: PathSegment[]) => unknown\n\n/** generic way to walk a nested object or array and apply a mapping function to each value\n * @alpha\n */\nexport function walkMap(value: unknown, mappingFn: WalkMapFn, path: PathSegment[] = []): unknown {\n if (isArray(value)) {\n return value.map((v, idx) => {\n if (isRecord(v)) {\n const key = v['_key']\n if (typeof key === 'string') {\n return walkMap(v, mappingFn, path.concat({key, index: idx}))\n }\n }\n\n return walkMap(v, mappingFn, path.concat(idx))\n })\n }\n\n if (isRecord(value)) {\n return Object.fromEntries(\n Object.entries(value).map(([k, v]) => [k, walkMap(v, mappingFn, path.concat(k))]),\n )\n }\n\n return mappingFn(value, path)\n}\n\n/** @alpha */\nexport function resolveMapping(\n resultPath: PathSegment[],\n csm: ContentSourceMap,\n): [ContentSourceMapMapping, string, string] | undefined {\n const resultJsonPath = jsonPath(resultPath)\n\n if (csm.mappings[resultJsonPath] !== undefined) {\n return [csm.mappings[resultJsonPath], resultJsonPath, '']\n }\n\n const mappings = Object.entries(csm.mappings)\n .filter(([key]) => resultJsonPath.startsWith(key))\n .sort(([key1], [key2]) => key2.length - key1.length)\n\n if (mappings.length == 0) {\n return undefined\n }\n\n const [matchedPath, mapping] = mappings[0]\n const pathSuffix = resultJsonPath.substring(matchedPath.length)\n return [mapping, matchedPath, pathSuffix]\n}\n","import type {ContentSourceMap} from '../types'\nimport {defineEditLink} from './editIntent'\nimport {encodeIntoResult} from './sourcemap'\n\n/** @alpha */\nexport function mapToEditLinks<R>(result: R, csm: ContentSourceMap, studioUrl: string): R {\n const createEditLink = defineEditLink(studioUrl)\n return encodeIntoResult(result, csm, (_, sourceDocument, path) => {\n return createEditLink(sourceDocument, path)\n }) as R\n}\n"],"names":["ESCAPE","UNESCAPE","jsonPath","path","opts","concat","map","segment","escapedKey","replace","match","keyArraySelectors","key","index","join","parseJsonPath","parsed","parseRe","exec","m","push","parseInt","defineEditLink","_studioUrl","studioUrl","_ref","_id","_type","encodeJsonPathToUriComponent","sourcePath","Array","isArray","encodeURIComponent","i","isRecord","value","encodeIntoResult","result","csm","encoder","options","walkMap","resolveMappingResult","resolveMapping","mapping","matchedPath","pathSuffix","type","source","sourceDocument","documents","document","paths","matchPathSegments","sourcePathSegments","fullSourceSegments","slice","length","mappingFn","arguments","undefined","v","idx","Object","fromEntries","entries","_ref2","k","resultPath","resultJsonPath","mappings","filter","_ref3","startsWith","sort","_ref4","_ref5","key1","key2","substring","mapToEditLinks","createEditLink","_"],"mappings":"AAEA,MAAMA,MAAiC,GAAA;EACrC,IAAM,EAAA,KAAA;EACN,IAAM,EAAA,KAAA;EACN,IAAM,EAAA,KAAA;EACN,GAAM,EAAA,KAAA;EACN,GAAK,EAAA,KAAA;EACL,IAAM,EAAA;AACR,CAAA;AAEA,MAAMC,QAAmC,GAAA;EACvC,KAAO,EAAA,IAAA;EACP,KAAO,EAAA,IAAA;EACP,KAAO,EAAA,IAAA;EACP,KAAO,EAAA,GAAA;EACP,KAAO,EAAA,GAAA;EACP,MAAQ,EAAA;AACV,CAAA;AAGgB,SAAAC,QAAAA,CACdC,MACAC,IAGQ,EAAA;EACR,OAAO,GAAI,CAAAC,MAAA,CAAAF,IAAA,CACRG,GAAI,CAACC,OAAY,IAAA;IACZ,IAAA,OAAOA,YAAY,QAAU,EAAA;MAC/B,MAAMC,UAAa,GAAAD,OAAA,CAAQE,OAAQ,CAAA,gBAAA,EAAmBC,KAAU,IAAA;QAC9D,OAAOV,OAAOU,KAAK,CAAA;MAAA,CACpB,CAAA;MACD,OAAO,KAAKL,MAAU,CAAAG,UAAA,EAAA,IAAA,CAAA;IACxB;IAEI,IAAA,OAAOD,YAAY,QAAU,EAAA;MAC/B,OAAO,IAAIF,MAAO,CAAAE,OAAA,EAAA,GAAA,CAAA;IACpB;IAEA,IAAA,CAAIH,IAAM,IAAA,IAAA,GAAA,KAAA,CAAA,GAAAA,IAAA,CAAAO,iBAAA,KAAqBJ,OAAQ,CAAAK,GAAA,KAAQ,EAAI,EAAA;MACjD,MAAMJ,aAAaD,OAAQ,CAAAK,GAAA,CAAIH,OAAQ,CAAA,QAAA,EAAWC,KAAU,IAAA;QAC1D,OAAOV,OAAOU,KAAK,CAAA;MAA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8D,IAAA,CAAK,CAAAC,KAAA,EAAAC,KAAA;IAAA,IAAC,CAACC,IAAI,CAAA,GAAAF,KAAA;IAAA,IAAG,CAACG,IAAI,CAAM,GAAAF,KAAA;IAAA,OAAAE,IAAA,CAAKrB,MAAS,GAAAoB,IAAA,CAAKpB,MAAM;EAAA,EAAA;EAEjD,IAAAa,QAAA,CAASb,UAAU,CAAG,EAAA;IACjB,OAAA,KAAA,CAAA;EACT;EAEA,MAAM,CAACZ,WAAA,EAAaD,OAAO,CAAA,GAAI0B,SAAS,CAAC,CAAA;EACzC,MAAMxB,UAAa,GAAAuB,cAAA,CAAeU,SAAU,CAAAlC,WAAA,CAAYY,MAAM,CAAA;EACvD,OAAA,CAACb,OAAS,EAAAC,WAAA,EAAaC,UAAU,CAAA;AAC1C;ACzHgB,SAAAkC,cAAAA,CAAkB3C,MAAW,EAAAC,GAAA,EAAuBd,SAAsB,EAAA;EAClF,MAAAyD,cAAA,GAAiB3D,eAAeE,SAAS,CAAA;EAC/C,OAAOY,iBAAiBC,MAAQ,EAAAC,GAAA,EAAK,CAAC4C,CAAA,EAAGjC,gBAAgB9C,IAAS,KAAA;IACzD,OAAA8E,cAAA,CAAehC,gBAAgB9C,IAAI,CAAA;EAAA,CAC3C,CAAA;AACH;"}
|
package/dist/index.cjs
CHANGED
|
@@ -8,7 +8,7 @@ var getIt = require('get-it');
|
|
|
8
8
|
var rxjs = require('rxjs');
|
|
9
9
|
var operators = require('rxjs/operators');
|
|
10
10
|
var name = "@sanity/client";
|
|
11
|
-
var version = "6.7.0";
|
|
11
|
+
var version = "6.7.1-canary.0";
|
|
12
12
|
const middleware = [middleware$1.debug({
|
|
13
13
|
verbose: true,
|
|
14
14
|
namespace: "sanity:client"
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { adapter as unstable__adapter, environment as unstable__environment } fr
|
|
|
4
4
|
import { Observable, lastValueFrom } from 'rxjs';
|
|
5
5
|
import { map, filter } from 'rxjs/operators';
|
|
6
6
|
var name = "@sanity/client";
|
|
7
|
-
var version = "6.7.0";
|
|
7
|
+
var version = "6.7.1-canary.0";
|
|
8
8
|
const middleware = [debug({
|
|
9
9
|
verbose: true,
|
|
10
10
|
namespace: "sanity:client"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/client",
|
|
3
|
-
"version": "6.7.0",
|
|
3
|
+
"version": "6.7.1-canary.0",
|
|
4
4
|
"description": "Client for retrieving, creating and patching data from Sanity.io",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -44,6 +44,13 @@
|
|
|
44
44
|
},
|
|
45
45
|
"default": "./dist/index.js"
|
|
46
46
|
},
|
|
47
|
+
"./csm": {
|
|
48
|
+
"types": "./dist/csm.d.ts",
|
|
49
|
+
"source": "./src/csm/index.ts",
|
|
50
|
+
"import": "./dist/csm.js",
|
|
51
|
+
"require": "./dist/csm.cjs",
|
|
52
|
+
"default": "./dist/csm.js"
|
|
53
|
+
},
|
|
47
54
|
"./package.json": "./package.json"
|
|
48
55
|
},
|
|
49
56
|
"main": "./dist/index.cjs",
|
|
@@ -55,6 +62,13 @@
|
|
|
55
62
|
"./dist/index.js": "./dist/index.browser.js"
|
|
56
63
|
},
|
|
57
64
|
"types": "./dist/index.d.ts",
|
|
65
|
+
"typesVersions": {
|
|
66
|
+
"*": {
|
|
67
|
+
"csm": [
|
|
68
|
+
"./dist/csm.d.ts"
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
},
|
|
58
72
|
"files": [
|
|
59
73
|
"dist",
|
|
60
74
|
"src",
|
|
@@ -91,33 +105,33 @@
|
|
|
91
105
|
},
|
|
92
106
|
"dependencies": {
|
|
93
107
|
"@sanity/eventsource": "^5.0.0",
|
|
94
|
-
"get-it": "^8.4.
|
|
108
|
+
"get-it": "^8.4.4",
|
|
95
109
|
"rxjs": "^7.0.0"
|
|
96
110
|
},
|
|
97
111
|
"devDependencies": {
|
|
98
|
-
"@edge-runtime/types": "^2.2.
|
|
99
|
-
"@edge-runtime/vm": "^3.1.
|
|
100
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
112
|
+
"@edge-runtime/types": "^2.2.6",
|
|
113
|
+
"@edge-runtime/vm": "^3.1.6",
|
|
114
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
101
115
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
102
|
-
"@sanity/pkg-utils": "^3.
|
|
103
|
-
"@types/node": "^20.8.
|
|
104
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
105
|
-
"@typescript-eslint/parser": "^6.
|
|
116
|
+
"@sanity/pkg-utils": "^3.2.1",
|
|
117
|
+
"@types/node": "^20.8.8",
|
|
118
|
+
"@typescript-eslint/eslint-plugin": "^6.9.0",
|
|
119
|
+
"@typescript-eslint/parser": "^6.9.0",
|
|
106
120
|
"@vitest/coverage-v8": "^0.34.6",
|
|
107
|
-
"eslint": "^8.
|
|
121
|
+
"eslint": "^8.52.0",
|
|
108
122
|
"eslint-config-prettier": "^9.0.0",
|
|
109
123
|
"eslint-plugin-prettier": "^5.0.1",
|
|
110
124
|
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
111
125
|
"faucet": "^0.0.4",
|
|
112
|
-
"happy-dom": "^12.
|
|
126
|
+
"happy-dom": "^12.10.1",
|
|
113
127
|
"ls-engines": "^0.9.0",
|
|
114
|
-
"nock": "^13.3.
|
|
128
|
+
"nock": "^13.3.6",
|
|
115
129
|
"prettier": "^3.0.3",
|
|
116
130
|
"prettier-plugin-packagejson": "^2.4.6",
|
|
117
131
|
"rimraf": "^5.0.1",
|
|
118
|
-
"rollup": "^4.
|
|
132
|
+
"rollup": "^4.1.4",
|
|
119
133
|
"sse-channel": "^4.0.0",
|
|
120
|
-
"terser": "^5.
|
|
134
|
+
"terser": "^5.22.0",
|
|
121
135
|
"typescript": "^5.2.2",
|
|
122
136
|
"vitest": "^0.34.6",
|
|
123
137
|
"vitest-github-actions-reporter": "^0.10.0"
|