mikser-io-sdk-api 3.3.0 → 3.4.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/README.md CHANGED
@@ -305,9 +305,9 @@ const { items } = await docs.list({
305
305
 
306
306
  | Cap | Default | Configured at | What triggers it |
307
307
  |---|---|---|---|
308
- | `maxDepth` | 5 | `api.expand.maxDepth` | One path is longer than this (`a.b.c.d.e.f` at default) |
309
- | `maxPaths` | 20 | `api.expand.maxPaths` | The `expand` array has more entries than this |
310
- | `maxResolved` | 100 | `api.expand.maxResolved` | Total entity lookups for the request (across all paths) exceeded |
308
+ | `maxDepth` | 5 | `catalog.expand.maxDepth` | One path is longer than this (`a.b.c.d.e.f` at default) |
309
+ | `maxPaths` | 20 | `catalog.expand.maxPaths` | The `expand` array has more entries than this |
310
+ | `maxResolved` | 100 | `catalog.expand.maxResolved` | Total entity lookups for the request (across all paths) exceeded |
311
311
 
312
312
  ```js
313
313
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mikser-io-sdk-api",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "Client SDK for mikser-io's api plugin — query the document catalog from the browser or Node",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/src/entities.js CHANGED
@@ -51,7 +51,7 @@ const GET_MAX_URL = 1800
51
51
  // console). Server-side has a matching warning that fires for all
52
52
  // clients regardless of SDK use.
53
53
  const WIDE_RESPONSE_ITEMS = 50
54
- const _warnedShapes = new Set()
54
+ const warnedShapes = new Set()
55
55
 
56
56
  function isProductionEnv() {
57
57
  try {
@@ -74,8 +74,8 @@ function maybeWarnWide({ endpoint, query, envelopeOrItems, quiet }) {
74
74
  const hasFields = Array.isArray(query?.fields) && query.fields.length > 0
75
75
  if (hasFields) return
76
76
  const shape = `${endpoint}|${JSON.stringify(query?.filter ?? null)}|${JSON.stringify(query?.sort ?? null)}`
77
- if (_warnedShapes.has(shape)) return
78
- _warnedShapes.add(shape)
77
+ if (warnedShapes.has(shape)) return
78
+ warnedShapes.add(shape)
79
79
  let sizeNote = ''
80
80
  try {
81
81
  const bytes = JSON.stringify(items).length
@@ -100,7 +100,7 @@ function maybeWarnWide({ endpoint, query, envelopeOrItems, quiet }) {
100
100
  // calls without noticing the snapshot is no longer involved. Deduped
101
101
  // per (endpoint, kind, what-was-set) so a page with 3 filtered calls
102
102
  // produces 3 warnings, not 30.
103
- const _bypassedShapes = new Set()
103
+ const bypassedShapes = new Set()
104
104
  function maybeWarnSnapshotBypass({ endpoint, kind, filter, sort, skip, quiet }) {
105
105
  if (quiet || isProductionEnv() || isQuiet()) return
106
106
  const reasons = []
@@ -110,8 +110,8 @@ function maybeWarnSnapshotBypass({ endpoint, kind, filter, sort, skip, quiet })
110
110
  if (reasons.length === 0) return
111
111
  const reasonLabel = reasons.join('+')
112
112
  const shape = `${endpoint}|${kind}|${reasonLabel}`
113
- if (_bypassedShapes.has(shape)) return
114
- _bypassedShapes.add(shape)
113
+ if (bypassedShapes.has(shape)) return
114
+ bypassedShapes.add(shape)
115
115
  const fallback = kind === 'live' ? 'live list()' : 'paginated fetch'
116
116
  console.warn(
117
117
  `[mikser-sdk] data.catalog is set on "${endpoint}" but this ${kind}() call uses ${reasonLabel} — snapshot bypassed, falling back to ${fallback}.\n` +
package/src/href.js CHANGED
@@ -22,20 +22,31 @@
22
22
  * @returns {{
23
23
  * href: (ref: string, lang?: string) => string,
24
24
  * refFor: (url: string|null) => string|null,
25
+ * docFor: (ref: string, lang?: string) => object|null,
26
+ * metaFor: (ref: string, lang?: string) => object|null,
25
27
  * alternates: (opts: { route: string|null, languages?: string[] }) => { current: {lang, url, ref}|null, alternates: Array<{lang, url}> },
26
28
  * map: Record<string, Record<string, string>>,
27
29
  * }}
28
30
  */
29
31
  export function createHrefIndex(documents, { defaultLang = 'default' } = {}) {
30
32
  const map = {}
33
+ // ref → lang → document. The index already iterates every document
34
+ // with its full meta to build `map`; keeping the document here too
35
+ // turns the href index into a content index — `metaFor('/menu')`
36
+ // reads a known document by its logical reference, the companion to
37
+ // `href('/menu')` resolving the URL. Costs one extra object slot per
38
+ // document; the data was already in hand.
39
+ const docs = {}
31
40
  if (Array.isArray(documents)) {
32
41
  for (const document of documents) {
33
42
  const ref = document?.meta?.href
34
43
  if (!ref) continue
35
44
  const lang = document.meta?.lang ?? defaultLang
36
45
  const url = document.meta?.route ?? document.meta?.destination ?? ref
37
- if (!map[ref]) map[ref] = {}
38
- map[ref][lang] = url
46
+ if (!map[ref]) map[ref] = {}
47
+ if (!docs[ref]) docs[ref] = {}
48
+ map[ref][lang] = url
49
+ docs[ref][lang] = document
39
50
  }
40
51
  }
41
52
 
@@ -56,6 +67,32 @@ export function createHrefIndex(documents, { defaultLang = 'default' } = {}) {
56
67
  ?? ref
57
68
  }
58
69
 
70
+ /**
71
+ * Resolve a logical reference to its document — the content
72
+ * companion to href(). Same lang-fallback chain (requested lang →
73
+ * 'default' → any available). Returns null when the ref isn't in
74
+ * the index (a missing document can't be faked the way a missing
75
+ * URL falls back to the ref string).
76
+ */
77
+ function docFor(ref, lang) {
78
+ const target = lang ?? defaultLang
79
+ const entry = docs[ref]
80
+ if (!entry) return null
81
+ return entry[target]
82
+ ?? entry['default']
83
+ ?? Object.values(entry)[0]
84
+ ?? null
85
+ }
86
+
87
+ /**
88
+ * The meta of the document a logical reference resolves to — the
89
+ * 90% case (read fields off known content by its ref). Shorthand
90
+ * for `docFor(ref, lang)?.meta`.
91
+ */
92
+ function metaFor(ref, lang) {
93
+ return docFor(ref, lang)?.meta ?? null
94
+ }
95
+
59
96
  /**
60
97
  * Reverse lookup — given a deployed URL, return the logical
61
98
  * reference it belongs to (or null if it's not in the index).
@@ -106,5 +143,5 @@ export function createHrefIndex(documents, { defaultLang = 'default' } = {}) {
106
143
  return { current, alternates: list }
107
144
  }
108
145
 
109
- return { href, refFor, alternates, map }
146
+ return { href, refFor, docFor, metaFor, alternates, map }
110
147
  }