@proveanything/smartlinks 3.0.0-alpha.0 → 3.0.0-alpha.2

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.
Files changed (149) hide show
  1. package/README.md +7 -7
  2. package/dist/api/analytics.d.ts +5 -4
  3. package/dist/api/analytics.js +5 -4
  4. package/dist/api/appConfiguration.d.ts +23 -18
  5. package/dist/api/appConfiguration.js +24 -18
  6. package/dist/api/appObjects.d.ts +54 -10
  7. package/dist/api/appObjects.js +75 -40
  8. package/dist/api/asset.d.ts +28 -22
  9. package/dist/api/asset.js +45 -56
  10. package/dist/api/attestation.d.ts +11 -3
  11. package/dist/api/attestation.js +12 -3
  12. package/dist/api/attestations.d.ts +12 -8
  13. package/dist/api/attestations.js +18 -21
  14. package/dist/api/authKit.d.ts +15 -10
  15. package/dist/api/authKit.js +17 -11
  16. package/dist/api/batch.d.ts +36 -25
  17. package/dist/api/batch.js +46 -39
  18. package/dist/api/bookings.d.ts +18 -9
  19. package/dist/api/bookings.js +23 -13
  20. package/dist/api/broadcasts.js +3 -17
  21. package/dist/api/claimSet.d.ts +26 -12
  22. package/dist/api/claimSet.js +32 -24
  23. package/dist/api/collection.d.ts +15 -10
  24. package/dist/api/collection.js +17 -11
  25. package/dist/api/comms.d.ts +12 -6
  26. package/dist/api/comms.js +12 -6
  27. package/dist/api/conditions.d.ts +7 -6
  28. package/dist/api/conditions.js +8 -6
  29. package/dist/api/contact.d.ts +6 -2
  30. package/dist/api/contact.js +25 -60
  31. package/dist/api/containers.d.ts +14 -10
  32. package/dist/api/containers.js +19 -14
  33. package/dist/api/crate.js +7 -9
  34. package/dist/api/dpp.d.ts +20 -13
  35. package/dist/api/dpp.js +23 -15
  36. package/dist/api/facets.d.ts +38 -13
  37. package/dist/api/facets.js +40 -15
  38. package/dist/api/files.d.ts +5 -2
  39. package/dist/api/files.js +7 -4
  40. package/dist/api/form.d.ts +8 -5
  41. package/dist/api/form.js +9 -5
  42. package/dist/api/index.d.ts +0 -1
  43. package/dist/api/index.js +0 -1
  44. package/dist/api/integrations.d.ts +29 -17
  45. package/dist/api/integrations.js +32 -25
  46. package/dist/api/interactions.d.ts +11 -6
  47. package/dist/api/interactions.js +14 -23
  48. package/dist/api/jobs.d.ts +16 -6
  49. package/dist/api/jobs.js +30 -20
  50. package/dist/api/journeys.js +2 -14
  51. package/dist/api/journeysAnalytics.d.ts +8 -5
  52. package/dist/api/journeysAnalytics.js +8 -5
  53. package/dist/api/knowledge.d.ts +20 -14
  54. package/dist/api/knowledge.js +22 -15
  55. package/dist/api/location.d.ts +6 -3
  56. package/dist/api/location.js +8 -22
  57. package/dist/api/lots.d.ts +9 -5
  58. package/dist/api/lots.js +22 -26
  59. package/dist/api/loyalty.d.ts +25 -16
  60. package/dist/api/loyalty.js +33 -32
  61. package/dist/api/nfc.d.ts +3 -1
  62. package/dist/api/nfc.js +3 -1
  63. package/dist/api/order.d.ts +45 -39
  64. package/dist/api/order.js +48 -65
  65. package/dist/api/partner.d.ts +17 -14
  66. package/dist/api/partner.js +21 -22
  67. package/dist/api/products.d.ts +35 -12
  68. package/dist/api/products.js +36 -13
  69. package/dist/api/proof.d.ts +41 -19
  70. package/dist/api/proof.js +44 -23
  71. package/dist/api/segments.js +3 -15
  72. package/dist/api/serviceAccounts.d.ts +8 -5
  73. package/dist/api/serviceAccounts.js +9 -6
  74. package/dist/api/shop.d.ts +7 -5
  75. package/dist/api/shop.js +13 -19
  76. package/dist/api/subscriptions.d.ts +12 -10
  77. package/dist/api/subscriptions.js +17 -25
  78. package/dist/api/tags.d.ts +23 -20
  79. package/dist/api/tags.js +40 -52
  80. package/dist/api/template.d.ts +16 -11
  81. package/dist/api/template.js +19 -13
  82. package/dist/api/translations.js +2 -12
  83. package/dist/api/userGroups.d.ts +26 -16
  84. package/dist/api/userGroups.js +43 -30
  85. package/dist/api/variant.d.ts +10 -7
  86. package/dist/api/variant.js +11 -7
  87. package/dist/api/wallet.d.ts +14 -11
  88. package/dist/api/wallet.js +15 -12
  89. package/dist/docs/API_SUMMARY.md +289 -483
  90. package/dist/docs/ai.md +15 -15
  91. package/dist/docs/analytics.md +1 -1
  92. package/dist/docs/app-objects.md +4 -4
  93. package/dist/docs/attestations.md +8 -8
  94. package/dist/docs/contact-search.md +2 -3
  95. package/dist/docs/i18n.md +46 -292
  96. package/dist/docs/knowledge.md +3 -3
  97. package/dist/docs/lists.md +58 -15
  98. package/dist/docs/upgrading-to-3.md +238 -136
  99. package/dist/i18n.d.ts +14 -2
  100. package/dist/i18n.js +23 -6
  101. package/dist/list.d.ts +12 -0
  102. package/dist/list.js +59 -0
  103. package/dist/openapi.yaml +301 -662
  104. package/dist/types/analytics.d.ts +7 -3
  105. package/dist/types/appObjects.d.ts +27 -12
  106. package/dist/types/appOptions.d.ts +2 -2
  107. package/dist/types/asset.d.ts +5 -6
  108. package/dist/types/attestations.d.ts +7 -9
  109. package/dist/types/batch.d.ts +5 -5
  110. package/dist/types/bookings.d.ts +10 -5
  111. package/dist/types/comms.d.ts +9 -5
  112. package/dist/types/contact.d.ts +7 -4
  113. package/dist/types/containers.d.ts +2 -1
  114. package/dist/types/facets.d.ts +14 -2
  115. package/dist/types/files.d.ts +3 -2
  116. package/dist/types/integrations.d.ts +2 -1
  117. package/dist/types/interaction.d.ts +15 -7
  118. package/dist/types/jobs.d.ts +1 -1
  119. package/dist/types/journeysAnalytics.d.ts +3 -2
  120. package/dist/types/knowledge.d.ts +6 -3
  121. package/dist/types/knowledge.js +0 -1
  122. package/dist/types/list.d.ts +30 -2
  123. package/dist/types/location.d.ts +7 -2
  124. package/dist/types/location.js +0 -1
  125. package/dist/types/lots.d.ts +5 -2
  126. package/dist/types/lots.js +0 -6
  127. package/dist/types/order.d.ts +22 -20
  128. package/dist/types/product.d.ts +28 -11
  129. package/dist/types/proof.d.ts +7 -8
  130. package/dist/types/tags.d.ts +5 -3
  131. package/dist/types/userGroups.d.ts +3 -3
  132. package/dist/types/userGroups.js +0 -4
  133. package/dist/version.d.ts +1 -1
  134. package/dist/version.js +1 -1
  135. package/docs/API_SUMMARY.md +289 -483
  136. package/docs/ai.md +15 -15
  137. package/docs/analytics.md +1 -1
  138. package/docs/app-objects.md +4 -4
  139. package/docs/attestations.md +8 -8
  140. package/docs/contact-search.md +2 -3
  141. package/docs/i18n.md +46 -292
  142. package/docs/knowledge.md +3 -3
  143. package/docs/lists.md +58 -15
  144. package/docs/upgrading-to-3.md +238 -136
  145. package/openapi.yaml +301 -662
  146. package/package.json +91 -91
  147. package/scripts/lib/upgrade.mjs +216 -60
  148. package/scripts/upgrade.mjs +33 -10
  149. package/upgrade/3.json +2731 -2213
package/package.json CHANGED
@@ -1,91 +1,91 @@
1
- {
2
- "name": "@proveanything/smartlinks",
3
- "version": "3.0.0-alpha.0",
4
- "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
- "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "exports": {
9
- ".": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js",
12
- "default": "./dist/index.js"
13
- },
14
- "./testing": {
15
- "types": "./dist/testing/index.d.ts",
16
- "import": "./dist/testing/index.js",
17
- "default": "./dist/testing/index.js"
18
- },
19
- "./*": {
20
- "types": "./dist/*.d.ts",
21
- "import": "./dist/*.js",
22
- "default": "./dist/*.js"
23
- },
24
- "./baseline.css": "./dist/baseline.css",
25
- "./baseline.classes.json": "./dist/baseline.classes.json",
26
- "./theme.css": "./dist/theme.css",
27
- "./theme-boot.js": "./dist/theme-boot.js",
28
- "./package.json": "./package.json"
29
- },
30
- "bin": {
31
- "smartlinks-register-release": "scripts/register-release.mjs",
32
- "smartlinks-publish": "scripts/publish.mjs",
33
- "smartlinks-doctor": "scripts/doctor.mjs",
34
- "smartlinks-headless": "scripts/headless-check.mjs",
35
- "smartlinks-upgrade": "scripts/upgrade.mjs"
36
- },
37
- "files": [
38
- "dist/",
39
- "docs/",
40
- "upgrade/",
41
- "scripts/register-release.mjs",
42
- "scripts/publish.mjs",
43
- "scripts/doctor.mjs",
44
- "scripts/upgrade.mjs",
45
- "scripts/headless-check.mjs",
46
- "scripts/lib/",
47
- "openapi.yaml",
48
- "README.md"
49
- ],
50
- "scripts": {
51
- "test": "node test/run.cjs",
52
- "build": "node scripts/write-version.mjs && node scripts/upgrade-table.mjs --check && tsc && node scripts/fix-esm-extensions.mjs && node generate-api-summary.cjs && node generate-openapi.cjs && node scripts/copy-docs-to-dist.cjs && node scripts/build-baseline.mjs",
53
- "docs": "typedoc",
54
- "docs:summary": "node generate-api-summary.cjs",
55
- "docs:openapi": "node generate-openapi.cjs",
56
- "docs:openapi:lint": "npx --yes @redocly/cli@latest lint openapi.yaml",
57
- "docs:openapi:check": "node generate-openapi.cjs && npx --yes @redocly/cli@latest lint openapi.yaml",
58
- "build:docs": "tsc build-docs.ts --outDir dist && node dist/build-docs.js",
59
- "prepublishOnly": "npm run build",
60
- "docs:upgrade": "node scripts/upgrade-table.mjs"
61
- },
62
- "keywords": [
63
- "smartlinks",
64
- "api",
65
- "authentication",
66
- "traceability",
67
- "blockchain",
68
- "typescript",
69
- "sdk"
70
- ],
71
- "author": "Glenn Shoosmith",
72
- "license": "MIT",
73
- "publishConfig": {
74
- "access": "public"
75
- },
76
- "dependencies": {
77
- "cross-fetch": "^3.1.5",
78
- "es-module-lexer": "^1.7.0"
79
- },
80
- "devDependencies": {
81
- "ts-node": "^10.9.1",
82
- "typedoc": "^0.25.13",
83
- "typedoc-plugin-markdown": "^3.17.1",
84
- "typescript": "^4.9.0"
85
- },
86
- "repository": {
87
- "type": "git",
88
- "url": "https://github.com/Prove-Anything/smartlinks.git"
89
- },
90
- "homepage": "https://smartlinks.app"
91
- }
1
+ {
2
+ "name": "@proveanything/smartlinks",
3
+ "version": "3.0.0-alpha.2",
4
+ "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./testing": {
15
+ "types": "./dist/testing/index.d.ts",
16
+ "import": "./dist/testing/index.js",
17
+ "default": "./dist/testing/index.js"
18
+ },
19
+ "./*": {
20
+ "types": "./dist/*.d.ts",
21
+ "import": "./dist/*.js",
22
+ "default": "./dist/*.js"
23
+ },
24
+ "./baseline.css": "./dist/baseline.css",
25
+ "./baseline.classes.json": "./dist/baseline.classes.json",
26
+ "./theme.css": "./dist/theme.css",
27
+ "./theme-boot.js": "./dist/theme-boot.js",
28
+ "./package.json": "./package.json"
29
+ },
30
+ "bin": {
31
+ "smartlinks-register-release": "scripts/register-release.mjs",
32
+ "smartlinks-publish": "scripts/publish.mjs",
33
+ "smartlinks-doctor": "scripts/doctor.mjs",
34
+ "smartlinks-headless": "scripts/headless-check.mjs",
35
+ "smartlinks-upgrade": "scripts/upgrade.mjs"
36
+ },
37
+ "files": [
38
+ "dist/",
39
+ "docs/",
40
+ "upgrade/",
41
+ "scripts/register-release.mjs",
42
+ "scripts/publish.mjs",
43
+ "scripts/doctor.mjs",
44
+ "scripts/upgrade.mjs",
45
+ "scripts/headless-check.mjs",
46
+ "scripts/lib/",
47
+ "openapi.yaml",
48
+ "README.md"
49
+ ],
50
+ "scripts": {
51
+ "test": "node test/run.cjs",
52
+ "build": "node scripts/write-version.mjs && node scripts/upgrade-table.mjs --check && tsc && node scripts/fix-esm-extensions.mjs && node generate-api-summary.cjs && node generate-openapi.cjs && node scripts/copy-docs-to-dist.cjs && node scripts/build-baseline.mjs",
53
+ "docs": "typedoc",
54
+ "docs:summary": "node generate-api-summary.cjs",
55
+ "docs:openapi": "node generate-openapi.cjs",
56
+ "docs:openapi:lint": "npx --yes @redocly/cli@latest lint openapi.yaml",
57
+ "docs:openapi:check": "node generate-openapi.cjs && npx --yes @redocly/cli@latest lint openapi.yaml",
58
+ "build:docs": "tsc build-docs.ts --outDir dist && node dist/build-docs.js",
59
+ "prepublishOnly": "npm run build",
60
+ "docs:upgrade": "node scripts/upgrade-table.mjs"
61
+ },
62
+ "keywords": [
63
+ "smartlinks",
64
+ "api",
65
+ "authentication",
66
+ "traceability",
67
+ "blockchain",
68
+ "typescript",
69
+ "sdk"
70
+ ],
71
+ "author": "Glenn Shoosmith",
72
+ "license": "MIT",
73
+ "publishConfig": {
74
+ "access": "public"
75
+ },
76
+ "dependencies": {
77
+ "cross-fetch": "^3.1.5",
78
+ "es-module-lexer": "^1.7.0"
79
+ },
80
+ "devDependencies": {
81
+ "ts-node": "^10.9.1",
82
+ "typedoc": "^0.25.13",
83
+ "typedoc-plugin-markdown": "^3.17.1",
84
+ "typescript": "^4.9.0"
85
+ },
86
+ "repository": {
87
+ "type": "git",
88
+ "url": "https://github.com/Prove-Anything/smartlinks.git"
89
+ },
90
+ "homepage": "https://smartlinks.app"
91
+ }
@@ -82,6 +82,22 @@ function analyseFile(ts, checker, sf, idx, rel) {
82
82
  const work = [] // { kind, name, line, note, ... }
83
83
  const lineOf = (node) => sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1
84
84
  const push = (kind, node, name, extra = {}) => work.push({ kind, file: rel, line: lineOf(node), name, ...extra })
85
+ // `// sl-upgrade: ok <why>` on the line, or the line above, says a person has looked at this place and it
86
+ // is right as it is (the first page is all that's wanted; the options come from elsewhere and carry a
87
+ // limit). It settles what only a person can judge; it never excuses a call that no longer exists.
88
+ const lines = text.split('\n')
89
+ const MARK = /sl-upgrade:\s*ok\b/i
90
+ const markedAt = (line) => MARK.test(lines[line - 1] || '') || MARK.test(lines[line - 2] || '')
91
+ /** Is this node inside the page function handed to `all(…)` or `each(…)`? */
92
+ const insideWalk = (node) => {
93
+ for (let n = node.parent; n; n = n.parent) {
94
+ if (!ts.isCallExpression(n)) continue
95
+ const callee = n.expression
96
+ const name = ts.isIdentifier(callee) ? callee.text : ts.isPropertyAccessExpression(callee) ? callee.name.text : ''
97
+ if ((name === 'all' || name === 'each') && n.arguments.some((a) => a.pos <= node.pos && node.end <= a.end)) return true
98
+ }
99
+ return false
100
+ }
85
101
 
86
102
  // 1. What the SDK's names are bound to in this file.
87
103
  const imports = new Map() // symbol → { imported, local, spec, decl }
@@ -153,9 +169,26 @@ function analyseFile(ts, checker, sf, idx, rel) {
153
169
 
154
170
  const objectKeys = (call) => {
155
171
  const keys = new Set()
156
- for (const a of call.arguments || []) if (ts.isObjectLiteralExpression(a)) for (const p of a.properties) if (p.name && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name))) keys.add(p.name.text)
172
+ const named = (p) => p.name && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name))
173
+ for (const a of call.arguments || []) {
174
+ if (!ts.isObjectLiteralExpression(a)) continue
175
+ for (const p of a.properties) {
176
+ if (!named(p)) continue
177
+ keys.add(p.name.text)
178
+ // One level down, for options that sat inside another (`query.search`, `page.offset`):
179
+ // the keys written out, or "anything" when the inner object isn't written here.
180
+ if (ts.isPropertyAssignment(p) && ts.isObjectLiteralExpression(p.initializer)) {
181
+ for (const q of p.initializer.properties) { if (named(q)) keys.add(p.name.text + '.' + q.name.text); else keys.add(p.name.text + '.*') }
182
+ } else keys.add(p.name.text + '.*')
183
+ }
184
+ }
157
185
  return keys
158
186
  }
187
+ /** Does a call's options object carry `option` (which may be `outer.inner`)? */
188
+ const carries = (keys, option) => {
189
+ if (!option.includes('.')) return keys.has(option)
190
+ return keys.has(option) || keys.has(option.split('.')[0] + '.*')
191
+ }
159
192
 
160
193
  const visit = (node) => {
161
194
  if (ts.isIdentifier(node)) {
@@ -177,11 +210,18 @@ function analyseFile(ts, checker, sf, idx, rel) {
177
210
  if (idx.renames.has(name)) {
178
211
  const to = idx.renames.get(name)
179
212
  const [fromHead, toHead] = [name.split('.')[0], to.split('.')[0]]
180
- // The part that changes is the first one: `product` in product.get, or the whole of a type's name.
213
+ const [fromLast, toLast] = [name.split('.').pop(), to.split('.').pop()]
214
+ // The last part changed (jobs.listJobs → jobs.list, async.enqueueAsyncJob → jobs.enqueue).
215
+ if (p.length > 1 && fromLast !== toLast && ts.isPropertyAccessExpression(node) && node.name.text === fromLast) {
216
+ edits.push({ start: node.name.getStart(sf), end: node.name.getEnd(), text: toLast })
217
+ }
218
+ // The first part changed: `product` in product.get, or the whole of a type's name.
181
219
  let head = node
182
220
  for (let i = p.length; i > 1 && ts.isPropertyAccessExpression(head); i--) head = head.expression
183
221
  while (ts.isParenthesizedExpression(head) || ts.isNonNullExpression(head) || ts.isAsExpression(head)) head = head.expression
184
- if (ts.isPropertyAccessExpression(head) && head.name.text === fromHead) {
222
+ if (fromHead === toHead) {
223
+ // Same namespace: only the function's name changed, and that is done above.
224
+ } else if (ts.isPropertyAccessExpression(head) && head.name.text === fromHead) {
185
225
  edits.push({ start: head.name.getStart(sf), end: head.name.getEnd(), text: toHead }) // SL.product → SL.products
186
226
  } else if (ts.isIdentifier(head) && imports.has(symbolOf(head)) && imports.get(symbolOf(head)).imported === fromHead) {
187
227
  const sym = symbolOf(head)
@@ -201,8 +241,17 @@ function analyseFile(ts, checker, sf, idx, rel) {
201
241
  const list = idx.lists.get(name)
202
242
  if (list) {
203
243
  const keys = call ? objectKeys(call) : new Set()
204
- const passes = (list.optionsRemoved || []).filter((o) => keys.has(o.split('.')[0]))
205
- push('list', node, name, { before: list.before, after: list.after, paged: !!list.paged, passes, called: !!call, note: list.note || '' })
244
+ const passes = (list.optionsRemoved || []).filter((o) => carries(keys, o))
245
+ // A list that used to return everything: has this call been decided? It has when it says how many
246
+ // it wants (`limit`), follows the pages (`cursor`, or it sits inside all() / each()), or is marked.
247
+ const line = lineOf(node)
248
+ const decided = !list.firstPageOnly ? null
249
+ : keys.has('cursor') ? 'follows the pages'
250
+ : keys.has('limit') ? 'says how many'
251
+ : insideWalk(node) ? 'inside all() / each()'
252
+ : markedAt(line) ? 'marked ok'
253
+ : false
254
+ push('list', node, name, { before: list.before, after: list.after, paged: !!list.paged, firstPageOnly: !!list.firstPageOnly, decided, passes, called: !!call, note: list.note || '' })
206
255
  }
207
256
  for (const opt of idx.options.get(name) || []) {
208
257
  if (typeof opt.argument === 'number') {
@@ -331,7 +380,7 @@ function analyseFile(ts, checker, sf, idx, rel) {
331
380
  const hint = (re, name, note) => {
332
381
  let m
333
382
  const g = new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g')
334
- while ((m = g.exec(text))) work.push({ kind: 'check', file: rel, line: text.slice(0, m.index).split('\n').length, name, note })
383
+ while ((m = g.exec(text))) { const line = text.slice(0, m.index).split('\n').length; work.push({ kind: 'check', file: rel, line, name, note, ok: markedAt(line) }) }
335
384
  }
336
385
  // A code compared with something that isn't UPPER_SNAKE: 'segments.list.failed', 'notFound'.
337
386
  hint(/\b(?:errorCode|details\??\.error(?:Code)?)\s*(?:===|!==|==|!=)\s*['"`](?![A-Z0-9_]+['"`])[^'"`]+['"`]/, 'error codes',
@@ -417,96 +466,203 @@ export function upgradeApp({ dir, major = '3', write = false, ts = null } = {})
417
466
  return result
418
467
  }
419
468
 
420
- // ── the report ───────────────────────────────────────────────────────────────────────────────────
469
+ // ── the passes ───────────────────────────────────────────────────────────────────────────────────
421
470
 
422
471
  const plural = (n, one, many = one + 's') => `${n} ${n === 1 ? one : many}`
423
472
 
424
- /** The plan as Markdown: what the script did (or would do), then the work left, file by file. */
425
- export function formatReport(result, { write = false } = {}) {
473
+ /**
474
+ * The move as a series of passes, in the order to do them. Each has the places still to change (`left`)
475
+ * and what decides it is finished (`judge`): this script, run again, or the app's own type-check.
476
+ * A pass the script judges is done when `left` is empty; do them in order, one at a time.
477
+ *
478
+ * automatic the renames and dropped arguments the script makes itself (--write)
479
+ * replace calls that no longer exist, and options that went: each needs a decision
480
+ * lists every list returns { items, nextCursor, count? } and takes the standard words: the
481
+ * type-check finds what is left (the script lists the calls, and judges the options)
482
+ * pages a list that used to return everything now returns one page: all of them, or a page?
483
+ * errors error codes compared as text, and the SDK read from window: found by search
484
+ */
485
+ export function passesOf(result, { write = false } = {}) {
486
+ const of = (kind) => result.work.filter((w) => w.kind === kind)
487
+ const edits = result.files.reduce((n, f) => n + f.edits, 0)
488
+ const manifestChange = !!(result.manifest && result.manifest.from !== result.manifest.to)
489
+ const lists = of('list')
490
+ const seen = new Set()
491
+ const checks = of('check').filter((w) => { const k = w.file + ':' + w.line + w.note; if (seen.has(k)) return false; seen.add(k); return true })
492
+ const pages = lists.filter((w) => w.firstPageOnly)
493
+ return [
494
+ {
495
+ id: 'automatic', title: 'Automatic changes', judge: 'script',
496
+ // After --write they are made: nothing is left unless the files could not be written.
497
+ left: write ? [] : [...result.files.map((f) => ({ file: f.file, edits: f.edits })), ...(manifestChange ? [{ file: result.manifest.file, edits: 1 }] : [])],
498
+ total: edits + (manifestChange ? 1 : 0),
499
+ how: 'Run `npx smartlinks-upgrade --write`.',
500
+ },
501
+ {
502
+ id: 'replace', title: 'Calls to replace and options that went', judge: 'script',
503
+ left: [...of('removed'), ...of('by-hand'), ...of('option'), ...of('option-check')],
504
+ how: 'Each is a call that no longer exists, or an option a call no longer takes. Replace it as the note says.',
505
+ },
506
+ {
507
+ id: 'lists', title: 'Lists: the new result and the standard words', judge: 'type-check',
508
+ // The script can see an option that is gone; whether `.items` is read is the type-check\'s to say.
509
+ left: lists.filter((w) => w.passes.length),
510
+ all: lists,
511
+ how: 'Read each list from `.items` (a total from `.count`, more from `.nextCursor`), page with `cursor`, and use `q`, `orderBy`, a date range and `expand`. Done when the app type-checks and no call here passes an option that is gone.',
512
+ },
513
+ {
514
+ id: 'pages', title: 'One page, or all of them', judge: 'script',
515
+ left: pages.filter((w) => w.decided === false),
516
+ decided: pages.filter((w) => w.decided),
517
+ how: 'Each of these returned everything in SDK 2 and returns 50 now. Where the app needs every item (it filters, counts, looks one up, fills a picker): `all((cursor) => theList(…, { limit: 200, cursor }))`. Where it shows a page: pass `limit` (and `cursor` for the next). Where the first 50 really is all that is wanted, or the options come from elsewhere: put `// sl-upgrade: ok <why>` on the line above.',
518
+ },
519
+ {
520
+ id: 'errors', title: 'Error codes and the SDK global', judge: 'script',
521
+ left: checks.filter((w) => !w.ok),
522
+ how: 'Found by search, so read each one. Where the code is right as it is, put `// sl-upgrade: ok <why>` on the line above.',
523
+ },
524
+ ]
525
+ }
526
+
527
+ /** Is there anything left in the passes this script judges (all of them, or just `only`)? */
528
+ export function leftToDo(result, { write = false, only = null } = {}) {
529
+ return passesOf(result, { write }).filter((p) => (only ? p.id === only : true)).reduce((n, p) => n + p.left.length, 0)
530
+ }
531
+
532
+ // ── the report ───────────────────────────────────────────────────────────────────────────────────
533
+
534
+ /** The plan as Markdown: the passes, then each pass's places, file by file. */
535
+ export function formatReport(result, { write = false, only = null } = {}) {
426
536
  const { table, work } = result
427
537
  const out = []
428
538
  const major = table.sdk.to
429
- out.push(`# Moving to SDK ${major}`, '')
539
+ const passes = passesOf(result, { write })
540
+ const pass = (id) => passes.find((p) => p.id === id)
541
+ const show = (id) => !only || only === id
542
+ const where = (w) => `\`${w.file}:${w.line}\``
543
+ const of = (kind) => work.filter((w) => w.kind === kind)
430
544
 
431
- const edits = result.files.reduce((n, f) => n + f.edits, 0)
432
- const manifestChange = result.manifest && result.manifest.from !== result.manifest.to
433
- out.push(`## ${write ? 'Done by the script' : 'What the script will change (run again with --write)'}`, '')
434
- if (!edits && !manifestChange) out.push('Nothing mechanical to change.', '')
435
- for (const f of result.files) out.push(`- \`${f.file}\`: ${plural(f.edits, 'edit')} (renamed calls, dropped arguments, imports)`)
436
- if (manifestChange) out.push(`- \`${result.manifest.file}\`: \`sharedDependencies\` ${result.manifest.from} → ${result.manifest.to}`)
437
- if (edits || manifestChange) out.push('')
545
+ out.push(`# Moving to SDK ${major}`, '')
438
546
 
439
- const of = (kind) => work.filter((w) => w.kind === kind)
440
- const where = (w) => `\`${w.file}:${w.line}\``
547
+ if (!only) {
548
+ out.push('## The passes', '',
549
+ 'Do them in this order, one at a time. A pass is finished when its check passes, not before:',
550
+ 'run `npx smartlinks-upgrade --check <pass>` (it exits 0 when nothing is left), or the type-check where it says so.', '',
551
+ '| | Pass | Left | Finished when |', '|---|---|---|---|')
552
+ const done = { script: 'nothing is left here', 'type-check': 'the app type-checks, and nothing is left here' }
553
+ passes.forEach((p, i) => {
554
+ const left = p.id === 'lists' ? `${plural(p.all.length, 'call')} to go through${p.left.length ? `, ${p.left.length} passing an option that is gone` : ''}`
555
+ : p.id === 'pages' ? `${p.left.length} to decide${p.decided.length ? `, ${p.decided.length} decided` : ''}`
556
+ : p.id === 'automatic' ? (write ? 'done' : plural(p.total, 'edit')) : String(p.left.length)
557
+ out.push(`| ${i + 1} | **${p.title}** (\`${p.id}\`) | ${left} | ${done[p.judge]} |`)
558
+ })
559
+ out.push('', 'Then build, run the SDK doctor and the app\'s own tests, and say which screens changed. Never release: the owner does.', '')
560
+ }
441
561
 
442
562
  const hold = of('hold')
443
- if (hold.length) {
563
+ if (hold.length && !only) {
444
564
  out.push('## Leave these as they are', '', hold[0].note, '')
445
565
  for (const w of hold) out.push(`- ${where(w)} \`${w.name}\``)
446
566
  out.push('')
447
567
  }
448
568
 
449
569
  const bad = result.packages.filter((p) => !p.ok)
450
- if (bad.length) {
570
+ if (bad.length && !only) {
451
571
  out.push('## Packages to update first', '')
452
572
  for (const p of bad) out.push(`- \`${p.name}\` ${p.version} is built for SDK \`${p.range}\`. Install a version built for SDK ${major}, or it will read the old shapes.`)
453
573
  out.push('')
454
574
  }
455
575
 
456
- const removed = [...of('removed'), ...of('by-hand')]
457
- if (removed.length) {
458
- out.push(`## Calls to replace (${removed.length})`, '')
459
- for (const w of removed) out.push(`- ${where(w)} \`${w.name}\`${w.to ? ` → \`${w.to}\`` : ''}. ${w.note}`)
460
- out.push('')
576
+ if (show('automatic')) {
577
+ const p = pass('automatic')
578
+ const manifestChange = result.manifest && result.manifest.from !== result.manifest.to
579
+ out.push(`## 1. ${p.title}`, '', write ? 'Made by the script:' : p.how, '')
580
+ if (!p.total) out.push('Nothing mechanical to change.', '')
581
+ for (const f of result.files) out.push(`- \`${f.file}\`: ${plural(f.edits, 'edit')} (renamed calls, dropped arguments, imports)`)
582
+ if (manifestChange) out.push(`- \`${result.manifest.file}\`: \`sharedDependencies\` ${result.manifest.from} → ${result.manifest.to}`)
583
+ if (p.total) out.push('')
461
584
  }
462
585
 
463
- const options = [...of('option'), ...of('option-check')]
464
- if (options.length) {
465
- out.push(`## Options that went (${options.length})`, '')
466
- for (const w of options) out.push(`- ${where(w)} \`${w.name}\` ${w.kind === 'option' ? 'passes' : 'may pass'} \`${w.option}\`. ${w.note}`)
467
- out.push('')
586
+ if (show('replace')) {
587
+ const p = pass('replace')
588
+ out.push(`## 2. ${p.title} (${p.left.length} left)`, '')
589
+ if (!p.left.length) out.push('Nothing left.', '')
590
+ else {
591
+ out.push(p.how, '')
592
+ for (const w of [...of('removed'), ...of('by-hand')]) out.push(`- ${where(w)} \`${w.name}\`${w.to ? ` → \`${w.to}\`` : ''}. ${w.note}`)
593
+ for (const w of [...of('option'), ...of('option-check')]) out.push(`- ${where(w)} \`${w.name}\` ${w.kind === 'option' ? 'passes' : 'may pass'} \`${w.option}\`. ${w.note}`)
594
+ out.push('')
595
+ }
468
596
  }
469
597
 
470
- const lists = of('list')
471
- if (lists.length) {
472
- out.push(`## Lists whose result changed (${lists.length})`, '',
473
- 'Each of these now returns `{ items, nextCursor, count? }`. At each place: read the list from `.items`,',
474
- 'a total from `.count`, "is there more" from `.nextCursor !== null`, and page with `cursor`, not `offset` or `page`.', '')
475
- const byFile = new Map()
476
- for (const w of lists) byFile.set(w.file, [...(byFile.get(w.file) || []), w])
477
- for (const [file, items] of byFile) {
478
- out.push(`### \`${file}\``, '')
479
- for (const w of items) {
480
- const bits = [`was \`${w.before}\``]
481
- if (w.passes.length) bits.push(`**passes ${w.passes.map((p) => '`' + p + '`').join(', ')}**, which is gone`)
482
- if (!w.paged) bits.push('not paged')
483
- if (!w.called) bits.push('passed as a value, not called here: follow it to where the result is read')
484
- if (w.note) bits.push(w.note)
485
- out.push(`- line ${w.line} \`${w.name}\`: ${bits.join('; ')}`)
598
+ if (show('lists')) {
599
+ const p = pass('lists')
600
+ out.push(`## 3. ${p.title} (${plural(p.all.length, 'call')})`, '')
601
+ if (!p.all.length) out.push('This app calls no list that changed.', '')
602
+ else {
603
+ out.push('Each of these now returns `{ items, nextCursor, count? }`. At each place: read the list from `.items`,',
604
+ 'a total from `.count`, "is there more" from `.nextCursor !== null`, and page with `cursor`, not `offset` or `page`.',
605
+ 'Search is `q`, sorting is `orderBy: [{ field: \'asc\' | \'desc\' }]`, a date field takes `{ gte, lte }`, related things are `expand`.', '',
606
+ '**Finished when the app type-checks** (`npx tsc --noEmit`) and no call below still passes an option that is gone.',
607
+ 'In a JavaScript app there is no type-check to lean on: go through every call below.', '')
608
+ const byFile = new Map()
609
+ for (const w of p.all) byFile.set(w.file, [...(byFile.get(w.file) || []), w])
610
+ for (const [file, items] of byFile) {
611
+ out.push(`### \`${file}\``, '')
612
+ for (const w of items) {
613
+ const bits = [`was \`${w.before}\``]
614
+ if (w.passes.length) bits.push(`**passes ${w.passes.map((o) => '`' + o + '`').join(', ')}**, which is gone`)
615
+ if (w.firstPageOnly) bits.push('**used to return everything**, now one page (pass 4)')
616
+ if (!w.paged) bits.push('always returned whole (no `limit` or `cursor`)')
617
+ if (!w.called) bits.push('passed as a value, not called here: follow it to where the result is read')
618
+ if (w.note) bits.push(w.note)
619
+ out.push(`- line ${w.line} \`${w.name}\`: ${bits.join('; ')}`)
620
+ }
621
+ out.push('')
486
622
  }
487
- out.push('')
488
623
  }
489
624
  }
490
625
 
491
- const checks = of('check')
492
- if (checks.length) {
493
- out.push(`## Check by hand (${checks.length})`, '')
494
- const seen = new Set()
495
- for (const w of checks) { const k = w.file + ':' + w.line + w.note; if (seen.has(k)) continue; seen.add(k); out.push(`- ${where(w)} ${w.note}`) }
496
- out.push('')
626
+ if (show('pages')) {
627
+ const p = pass('pages')
628
+ out.push(`## 4. ${p.title} (${p.left.length} to decide${p.decided.length ? `, ${p.decided.length} decided` : ''})`, '')
629
+ if (!p.left.length && !p.decided.length) out.push('This app calls no list that used to return everything.', '')
630
+ else {
631
+ out.push(p.how, '',
632
+ 'This is the change that breaks an app quietly: code that reads `.items` compiles and runs, and is wrong once there are more than 50.', '')
633
+ for (const w of p.left) out.push(`- ${where(w)} \`${w.name}\`${w.called ? '' : ' (passed as a value, not called here)'}`)
634
+ if (p.left.length) out.push('')
635
+ if (p.decided.length) {
636
+ out.push('Decided:', '')
637
+ for (const w of p.decided) out.push(`- ${where(w)} \`${w.name}\`: ${w.decided}`)
638
+ out.push('')
639
+ }
640
+ }
641
+ }
642
+
643
+ if (show('errors')) {
644
+ const p = pass('errors')
645
+ out.push(`## 5. ${p.title} (${p.left.length} left)`, '')
646
+ if (!p.left.length) out.push('Nothing left.', '')
647
+ else { out.push(p.how, ''); for (const w of p.left) out.push(`- ${where(w)} ${w.note}`); out.push('') }
497
648
  }
498
649
 
499
- out.push('## What no script can see', '')
500
- for (const b of result.behaviour) out.push(`- **${b.name}.** ${b.note}`)
501
- for (const f of result.fields) out.push(`- **\`${f.name}\`** (a field).${f.to ? ` Use \`${f.to}\`.` : ''} ${f.note}`)
502
- out.push('', `Everything above is explained in \`docs/${path.basename(table.guide)}\` in this package.`, '')
650
+ if (!only) {
651
+ out.push('## What no script can see', '')
652
+ for (const b of result.behaviour) out.push(`- **${b.name}.** ${b.note}`)
653
+ for (const f of result.fields) out.push(`- **\`${f.name}\`** (a field).${f.to ? ` Use \`${f.to}\`.` : ''} ${f.note}`)
654
+ out.push('', `Everything above is explained in \`docs/${path.basename(table.guide)}\` in this package.`, '')
655
+ }
503
656
  return out.join('\n')
504
657
  }
505
658
 
506
659
  /** One line for a log. */
507
- export function summary(result) {
660
+ export function summary(result, { write = false } = {}) {
508
661
  const n = (k) => result.work.filter((w) => w.kind === k).length
662
+ const passes = passesOf(result, { write })
663
+ const left = (id) => passes.find((p) => p.id === id).left.length
509
664
  return `${plural(result.files.reduce((a, f) => a + f.edits, 0), 'mechanical edit')} in ${plural(result.files.length, 'file')}; `
510
- + `left to do: ${plural(n('list'), 'list call')}, ${plural(n('removed') + n('by-hand'), 'call')} to replace, ${plural(n('option') + n('option-check'), 'option')}, ${plural(n('check'), 'check')}`
665
+ + `left to do: ${plural(left('replace'), 'call or option')} to replace, ${plural(n('list'), 'list call')} to go through, `
666
+ + `${plural(left('pages'), 'list')} to decide (one page or all), ${plural(left('errors'), 'check')}`
511
667
  + (n('hold') ? `; ${plural(n('hold'), 'call')} to leave alone` : '')
512
668
  }
@@ -7,25 +7,43 @@
7
7
  // to. It works from upgrade/<major>.json in this package: the same table the guide
8
8
  // docs/upgrading-to-<major>.md is filled from.
9
9
  //
10
+ // The move is a series of passes, done in order, one at a time. Each is finished when its check
11
+ // passes, not when it looks finished:
12
+ //
13
+ // automatic the renames the script makes itself
14
+ // replace calls that no longer exist, options that went
15
+ // lists every list's new result and the standard words (the type-check finishes this one)
16
+ // pages a list that used to return everything: one page, or all of them?
17
+ // errors error codes compared as text, the SDK read from window
18
+ //
10
19
  // Usage (in the app, with this SDK major installed):
11
- // npx smartlinks-upgrade # show what it would change, and the work left
12
- // npx smartlinks-upgrade --write # make the mechanical changes
13
- // npx smartlinks-upgrade --report FILE # also save the list as Markdown
14
- // npx smartlinks-upgrade [appDir] --json # the plan as JSON
20
+ // npx smartlinks-upgrade # the passes, and every place left in each
21
+ // npx smartlinks-upgrade --write # make the automatic changes
22
+ // npx smartlinks-upgrade --check # is anything left? exits 0 when nothing is, 2 when something is
23
+ // npx smartlinks-upgrade --check pages # the same for one pass, listing only its places
24
+ // npx smartlinks-upgrade --report FILE # also save what is printed as Markdown
25
+ // npx smartlinks-upgrade [appDir] --json # the plan as JSON (with `passes`)
26
+ //
27
+ // A place only a person can judge (the first page is all that's wanted; a comparison is right as it
28
+ // is) is settled by a comment on the line above it: // sl-upgrade: ok <why>
15
29
  //
16
30
  // It never installs, builds, commits or releases anything.
17
- // Exit code: 0 = ran; 1 = could not run (no TypeScript, unreadable app).
31
+ // Exit code: 0 = ran (with --check: nothing left); 1 = could not run (no TypeScript, unreadable app);
32
+ // 2 = --check found places left.
18
33
  // =============================================================================
19
34
 
20
35
  import fs from 'node:fs'
21
36
  import path from 'node:path'
22
37
  import { fileURLToPath } from 'node:url'
23
- import { upgradeApp, formatReport, summary } from './lib/upgrade.mjs'
38
+ import { upgradeApp, formatReport, summary, passesOf, leftToDo } from './lib/upgrade.mjs'
24
39
 
40
+ const PASSES = ['automatic', 'replace', 'lists', 'pages', 'errors']
25
41
  const args = process.argv.slice(2)
26
42
  const flag = (name) => args.includes(name)
27
43
  const value = (name) => { const i = args.indexOf(name); return i >= 0 ? args[i + 1] : null }
28
- const positional = args.filter((a, i) => !a.startsWith('--') && args[i - 1] !== '--report' && args[i - 1] !== '--to')
44
+ // `--check` may be followed by a pass name.
45
+ const checkPass = flag('--check') && PASSES.includes(value('--check')) ? value('--check') : null
46
+ const positional = args.filter((a, i) => !a.startsWith('--') && args[i - 1] !== '--report' && args[i - 1] !== '--to' && !(args[i - 1] === '--check' && a === checkPass))
29
47
 
30
48
  if (flag('--help') || flag('-h')) {
31
49
  console.log(fs.readFileSync(fileURLToPath(import.meta.url), 'utf8').split('\n').filter((l) => l.startsWith('//')).map((l) => l.slice(3)).join('\n'))
@@ -37,16 +55,20 @@ const own = JSON.parse(fs.readFileSync(path.join(here, '..', 'package.json'), 'u
37
55
  const major = value('--to') || String(own.version).split('.')[0]
38
56
  const dir = path.resolve(positional[0] || process.cwd())
39
57
  const write = flag('--write')
58
+ const check = flag('--check')
40
59
 
60
+ let left = 0
41
61
  try {
42
62
  const result = upgradeApp({ dir, major, write })
63
+ left = leftToDo(result, { write, only: checkPass })
43
64
  if (flag('--json')) {
44
65
  const { table: _t, ...plain } = result
45
- console.log(JSON.stringify(plain, null, 2))
66
+ console.log(JSON.stringify({ ...plain, passes: passesOf(result, { write }), left }, null, 2))
46
67
  } else {
47
- const report = formatReport(result, { write })
68
+ const report = formatReport(result, { write, only: checkPass })
48
69
  console.log(report)
49
- console.log(summary(result))
70
+ console.log(summary(result, { write }))
71
+ if (check) console.log(left ? `${left} left${checkPass ? ` in "${checkPass}"` : ''}: not finished.` : `Nothing left${checkPass ? ` in "${checkPass}"` : ''}.`)
50
72
  const to = value('--report')
51
73
  if (to) { fs.mkdirSync(path.dirname(path.resolve(dir, to)), { recursive: true }); fs.writeFileSync(path.resolve(dir, to), report); console.log(`Saved to ${to}`) }
52
74
  }
@@ -54,3 +76,4 @@ try {
54
76
  console.error(`smartlinks-upgrade: ${e && e.message ? e.message : e}`)
55
77
  process.exit(1)
56
78
  }
79
+ if (check && left) process.exit(2)