@farm.js/sanity 0.1.0-beta.107 → 0.1.0-beta.108
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/content.d.ts.map +1 -1
- package/dist/content.js +37 -22
- package/package.json +3 -3
package/dist/content.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,MAAM,WAAW,0BAA0B;IACzC,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IACnD,6EAA6E;IAC7E,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IACjE,oDAAoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,0BAA0B,GAAG,mBAAmB,
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAInD,MAAM,WAAW,0BAA0B;IACzC,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,8EAA8E;IAC9E,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,gEAAgE;IAChE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;IACnD,6EAA6E;IAC7E,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC;IACjE,oDAAoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,0BAA0B,GAAG,mBAAmB,CA0KrF"}
|
package/dist/content.js
CHANGED
|
@@ -44,29 +44,44 @@ export function sanitySource(options) {
|
|
|
44
44
|
return writeClient;
|
|
45
45
|
};
|
|
46
46
|
// Entry ids are slugs by default, but Sanity mutations address `_id`.
|
|
47
|
-
//
|
|
48
|
-
//
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
// unrelated
|
|
47
|
+
//
|
|
48
|
+
// Resolve against the collection's own read query, so a write can only ever
|
|
49
|
+
// address a document this collection actually reads. Two earlier shapes were
|
|
50
|
+
// both wrong: an unconstrained `slug.current == $id` lookup could resolve a
|
|
51
|
+
// document of an unrelated type that happened to share the slug, and
|
|
52
|
+
// deleting it destroyed data the collection does not own; constraining to
|
|
53
|
+
// `createType` instead left every entry of any other type in a multi-type
|
|
54
|
+
// collection unresolvable, so ordinary updates started throwing.
|
|
55
|
+
//
|
|
56
|
+
// Resolved live on every write, because a cached mapping goes stale the
|
|
57
|
+
// moment an editor reassigns a slug. That costs one query per write, which
|
|
58
|
+
// is the same query the read path already runs, and writes are rare next to
|
|
59
|
+
// reads.
|
|
52
60
|
const resolveDocumentId = async (id) => {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
const documents = await resolveWriteClient().fetch(options.query, options.params ?? {});
|
|
62
|
+
if (!Array.isArray(documents)) {
|
|
63
|
+
throw new Error(`sanitySource(${JSON.stringify(name)}) query must resolve to an array of documents; ` +
|
|
64
|
+
"the write was not sent.");
|
|
65
|
+
}
|
|
66
|
+
const records = documents;
|
|
67
|
+
const match = records.find((record) => resolveId(record) === id) ??
|
|
68
|
+
// A custom `id` option can address documents by their own `_id`.
|
|
69
|
+
records.find((record) => record._id === id);
|
|
70
|
+
if (!match) {
|
|
71
|
+
throw new Error(`sanitySource(${JSON.stringify(name)}) could not resolve ${JSON.stringify(id)} to a ` +
|
|
72
|
+
"document this collection reads; the write was not sent. The entry may have been " +
|
|
73
|
+
"deleted, its slug may have changed, or it may belong to another collection.");
|
|
74
|
+
}
|
|
75
|
+
const documentId = match._id;
|
|
76
|
+
if (typeof documentId !== "string" || !documentId) {
|
|
77
|
+
// Reads only need an id the projection can derive, so a query that omits
|
|
78
|
+
// `_id` loads fine and then cannot be written back. Say which projection
|
|
79
|
+
// is short rather than claiming the entry does not exist.
|
|
80
|
+
throw new Error(`sanitySource(${JSON.stringify(name)}) resolved ${JSON.stringify(id)} to a document ` +
|
|
81
|
+
"without an `_id`; the write was not sent. Add `_id` to the collection query's " +
|
|
82
|
+
"projection so writes can address the document.");
|
|
83
|
+
}
|
|
84
|
+
return documentId;
|
|
70
85
|
};
|
|
71
86
|
const toDocument = (record) => {
|
|
72
87
|
const id = resolveId(record) || record._id;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farm.js/sanity",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.108",
|
|
4
4
|
"description": "Sanity CMS integration for Farm.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@sanity/image-url": "^2.1.1",
|
|
29
29
|
"@sanity/webhook": "^4.0.4",
|
|
30
|
-
"@farm.js/core": "0.1.0-beta.
|
|
31
|
-
"@farm.js/integration-utils": "0.1.0-beta.
|
|
30
|
+
"@farm.js/core": "0.1.0-beta.108",
|
|
31
|
+
"@farm.js/integration-utils": "0.1.0-beta.108"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@sanity/client": "^8.4.0",
|