@proveanything/smartlinks 3.0.0-alpha.1 → 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.
- package/README.md +7 -7
- package/dist/api/analytics.d.ts +5 -4
- package/dist/api/analytics.js +5 -4
- package/dist/api/appConfiguration.d.ts +23 -18
- package/dist/api/appConfiguration.js +24 -18
- package/dist/api/appObjects.d.ts +54 -10
- package/dist/api/appObjects.js +75 -40
- package/dist/api/asset.d.ts +28 -22
- package/dist/api/asset.js +45 -56
- package/dist/api/attestation.d.ts +11 -3
- package/dist/api/attestation.js +12 -3
- package/dist/api/attestations.d.ts +12 -8
- package/dist/api/attestations.js +18 -21
- package/dist/api/authKit.d.ts +15 -10
- package/dist/api/authKit.js +17 -11
- package/dist/api/batch.d.ts +36 -25
- package/dist/api/batch.js +46 -39
- package/dist/api/bookings.d.ts +18 -9
- package/dist/api/bookings.js +23 -13
- package/dist/api/broadcasts.js +3 -17
- package/dist/api/claimSet.d.ts +26 -12
- package/dist/api/claimSet.js +32 -24
- package/dist/api/collection.d.ts +15 -10
- package/dist/api/collection.js +17 -11
- package/dist/api/comms.d.ts +12 -6
- package/dist/api/comms.js +12 -6
- package/dist/api/conditions.d.ts +7 -6
- package/dist/api/conditions.js +8 -6
- package/dist/api/contact.d.ts +6 -2
- package/dist/api/contact.js +25 -60
- package/dist/api/containers.d.ts +14 -10
- package/dist/api/containers.js +19 -14
- package/dist/api/crate.js +7 -9
- package/dist/api/dpp.d.ts +20 -13
- package/dist/api/dpp.js +23 -15
- package/dist/api/facets.d.ts +38 -13
- package/dist/api/facets.js +40 -15
- package/dist/api/files.d.ts +5 -2
- package/dist/api/files.js +7 -4
- package/dist/api/form.d.ts +8 -5
- package/dist/api/form.js +9 -5
- package/dist/api/index.d.ts +0 -1
- package/dist/api/index.js +0 -1
- package/dist/api/integrations.d.ts +29 -17
- package/dist/api/integrations.js +32 -25
- package/dist/api/interactions.d.ts +11 -6
- package/dist/api/interactions.js +14 -23
- package/dist/api/jobs.d.ts +16 -6
- package/dist/api/jobs.js +30 -20
- package/dist/api/journeys.js +2 -14
- package/dist/api/journeysAnalytics.d.ts +8 -5
- package/dist/api/journeysAnalytics.js +8 -5
- package/dist/api/knowledge.d.ts +20 -14
- package/dist/api/knowledge.js +22 -15
- package/dist/api/location.d.ts +6 -3
- package/dist/api/location.js +8 -22
- package/dist/api/lots.d.ts +9 -5
- package/dist/api/lots.js +22 -26
- package/dist/api/loyalty.d.ts +25 -16
- package/dist/api/loyalty.js +33 -32
- package/dist/api/nfc.d.ts +3 -1
- package/dist/api/nfc.js +3 -1
- package/dist/api/order.d.ts +45 -39
- package/dist/api/order.js +48 -65
- package/dist/api/partner.d.ts +17 -14
- package/dist/api/partner.js +21 -22
- package/dist/api/products.d.ts +35 -12
- package/dist/api/products.js +36 -13
- package/dist/api/proof.d.ts +41 -19
- package/dist/api/proof.js +44 -23
- package/dist/api/segments.js +3 -15
- package/dist/api/serviceAccounts.d.ts +8 -5
- package/dist/api/serviceAccounts.js +9 -6
- package/dist/api/shop.d.ts +7 -5
- package/dist/api/shop.js +13 -19
- package/dist/api/subscriptions.d.ts +12 -10
- package/dist/api/subscriptions.js +17 -25
- package/dist/api/tags.d.ts +23 -20
- package/dist/api/tags.js +40 -52
- package/dist/api/template.d.ts +16 -11
- package/dist/api/template.js +19 -13
- package/dist/api/translations.js +2 -12
- package/dist/api/userGroups.d.ts +26 -16
- package/dist/api/userGroups.js +43 -30
- package/dist/api/variant.d.ts +10 -7
- package/dist/api/variant.js +11 -7
- package/dist/api/wallet.d.ts +14 -11
- package/dist/api/wallet.js +15 -12
- package/dist/docs/API_SUMMARY.md +289 -483
- package/dist/docs/ai.md +15 -15
- package/dist/docs/analytics.md +1 -1
- package/dist/docs/app-objects.md +4 -4
- package/dist/docs/attestations.md +8 -8
- package/dist/docs/contact-search.md +2 -3
- package/dist/docs/knowledge.md +3 -3
- package/dist/docs/lists.md +58 -15
- package/dist/docs/upgrading-to-3.md +238 -136
- package/dist/list.d.ts +12 -0
- package/dist/list.js +59 -0
- package/dist/openapi.yaml +301 -662
- package/dist/types/analytics.d.ts +7 -3
- package/dist/types/appObjects.d.ts +27 -12
- package/dist/types/appOptions.d.ts +2 -2
- package/dist/types/asset.d.ts +5 -6
- package/dist/types/attestations.d.ts +7 -9
- package/dist/types/batch.d.ts +5 -5
- package/dist/types/bookings.d.ts +10 -5
- package/dist/types/comms.d.ts +9 -5
- package/dist/types/contact.d.ts +7 -4
- package/dist/types/containers.d.ts +2 -1
- package/dist/types/facets.d.ts +14 -2
- package/dist/types/files.d.ts +3 -2
- package/dist/types/integrations.d.ts +2 -1
- package/dist/types/interaction.d.ts +15 -7
- package/dist/types/jobs.d.ts +1 -1
- package/dist/types/journeysAnalytics.d.ts +3 -2
- package/dist/types/knowledge.d.ts +6 -3
- package/dist/types/knowledge.js +0 -1
- package/dist/types/list.d.ts +30 -2
- package/dist/types/location.d.ts +7 -2
- package/dist/types/location.js +0 -1
- package/dist/types/lots.d.ts +5 -2
- package/dist/types/lots.js +0 -6
- package/dist/types/order.d.ts +22 -20
- package/dist/types/product.d.ts +28 -11
- package/dist/types/proof.d.ts +7 -8
- package/dist/types/tags.d.ts +5 -3
- package/dist/types/userGroups.d.ts +3 -3
- package/dist/types/userGroups.js +0 -4
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/API_SUMMARY.md +289 -483
- package/docs/ai.md +15 -15
- package/docs/analytics.md +1 -1
- package/docs/app-objects.md +4 -4
- package/docs/attestations.md +8 -8
- package/docs/contact-search.md +2 -3
- package/docs/knowledge.md +3 -3
- package/docs/lists.md +58 -15
- package/docs/upgrading-to-3.md +238 -136
- package/openapi.yaml +301 -662
- package/package.json +1 -1
- package/scripts/lib/upgrade.mjs +216 -60
- package/scripts/upgrade.mjs +33 -10
- package/upgrade/3.json +2731 -2213
package/package.json
CHANGED
package/scripts/lib/upgrade.mjs
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
|
205
|
-
|
|
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)))
|
|
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
|
|
469
|
+
// ── the passes ───────────────────────────────────────────────────────────────────────────────────
|
|
421
470
|
|
|
422
471
|
const plural = (n, one, many = one + 's') => `${n} ${n === 1 ? one : many}`
|
|
423
472
|
|
|
424
|
-
/**
|
|
425
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
440
|
-
|
|
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
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
464
|
-
|
|
465
|
-
out.push(`##
|
|
466
|
-
|
|
467
|
-
|
|
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
|
-
|
|
471
|
-
|
|
472
|
-
out.push(`##
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|
-
|
|
492
|
-
|
|
493
|
-
out.push(`##
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
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
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
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(
|
|
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
|
}
|
package/scripts/upgrade.mjs
CHANGED
|
@@ -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 #
|
|
12
|
-
// npx smartlinks-upgrade --write # make the
|
|
13
|
-
// npx smartlinks-upgrade --
|
|
14
|
-
// npx smartlinks-upgrade
|
|
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
|
-
|
|
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)
|