jazz-tools 2.0.0-alpha.70 → 2.0.0-beta.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.
Files changed (238) hide show
  1. package/README.md +2 -3
  2. package/bin/jazz-tools.js +0 -3
  3. package/dist/accounts/account-manager-core.d.ts +54 -1
  4. package/dist/accounts/account-manager-core.d.ts.map +1 -1
  5. package/dist/accounts/account-manager-core.js +2 -2
  6. package/dist/accounts/account-manager-core.js.map +1 -1
  7. package/dist/accounts/context.js +1 -1
  8. package/dist/accounts/context.js.map +1 -1
  9. package/dist/backend/api.d.ts +1 -2
  10. package/dist/backend/api.d.ts.map +1 -1
  11. package/dist/backend/api.js +0 -2
  12. package/dist/backend/api.js.map +1 -1
  13. package/dist/backend/create-jazz.d.ts +0 -6
  14. package/dist/backend/create-jazz.d.ts.map +1 -1
  15. package/dist/backend/create-jazz.js +1 -1
  16. package/dist/backend/create-jazz.js.map +1 -1
  17. package/dist/backend/inspector-ui/11.js +2 -2
  18. package/dist/backend/inspector-ui/12.js +2 -2
  19. package/dist/backend/inspector-ui/13.js +2 -2
  20. package/dist/backend/inspector-ui/14.js +2 -2
  21. package/dist/backend/inspector-ui/20.js +1 -1
  22. package/dist/backend/inspector-ui-files.js +4 -4
  23. package/dist/backend/no-account-error.d.ts +1 -1
  24. package/dist/backend/no-account-error.js +1 -1
  25. package/dist/backend/no-account-error.js.map +1 -1
  26. package/dist/cli.d.ts +0 -1
  27. package/dist/cli.d.ts.map +1 -1
  28. package/dist/cli.js +8 -22
  29. package/dist/cli.js.map +1 -1
  30. package/dist/client/index.d.ts +0 -1
  31. package/dist/client/index.d.ts.map +1 -1
  32. package/dist/client/index.js +0 -2
  33. package/dist/client/index.js.map +1 -1
  34. package/dist/dev/app-files.js +1 -1
  35. package/dist/dev/app-files.js.map +1 -1
  36. package/dist/dev/catalogue-api.d.ts.map +1 -1
  37. package/dist/dev/catalogue-api.js +3 -6
  38. package/dist/dev/catalogue-api.js.map +1 -1
  39. package/dist/dev/inspector-overlay/embedded/assets/{index-D3RK8wNj.js → index-DUKUt96e.js} +3 -3
  40. package/dist/dev/inspector-overlay/embedded/assets/{jazz-broker-worker-EyaWhBtz.js → jazz-broker-worker-C_mr9Omd.js} +2 -2
  41. package/dist/dev/inspector-overlay/embedded/assets/{jazz_wasm-O10pptvY.js → jazz_wasm-BOvbCHn3.js} +1 -1
  42. package/dist/dev/inspector-overlay/embedded/assets/{jazz_wasm_bg-wI43fvvq.wasm → jazz_wasm_bg-BG8gazqt.wasm} +0 -0
  43. package/dist/dev/inspector-overlay/embedded/embedded.html +1 -1
  44. package/dist/dev/project.js +1 -1
  45. package/dist/dev/project.js.map +1 -1
  46. package/dist/dev/ts-project.d.ts.map +1 -1
  47. package/dist/dev/ts-project.js +3 -2
  48. package/dist/dev/ts-project.js.map +1 -1
  49. package/dist/expo/create-account-manager.d.ts +1 -1
  50. package/dist/expo/create-account-manager.js.map +1 -1
  51. package/dist/expo/index.d.ts +1 -2
  52. package/dist/expo/index.d.ts.map +1 -1
  53. package/dist/expo/index.js +1 -3
  54. package/dist/expo/index.js.map +1 -1
  55. package/dist/index.d.ts +0 -2
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +0 -4
  58. package/dist/index.js.map +1 -1
  59. package/dist/printer/index.d.ts +2 -2
  60. package/dist/printer/index.d.ts.map +1 -1
  61. package/dist/printer/index.js +4 -1
  62. package/dist/printer/index.js.map +1 -1
  63. package/dist/react/index.d.ts +1 -2
  64. package/dist/react/index.d.ts.map +1 -1
  65. package/dist/react/index.js +1 -3
  66. package/dist/react/index.js.map +1 -1
  67. package/dist/react/provider.d.ts +0 -2
  68. package/dist/react/provider.d.ts.map +1 -1
  69. package/dist/react/provider.js +1 -2
  70. package/dist/react/provider.js.map +1 -1
  71. package/dist/react-core/index.d.ts +1 -2
  72. package/dist/react-core/index.d.ts.map +1 -1
  73. package/dist/react-core/index.js +3 -5
  74. package/dist/react-core/index.js.map +1 -1
  75. package/dist/react-core/provider.d.ts +0 -8
  76. package/dist/react-core/provider.d.ts.map +1 -1
  77. package/dist/react-core/provider.js +0 -13
  78. package/dist/react-core/provider.js.map +1 -1
  79. package/dist/react-native/create-account-manager.d.ts +1 -1
  80. package/dist/react-native/create-account-manager.js.map +1 -1
  81. package/dist/react-native/index.d.ts +1 -3
  82. package/dist/react-native/index.d.ts.map +1 -1
  83. package/dist/react-native/index.js +1 -5
  84. package/dist/react-native/index.js.map +1 -1
  85. package/dist/react-native/provider.d.ts +0 -2
  86. package/dist/react-native/provider.d.ts.map +1 -1
  87. package/dist/react-native/provider.js +1 -2
  88. package/dist/react-native/provider.js.map +1 -1
  89. package/dist/runtime/db.d.ts +0 -5
  90. package/dist/runtime/db.d.ts.map +1 -1
  91. package/dist/runtime/db.js +0 -5
  92. package/dist/runtime/db.js.map +1 -1
  93. package/dist/runtime/native-artifact-fingerprint-napi.d.ts +1 -1
  94. package/dist/runtime/native-artifact-fingerprint-napi.js +1 -1
  95. package/dist/runtime/native-artifact-fingerprint-napi.js.map +1 -1
  96. package/dist/runtime/native-artifact-fingerprint-wasm.d.ts +1 -1
  97. package/dist/runtime/native-artifact-fingerprint-wasm.js +1 -1
  98. package/dist/runtime/native-artifact-fingerprint-wasm.js.map +1 -1
  99. package/dist/runtime/native-artifact-fingerprints.d.ts +2 -2
  100. package/dist/schema-builders.d.ts +0 -7
  101. package/dist/schema-builders.d.ts.map +1 -1
  102. package/dist/schema-builders.js +0 -7
  103. package/dist/schema-builders.js.map +1 -1
  104. package/dist/session/create-jazz-session.d.ts +1 -1
  105. package/dist/session/create-jazz-session.d.ts.map +1 -1
  106. package/dist/session/create-jazz-session.js.map +1 -1
  107. package/dist/solid/index.d.ts +1 -2
  108. package/dist/solid/index.d.ts.map +1 -1
  109. package/dist/solid/index.js +7 -8
  110. package/dist/solid/index.ssr.js +2 -3
  111. package/dist/solid/provider.d.ts +1 -12
  112. package/dist/solid/provider.d.ts.map +1 -1
  113. package/dist/solid/provider.js +12 -18
  114. package/dist/solid/provider.js.map +1 -1
  115. package/dist/solid/provider.ssr.js +1 -11
  116. package/dist/solid/provider.ssr.js.map +1 -1
  117. package/dist/svelte/context.svelte.d.ts +1 -12
  118. package/dist/svelte/context.svelte.d.ts.map +1 -1
  119. package/dist/svelte/context.svelte.js +2 -20
  120. package/dist/svelte/index.d.ts +1 -2
  121. package/dist/svelte/index.d.ts.map +1 -1
  122. package/dist/svelte/index.js +1 -3
  123. package/dist/thin/index.d.ts +0 -1
  124. package/dist/thin/index.d.ts.map +1 -1
  125. package/dist/thin/index.js +0 -2
  126. package/dist/thin/index.js.map +1 -1
  127. package/dist/typed-app.d.ts +1 -1
  128. package/dist/typed-app.js.map +1 -1
  129. package/dist/vue/index.d.ts +1 -2
  130. package/dist/vue/index.d.ts.map +1 -1
  131. package/dist/vue/index.js +1 -3
  132. package/dist/vue/index.js.map +1 -1
  133. package/dist/vue/provider.d.ts +2 -35
  134. package/dist/vue/provider.d.ts.map +1 -1
  135. package/dist/vue/provider.js +1 -135
  136. package/dist/vue/provider.js.map +1 -1
  137. package/dist/web/lazy-local-first.d.ts +0 -3
  138. package/dist/web/lazy-local-first.d.ts.map +1 -1
  139. package/dist/web/lazy-local-first.js +1 -6
  140. package/dist/web/lazy-local-first.js.map +1 -1
  141. package/dist/worker/jazz-broker-worker.js +2 -2
  142. package/dist/worker/jazz_wasm_bg.wasm +0 -0
  143. package/package.json +4 -8
  144. package/dist/accounts/create-account-manager.d.ts +0 -57
  145. package/dist/accounts/create-account-manager.d.ts.map +0 -1
  146. package/dist/accounts/create-account-manager.js +0 -17
  147. package/dist/accounts/create-account-manager.js.map +0 -1
  148. package/dist/permissions/index.d.ts +0 -5
  149. package/dist/permissions/index.d.ts.map +0 -1
  150. package/dist/permissions/index.js +0 -11
  151. package/dist/permissions/index.js.map +0 -1
  152. package/dist/removed-api.d.ts +0 -87
  153. package/dist/removed-api.d.ts.map +0 -1
  154. package/dist/removed-api.js +0 -95
  155. package/dist/removed-api.js.map +0 -1
  156. package/dist/removed-schema-api.d.ts +0 -80
  157. package/dist/removed-schema-api.d.ts.map +0 -1
  158. package/dist/removed-schema-api.js +0 -128
  159. package/dist/removed-schema-api.js.map +0 -1
  160. package/dist/session/deprecated-session-hook.d.ts +0 -8
  161. package/dist/session/deprecated-session-hook.d.ts.map +0 -1
  162. package/dist/session/deprecated-session-hook.js +0 -28
  163. package/dist/session/deprecated-session-hook.js.map +0 -1
  164. package/dist/svelte/JazzSvelteProvider.svelte +0 -181
  165. package/dist/svelte/JazzSvelteProvider.svelte.d.ts +0 -14
  166. package/dist/svelte/JazzSvelteProvider.svelte.d.ts.map +0 -1
  167. package/dist/upgrade/aliases.d.ts +0 -25
  168. package/dist/upgrade/aliases.d.ts.map +0 -1
  169. package/dist/upgrade/aliases.js +0 -80
  170. package/dist/upgrade/aliases.js.map +0 -1
  171. package/dist/upgrade/app-json.d.ts +0 -32
  172. package/dist/upgrade/app-json.d.ts.map +0 -1
  173. package/dist/upgrade/app-json.js +0 -145
  174. package/dist/upgrade/app-json.js.map +0 -1
  175. package/dist/upgrade/constants.d.ts +0 -25
  176. package/dist/upgrade/constants.d.ts.map +0 -1
  177. package/dist/upgrade/constants.js +0 -136
  178. package/dist/upgrade/constants.js.map +0 -1
  179. package/dist/upgrade/edits.d.ts +0 -10
  180. package/dist/upgrade/edits.d.ts.map +0 -1
  181. package/dist/upgrade/edits.js +0 -21
  182. package/dist/upgrade/edits.js.map +0 -1
  183. package/dist/upgrade/errors.d.ts +0 -12
  184. package/dist/upgrade/errors.d.ts.map +0 -1
  185. package/dist/upgrade/errors.js +0 -18
  186. package/dist/upgrade/errors.js.map +0 -1
  187. package/dist/upgrade/extras.d.ts +0 -42
  188. package/dist/upgrade/extras.d.ts.map +0 -1
  189. package/dist/upgrade/extras.js +0 -487
  190. package/dist/upgrade/extras.js.map +0 -1
  191. package/dist/upgrade/fresh.d.ts +0 -36
  192. package/dist/upgrade/fresh.d.ts.map +0 -1
  193. package/dist/upgrade/fresh.js +0 -154
  194. package/dist/upgrade/fresh.js.map +0 -1
  195. package/dist/upgrade/index.d.ts +0 -79
  196. package/dist/upgrade/index.d.ts.map +0 -1
  197. package/dist/upgrade/index.js +0 -806
  198. package/dist/upgrade/index.js.map +0 -1
  199. package/dist/upgrade/json-only.d.ts +0 -24
  200. package/dist/upgrade/json-only.d.ts.map +0 -1
  201. package/dist/upgrade/json-only.js +0 -124
  202. package/dist/upgrade/json-only.js.map +0 -1
  203. package/dist/upgrade/names.d.ts +0 -29
  204. package/dist/upgrade/names.d.ts.map +0 -1
  205. package/dist/upgrade/names.js +0 -105
  206. package/dist/upgrade/names.js.map +0 -1
  207. package/dist/upgrade/payload-enums.d.ts +0 -18
  208. package/dist/upgrade/payload-enums.d.ts.map +0 -1
  209. package/dist/upgrade/payload-enums.js +0 -52
  210. package/dist/upgrade/payload-enums.js.map +0 -1
  211. package/dist/upgrade/permissions-check.d.ts +0 -10
  212. package/dist/upgrade/permissions-check.d.ts.map +0 -1
  213. package/dist/upgrade/permissions-check.js +0 -85
  214. package/dist/upgrade/permissions-check.js.map +0 -1
  215. package/dist/upgrade/program.d.ts +0 -18
  216. package/dist/upgrade/program.d.ts.map +0 -1
  217. package/dist/upgrade/program.js +0 -56
  218. package/dist/upgrade/program.js.map +0 -1
  219. package/dist/upgrade/project.d.ts +0 -56
  220. package/dist/upgrade/project.d.ts.map +0 -1
  221. package/dist/upgrade/project.js +0 -254
  222. package/dist/upgrade/project.js.map +0 -1
  223. package/dist/upgrade/rewrite.d.ts +0 -34
  224. package/dist/upgrade/rewrite.d.ts.map +0 -1
  225. package/dist/upgrade/rewrite.js +0 -500
  226. package/dist/upgrade/rewrite.js.map +0 -1
  227. package/dist/upgrade/schema-ts.d.ts +0 -59
  228. package/dist/upgrade/schema-ts.d.ts.map +0 -1
  229. package/dist/upgrade/schema-ts.js +0 -582
  230. package/dist/upgrade/schema-ts.js.map +0 -1
  231. package/dist/upgrade/snapshot.d.ts +0 -11
  232. package/dist/upgrade/snapshot.d.ts.map +0 -1
  233. package/dist/upgrade/snapshot.js +0 -90
  234. package/dist/upgrade/snapshot.js.map +0 -1
  235. package/dist/upgrade/upgrade-test-helpers.d.ts +0 -12
  236. package/dist/upgrade/upgrade-test-helpers.d.ts.map +0 -1
  237. package/dist/upgrade/upgrade-test-helpers.js +0 -72
  238. package/dist/upgrade/upgrade-test-helpers.js.map +0 -1
@@ -1,10 +0,0 @@
1
- import type { Project } from "./project.js";
2
- /**
3
- * Where schema.ts, permissions.ts or the project files they import read the
4
- * environment. The printed policies hold the values validate resolved them
5
- * to, so upgrade warns about each rather than refuse.
6
- */
7
- export declare function environmentReads(project: Project, files: string[]): string[];
8
- /** Refuse `"true"` inside `anyOf` / `allOf` of jazz.permissions.json: the trace of a condition that compiled to nothing. */
9
- export declare function refuseDroppedConditions(project: Project): void;
10
- //# sourceMappingURL=permissions-check.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"permissions-check.d.ts","sourceRoot":"","sources":["../../src/upgrade/permissions-check.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CA8B5E;AAED,4HAA4H;AAC5H,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAgC9D"}
@@ -1,85 +0,0 @@
1
- /**
2
- * Permissions alpha.65 compiled from values that aren't in the source. Its
3
- * DSL ran permissions.ts when validate ran, so a `process.env` read became
4
- * whatever it was then (upgrade prints that value and warns), and a
5
- * `where({ col: undefined })` compiled to no condition at all, `"true"`
6
- * (upgrade refuses: the printed policy would allow more than its author
7
- * wrote).
8
- */
9
- import { readFileSync } from "node:fs";
10
- import { relative } from "node:path";
11
- import { isObject, parseJsonOrdered, entriesOf } from "./app-json.js";
12
- import { UpgradeRefusal } from "./errors.js";
13
- /**
14
- * Where schema.ts, permissions.ts or the project files they import read the
15
- * environment. The printed policies hold the values validate resolved them
16
- * to, so upgrade warns about each rather than refuse.
17
- */
18
- export function environmentReads(project, files) {
19
- const { ts } = project;
20
- const found = [];
21
- for (const file of files) {
22
- const text = readFileSync(file, "utf8");
23
- if (!/\b(?:process\.env|import\.meta\.env)\b/.test(text))
24
- continue;
25
- const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);
26
- const visit = (node) => {
27
- if (ts.isPropertyAccessExpression(node) && node.name.text === "env") {
28
- const target = node.expression;
29
- const isProcess = ts.isIdentifier(target) && target.text === "process";
30
- const isImportMeta = ts.isMetaProperty(target);
31
- if (isProcess || isImportMeta) {
32
- const parent = node.parent;
33
- const read = ts.isPropertyAccessExpression(parent) && parent.expression === node
34
- ? parent.getText(source)
35
- : ts.isElementAccessExpression(parent) && parent.expression === node
36
- ? parent.getText(source)
37
- : node.getText(source);
38
- const { line } = source.getLineAndCharacterOfPosition(node.getStart(source));
39
- found.push(`${relative(project.root, file) || file}:${line + 1}: reads \`${read}\``);
40
- return;
41
- }
42
- }
43
- ts.forEachChild(node, visit);
44
- };
45
- visit(source);
46
- }
47
- return found;
48
- }
49
- /** Refuse `"true"` inside `anyOf` / `allOf` of jazz.permissions.json: the trace of a condition that compiled to nothing. */
50
- export function refuseDroppedConditions(project) {
51
- let permissions;
52
- try {
53
- permissions = parseJsonOrdered(readFileSync(project.permissionsJsonFile, "utf8"));
54
- }
55
- catch {
56
- return; // the old validate already refused an unreadable file
57
- }
58
- const found = [];
59
- const walk = (value, path, combined) => {
60
- if (value === "true" && combined)
61
- found.push(path);
62
- else if (Array.isArray(value))
63
- value.forEach((item, i) => walk(item, `${path}[${i}]`, combined));
64
- else if (isObject(value)) {
65
- for (const [key, item] of entriesOf(value)) {
66
- if (key === "$comment")
67
- continue;
68
- walk(item, path ? `${path}.${key}` : key, combined || key === "anyOf" || key === "allOf");
69
- }
70
- }
71
- };
72
- if (isObject(permissions)) {
73
- for (const [key, value] of entriesOf(permissions)) {
74
- if (key === "tables")
75
- walk(value, key, false);
76
- }
77
- }
78
- if (found.length === 0)
79
- return;
80
- throw new UpgradeRefusal(`jazz.permissions.json has \`true\` inside anyOf/allOf at ${found.join(", ")}. alpha.65's validate writes that for a condition that ` +
81
- "compiled to nothing, typically `where({ column: value })` with `value` undefined when validate ran, so the policy " +
82
- "allows more than permissions.ts says. Fix the condition in permissions.ts (or, if the policy really is unconditional, " +
83
- "write it as `.always()` alone), run `npx jazz-tools validate` with the app's alpha.65, then upgrade again.", relative(project.root, project.permissionsJsonFile));
84
- }
85
- //# sourceMappingURL=permissions-check.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"permissions-check.js","sourceRoot":"","sources":["../../src/upgrade/permissions-check.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAa,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB,EAAE,KAAe;IAChE,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;IACvB,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACxC,IAAI,CAAC,wCAAwC,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,SAAS;QACnE,MAAM,MAAM,GAAG,EAAE,CAAC,gBAAgB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC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AE,KAAK,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;YAClD,IAAI,GAAG,KAAK,QAAQ;gBAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO;IAC/B,MAAM,IAAI,cAAc,CACtB,4DAA4D,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,yDAAyD;QACnI,oHAAoH;QACpH,wHAAwH;QACxH,4GAA4G,EAC9G,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,mBAAmB,CAAC,CACpD,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Permissions alpha.65 compiled from values that aren't in the source. Its\n * DSL ran permissions.ts when validate ran, so a `process.env` read became\n * whatever it was then (upgrade prints that value and warns), and a\n * `where({ col: undefined })` compiled to no condition at all, `\"true\"`\n * (upgrade refuses: the printed policy would allow more than its author\n * wrote).\n */\nimport { readFileSync } from \"node:fs\";\nimport { relative } from \"node:path\";\nimport type * as TS from \"typescript\";\nimport { isObject, parseJsonOrdered, entriesOf, type Json } from \"./app-json.js\";\nimport { UpgradeRefusal } from \"./errors.js\";\nimport type { Project } from \"./project.js\";\n\n/**\n * Where schema.ts, permissions.ts or the project files they import read the\n * environment. The printed policies hold the values validate resolved them\n * to, so upgrade warns about each rather than refuse.\n */\nexport function environmentReads(project: Project, files: string[]): string[] {\n const { ts } = project;\n const found: string[] = [];\n for (const file of files) {\n const text = readFileSync(file, \"utf8\");\n if (!/\\b(?:process\\.env|import\\.meta\\.env)\\b/.test(text)) continue;\n const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true);\n const visit = (node: TS.Node): void => {\n if (ts.isPropertyAccessExpression(node) && node.name.text === \"env\") {\n const target = node.expression;\n const isProcess = ts.isIdentifier(target) && target.text === \"process\";\n const isImportMeta = ts.isMetaProperty(target);\n if (isProcess || isImportMeta) {\n const parent = node.parent;\n const read =\n ts.isPropertyAccessExpression(parent) && parent.expression === node\n ? parent.getText(source)\n : ts.isElementAccessExpression(parent) && parent.expression === node\n ? parent.getText(source)\n : node.getText(source);\n const { line } = source.getLineAndCharacterOfPosition(node.getStart(source));\n found.push(`${relative(project.root, file) || file}:${line + 1}: reads \\`${read}\\``);\n return;\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(source);\n }\n return found;\n}\n\n/** Refuse `\"true\"` inside `anyOf` / `allOf` of jazz.permissions.json: the trace of a condition that compiled to nothing. */\nexport function refuseDroppedConditions(project: Project): void {\n let permissions: Json;\n try {\n permissions = parseJsonOrdered(readFileSync(project.permissionsJsonFile, \"utf8\"));\n } catch {\n return; // the old validate already refused an unreadable file\n }\n const found: string[] = [];\n const walk = (value: Json, path: string, combined: boolean): void => {\n if (value === \"true\" && combined) found.push(path);\n else if (Array.isArray(value))\n value.forEach((item, i) => walk(item, `${path}[${i}]`, combined));\n else if (isObject(value)) {\n for (const [key, item] of entriesOf(value)) {\n if (key === \"$comment\") continue;\n walk(item, path ? `${path}.${key}` : key, combined || key === \"anyOf\" || key === \"allOf\");\n }\n }\n };\n if (isObject(permissions)) {\n for (const [key, value] of entriesOf(permissions)) {\n if (key === \"tables\") walk(value, key, false);\n }\n }\n if (found.length === 0) return;\n throw new UpgradeRefusal(\n `jazz.permissions.json has \\`true\\` inside anyOf/allOf at ${found.join(\", \")}. alpha.65's validate writes that for a condition that ` +\n \"compiled to nothing, typically `where({ column: value })` with `value` undefined when validate ran, so the policy \" +\n \"allows more than permissions.ts says. Fix the condition in permissions.ts (or, if the policy really is unconditional, \" +\n \"write it as `.always()` alone), run `npx jazz-tools validate` with the app's alpha.65, then upgrade again.\",\n relative(project.root, project.permissionsJsonFile),\n );\n}\n"]}
@@ -1,18 +0,0 @@
1
- import type * as TS from "typescript";
2
- type Ts = typeof TS;
3
- export interface ProgramHandle {
4
- program: TS.Program;
5
- dispose(): void;
6
- }
7
- export declare function createProgram(ts: Ts, rootNames: string[], options: TS.CompilerOptions, jazzTools: string | undefined): ProgramHandle;
8
- /** An error in one of the project's own files. */
9
- export interface TypeError {
10
- /** `file:line:col: message`. */
11
- text: string;
12
- /** The error without its position: the same error before and after a rewrite moved its line. */
13
- key: string;
14
- }
15
- /** Errors in the project's own files. */
16
- export declare function typeErrors(ts: Ts, program: TS.Program, root: string): TypeError[];
17
- export {};
18
- //# sourceMappingURL=program.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"program.d.ts","sourceRoot":"","sources":["../../src/upgrade/program.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC;AAEpB,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC;IACpB,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,wBAAgB,aAAa,CAC3B,EAAE,EAAE,EAAE,EACN,SAAS,EAAE,MAAM,EAAE,EACnB,OAAO,EAAE,EAAE,CAAC,eAAe,EAC3B,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,aAAa,CAyBf;AAED,kDAAkD;AAClD,MAAM,WAAW,SAAS;IACxB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,GAAG,EAAE,MAAM,CAAC;CACb;AAED,yCAAyC;AACzC,wBAAgB,UAAU,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,CAoBjF"}
@@ -1,56 +0,0 @@
1
- /**
2
- * TypeScript programs over the project, with `jazz-tools` resolved to a
3
- * chosen package: the DSL-era one while reading schema.ts, this one (the
4
- * new runtime) for the closing typecheck.
5
- */
6
- import { mkdirSync, mkdtempSync, rmSync, symlinkSync } from "node:fs";
7
- import { tmpdir } from "node:os";
8
- import { join, relative } from "node:path";
9
- export function createProgram(ts, rootNames, options, jazzTools) {
10
- const host = ts.createCompilerHost(options, true);
11
- let scratch;
12
- if (jazzTools) {
13
- // Resolve `jazz-tools` (and its subpaths, through its exports) as if
14
- // installed beside a scratch file whose node_modules links to it.
15
- scratch = mkdtempSync(join(tmpdir(), "jazz-upgrade-"));
16
- mkdirSync(join(scratch, "node_modules"));
17
- symlinkSync(jazzTools, join(scratch, "node_modules", "jazz-tools"), "dir");
18
- const anchor = join(scratch, "anchor.ts");
19
- host.resolveModuleNameLiterals = (literals, containingFile, redirected, compilerOptions) => literals.map((literal) => {
20
- const name = literal.text;
21
- const from = name === "jazz-tools" || name.startsWith("jazz-tools/") ? anchor : containingFile;
22
- return ts.resolveModuleName(name, from, compilerOptions, host, undefined, redirected);
23
- });
24
- }
25
- const program = ts.createProgram({ rootNames, options, host });
26
- return {
27
- program,
28
- dispose: () => {
29
- if (scratch)
30
- rmSync(scratch, { recursive: true, force: true });
31
- },
32
- };
33
- }
34
- /** Errors in the project's own files. */
35
- export function typeErrors(ts, program, root) {
36
- const out = [];
37
- for (const diagnostic of ts.getPreEmitDiagnostics(program)) {
38
- if (diagnostic.category !== ts.DiagnosticCategory.Error)
39
- continue;
40
- const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n").split("\n")[0];
41
- if (!diagnostic.file) {
42
- out.push({ text: message, key: `TS${diagnostic.code} ${message}` });
43
- continue;
44
- }
45
- const path = relative(root, diagnostic.file.fileName);
46
- if (path.startsWith("..") || path.includes("node_modules"))
47
- continue;
48
- const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(diagnostic.start ?? 0);
49
- out.push({
50
- text: `${path}:${line + 1}:${character + 1}: ${message}`,
51
- key: `${path} TS${diagnostic.code} ${message}`,
52
- });
53
- }
54
- return out;
55
- }
56
- //# sourceMappingURL=program.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"program.js","sourceRoot":"","sources":["../../src/upgrade/program.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,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K,IAAI,CAAC,CACtB,CAAC;QACF,GAAG,CAAC,IAAI,CAAC;YACP,IAAI,EAAE,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,IAAI,SAAS,GAAG,CAAC,KAAK,OAAO,EAAE;YACxD,GAAG,EAAE,GAAG,IAAI,MAAM,UAAU,CAAC,IAAI,IAAI,OAAO,EAAE;SAC/C,CAAC,CAAC;IACL,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * TypeScript programs over the project, with `jazz-tools` resolved to a\n * chosen package: the DSL-era one while reading schema.ts, this one (the\n * new runtime) for the closing typecheck.\n */\nimport { mkdirSync, mkdtempSync, rmSync, symlinkSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join, relative } from \"node:path\";\nimport type * as TS from \"typescript\";\n\ntype Ts = typeof TS;\n\nexport interface ProgramHandle {\n program: TS.Program;\n dispose(): void;\n}\n\nexport function createProgram(\n ts: Ts,\n rootNames: string[],\n options: TS.CompilerOptions,\n jazzTools: string | undefined,\n): ProgramHandle {\n const host = ts.createCompilerHost(options, true);\n let scratch: string | undefined;\n if (jazzTools) {\n // Resolve `jazz-tools` (and its subpaths, through its exports) as if\n // installed beside a scratch file whose node_modules links to it.\n scratch = mkdtempSync(join(tmpdir(), \"jazz-upgrade-\"));\n mkdirSync(join(scratch, \"node_modules\"));\n symlinkSync(jazzTools, join(scratch, \"node_modules\", \"jazz-tools\"), \"dir\");\n const anchor = join(scratch, \"anchor.ts\");\n host.resolveModuleNameLiterals = (literals, containingFile, redirected, compilerOptions) =>\n literals.map((literal) => {\n const name = literal.text;\n const from =\n name === \"jazz-tools\" || name.startsWith(\"jazz-tools/\") ? anchor : containingFile;\n return ts.resolveModuleName(name, from, compilerOptions, host, undefined, redirected);\n });\n }\n const program = ts.createProgram({ rootNames, options, host });\n return {\n program,\n dispose: () => {\n if (scratch) rmSync(scratch, { recursive: true, force: true });\n },\n };\n}\n\n/** An error in one of the project's own files. */\nexport interface TypeError {\n /** `file:line:col: message`. */\n text: string;\n /** The error without its position: the same error before and after a rewrite moved its line. */\n key: string;\n}\n\n/** Errors in the project's own files. */\nexport function typeErrors(ts: Ts, program: TS.Program, root: string): TypeError[] {\n const out: TypeError[] = [];\n for (const diagnostic of ts.getPreEmitDiagnostics(program)) {\n if (diagnostic.category !== ts.DiagnosticCategory.Error) continue;\n const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, \"\\n\").split(\"\\n\")[0]!;\n if (!diagnostic.file) {\n out.push({ text: message, key: `TS${diagnostic.code} ${message}` });\n continue;\n }\n const path = relative(root, diagnostic.file.fileName);\n if (path.startsWith(\"..\") || path.includes(\"node_modules\")) continue;\n const { line, character } = diagnostic.file.getLineAndCharacterOfPosition(\n diagnostic.start ?? 0,\n );\n out.push({\n text: `${path}:${line + 1}:${character + 1}: ${message}`,\n key: `${path} TS${diagnostic.code} ${message}`,\n });\n }\n return out;\n}\n"]}
@@ -1,56 +0,0 @@
1
- import type * as TS from "typescript";
2
- import { UpgradeRefusal } from "./errors.js";
3
- export type Ts = typeof TS;
4
- /** Where a project keeps schema.ts, as validate looks for it. */
5
- export declare const SCHEMA_ROOTS: string[];
6
- export declare const APP_FILE = "jazz.app.json";
7
- export declare const PERMISSIONS_FILE = "jazz.permissions.json";
8
- export declare const GENERATED_FILE = "jazz.generated.ts";
9
- export declare const COMPUTED_FILE = "jazz.computed.ts";
10
- /** What schema.ts exported besides the schema, once it is gone. */
11
- export declare const EXTRAS_FILE = "app-extras.ts";
12
- export interface Project {
13
- /** The project root (`--dir`). */
14
- root: string;
15
- /** The directory holding schema.ts and the app files. */
16
- schemaDir: string;
17
- schemaFile: string;
18
- permissionsFile: string | undefined;
19
- /**
20
- * permissions.ts and the modules whose default export it re-exports
21
- * (`export { default } from "./src/db/access"`): importing any of them
22
- * imports the permissions.
23
- */
24
- permissionsSources: string[];
25
- migrationsDir: string | undefined;
26
- appFile: string;
27
- permissionsJsonFile: string;
28
- ts: Ts;
29
- tsconfig: string | undefined;
30
- compilerOptions: TS.CompilerOptions;
31
- /** The tsconfig's own files, for the typecheck. */
32
- configFileNames: string[];
33
- /** Every source file of the project, absolute. */
34
- sources: string[];
35
- }
36
- export declare function locateProject(root: string, schemaDirOption?: string): Project;
37
- /** The project's TypeScript: upgrade reads schema.ts with the compiler the app builds with. */
38
- export declare function loadTypeScript(root: string): Ts;
39
- /**
40
- * Where schema.ts is: `--schema-dir`, else where validate looks (., src,
41
- * src/lib), else the one directory under the project holding both schema.ts
42
- * and jazz.app.json (an Expo app's `jazz/`, say).
43
- */
44
- /**
45
- * An app whose source is its JSON files (jazz.app.json, no schema.ts), as an
46
- * alpha.65 Rust or Go backend's: `upgrade` writes its TS from them.
47
- */
48
- export declare class JsonOnlyApp extends UpgradeRefusal {
49
- readonly dir: string;
50
- constructor(dir: string);
51
- }
52
- /** The version of the jazz-tools package at `dir`. */
53
- export declare function packageVersion(dir: string): string;
54
- /** The root of the jazz-tools package running this command. */
55
- export declare function runningPackageRoot(): string;
56
- //# sourceMappingURL=project.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/upgrade/project.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;AAE3B,iEAAiE;AACjE,eAAO,MAAM,YAAY,UAAmC,CAAC;AAE7D,eAAO,MAAM,QAAQ,kBAAkB,CAAC;AACxC,eAAO,MAAM,gBAAgB,0BAA0B,CAAC;AACxD,eAAO,MAAM,cAAc,sBAAsB,CAAC;AAClD,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAChD,mEAAmE;AACnE,eAAO,MAAM,WAAW,kBAAkB,CAAC;AAsC3C,MAAM,WAAW,OAAO;IACtB,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC;;;;OAIG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,EAAE,EAAE,EAAE,CAAC;IACP,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,eAAe,EAAE,EAAE,CAAC,eAAe,CAAC;IACpC,mDAAmD;IACnD,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,kDAAkD;IAClD,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,OAAO,CA2B7E;AAED,+FAA+F;AAC/F,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAS/C;AAwCD;;;;GAIG;AACH;;;GAGG;AACH,qBAAa,WAAY,SAAQ,cAAc;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM;gBAAX,GAAG,EAAE,MAAM;CAGjC;AA6HD,sDAAsD;AACtD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGlD;AAED,+DAA+D;AAC/D,wBAAgB,kBAAkB,IAAI,MAAM,CAQ3C"}
@@ -1,254 +0,0 @@
1
- /**
2
- * The project `jazz-tools upgrade` converts: where its app files and TS
3
- * sources are, its tsconfig, and the TypeScript it compiles with.
4
- */
5
- import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
6
- import { createRequire } from "node:module";
7
- import { dirname, extname, join, relative, resolve, sep } from "node:path";
8
- import { UpgradeRefusal } from "./errors.js";
9
- /** Where a project keeps schema.ts, as validate looks for it. */
10
- export const SCHEMA_ROOTS = [".", "src", join("src", "lib")];
11
- export const APP_FILE = "jazz.app.json";
12
- export const PERMISSIONS_FILE = "jazz.permissions.json";
13
- export const GENERATED_FILE = "jazz.generated.ts";
14
- export const COMPUTED_FILE = "jazz.computed.ts";
15
- /** What schema.ts exported besides the schema, once it is gone. */
16
- export const EXTRAS_FILE = "app-extras.ts";
17
- /** Sources upgrade reads and rewrites. */
18
- const SOURCE_EXTENSIONS = new Set([
19
- ".ts",
20
- ".tsx",
21
- ".mts",
22
- ".cts",
23
- ".js",
24
- ".jsx",
25
- ".mjs",
26
- ".cjs",
27
- ".svelte",
28
- ".vue",
29
- // Inline `<script type="module">` blocks.
30
- ".html",
31
- ]);
32
- /** Directories that hold build output, dependencies or tooling, never sources. */
33
- const SKIPPED_DIRS = new Set([
34
- "node_modules",
35
- "dist",
36
- "build",
37
- "out",
38
- ".next",
39
- ".svelte-kit",
40
- ".turbo",
41
- ".vercel",
42
- ".output",
43
- ".expo",
44
- ".wrangler",
45
- "target",
46
- "coverage",
47
- "android",
48
- "ios",
49
- "playwright-report",
50
- "test-results",
51
- ]);
52
- export function locateProject(root, schemaDirOption) {
53
- root = resolve(root);
54
- if (!existsSync(root) || !statSync(root).isDirectory()) {
55
- throw new UpgradeRefusal(`${root} is not a directory`);
56
- }
57
- const schemaDir = findSchemaDir(root, schemaDirOption);
58
- const file = (name) => existsSync(join(schemaDir, name)) ? join(schemaDir, name) : undefined;
59
- const ts = loadTypeScript(root);
60
- const { tsconfig, options, fileNames } = readTsconfig(ts, root);
61
- return {
62
- root,
63
- schemaDir,
64
- schemaFile: join(schemaDir, "schema.ts"),
65
- permissionsFile: file("permissions.ts"),
66
- migrationsDir: existsSync(join(schemaDir, "migrations"))
67
- ? join(schemaDir, "migrations")
68
- : undefined,
69
- appFile: join(schemaDir, APP_FILE),
70
- permissionsJsonFile: join(schemaDir, PERMISSIONS_FILE),
71
- ts,
72
- tsconfig,
73
- compilerOptions: options,
74
- configFileNames: fileNames,
75
- sources: listSources(root, schemaDir),
76
- permissionsSources: permissionsSources(ts, file("permissions.ts")),
77
- };
78
- }
79
- /** The project's TypeScript: upgrade reads schema.ts with the compiler the app builds with. */
80
- export function loadTypeScript(root) {
81
- const require = createRequire(join(root, "package.json"));
82
- try {
83
- return require("typescript");
84
- }
85
- catch {
86
- throw new UpgradeRefusal(`upgrade reads schema.ts with the TypeScript compiler, but typescript isn't installed in ${root}: add it as a dev dependency and run upgrade again`);
87
- }
88
- }
89
- function readTsconfig(ts, root) {
90
- const tsconfig = ts.findConfigFile(root, (path) => ts.sys.fileExists(path), "tsconfig.json");
91
- // Only the project's own tsconfig, not a parent's in a monorepo.
92
- if (!tsconfig || relative(root, tsconfig).startsWith("..")) {
93
- return {
94
- tsconfig: undefined,
95
- options: {
96
- target: ts.ScriptTarget.ES2022,
97
- module: ts.ModuleKind.ESNext,
98
- moduleResolution: ts.ModuleResolutionKind.Bundler,
99
- strict: true,
100
- skipLibCheck: true,
101
- jsx: ts.JsxEmit.ReactJSX,
102
- allowImportingTsExtensions: true,
103
- noEmit: true,
104
- },
105
- fileNames: [],
106
- };
107
- }
108
- const parsed = ts.getParsedCommandLineOfConfigFile(tsconfig, {}, {
109
- ...ts.sys,
110
- // A missing extended config (SvelteKit's before `svelte-kit sync`) still leaves usable options.
111
- onUnRecoverableConfigFileDiagnostic: () => { },
112
- });
113
- return {
114
- tsconfig,
115
- options: { ...parsed?.options, noEmit: true },
116
- fileNames: parsed?.fileNames ?? [],
117
- };
118
- }
119
- /**
120
- * Where schema.ts is: `--schema-dir`, else where validate looks (., src,
121
- * src/lib), else the one directory under the project holding both schema.ts
122
- * and jazz.app.json (an Expo app's `jazz/`, say).
123
- */
124
- /**
125
- * An app whose source is its JSON files (jazz.app.json, no schema.ts), as an
126
- * alpha.65 Rust or Go backend's: `upgrade` writes its TS from them.
127
- */
128
- export class JsonOnlyApp extends UpgradeRefusal {
129
- dir;
130
- constructor(dir) {
131
- super(`${dir} has jazz.app.json but no schema.ts`);
132
- this.dir = dir;
133
- }
134
- }
135
- function findSchemaDir(root, option) {
136
- if (option) {
137
- const dir = resolve(root, option);
138
- if (!existsSync(join(dir, "schema.ts"))) {
139
- if (existsSync(join(dir, APP_FILE)))
140
- throw new JsonOnlyApp(dir);
141
- throw new UpgradeRefusal(`--schema-dir ${option}: no schema.ts in ${dir}`);
142
- }
143
- return dir;
144
- }
145
- const known = SCHEMA_ROOTS.map((r) => join(root, r)).find((dir) => existsSync(join(dir, "schema.ts")));
146
- if (known)
147
- return known;
148
- const found = [];
149
- const walk = (dir, depth) => {
150
- if (depth > 3)
151
- return;
152
- let entries;
153
- try {
154
- entries = readdirSync(dir, { withFileTypes: true });
155
- }
156
- catch {
157
- return;
158
- }
159
- if (entries.some((e) => e.name === "schema.ts") && entries.some((e) => e.name === APP_FILE))
160
- found.push(dir);
161
- for (const entry of entries) {
162
- if (entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED_DIRS.has(entry.name)) {
163
- walk(join(dir, entry.name), depth + 1);
164
- }
165
- }
166
- };
167
- walk(root, 0);
168
- if (found.length === 1)
169
- return found[0];
170
- if (found.length > 1) {
171
- throw new UpgradeRefusal(`${root} holds several apps (schema.ts beside jazz.app.json in ${found.map((d) => relative(root, d)).join(", ")}): pass --schema-dir for the one to upgrade`);
172
- }
173
- const jsonOnly = SCHEMA_ROOTS.map((r) => join(root, r)).find((dir) => existsSync(join(dir, APP_FILE)));
174
- if (jsonOnly)
175
- throw new JsonOnlyApp(jsonOnly);
176
- throw new UpgradeRefusal(`no schema.ts in ${root}, ${join(root, "src")} or ${join(root, "src", "lib")}: run upgrade in the app's directory (or pass --dir, and --schema-dir where schema.ts lives elsewhere)`);
177
- }
178
- function permissionsSources(ts, permissionsFile) {
179
- const out = [];
180
- for (let file = permissionsFile; file && !out.includes(file);) {
181
- out.push(file);
182
- const source = ts.createSourceFile(file, readFileSync(file, "utf8"), ts.ScriptTarget.Latest, true);
183
- let next;
184
- for (const statement of source.statements) {
185
- if (ts.isExportDeclaration(statement) &&
186
- statement.moduleSpecifier &&
187
- ts.isStringLiteral(statement.moduleSpecifier) &&
188
- statement.moduleSpecifier.text.startsWith(".") &&
189
- statement.exportClause &&
190
- ts.isNamedExports(statement.exportClause) &&
191
- statement.exportClause.elements.some((e) => (e.propertyName ?? e.name).text === "default")) {
192
- const base = join(dirname(file), statement.moduleSpecifier.text).replace(/\.(js|mjs|ts|mts)$/, "");
193
- next = [`${base}.ts`, `${base}.mts`, `${base}.tsx`, join(base, "index.ts")].find((c) => existsSync(c));
194
- }
195
- }
196
- file = next;
197
- }
198
- return out;
199
- }
200
- function listSources(root, schemaDir) {
201
- const out = [];
202
- const walk = (dir, top) => {
203
- let entries;
204
- try {
205
- entries = readdirSync(dir, { withFileTypes: true });
206
- }
207
- catch {
208
- return;
209
- }
210
- // A nested package is part of this app (a backend, a shared `jazz/`
211
- // folder) unless it is an app of its own, with its own schema.
212
- if (!top && entries.some((e) => e.name === "package.json") && !isWithin(schemaDir, dir)) {
213
- if (SCHEMA_ROOTS.some((r) => existsSync(join(dir, r, "schema.ts")) || existsSync(join(dir, r, APP_FILE))))
214
- return;
215
- }
216
- for (const entry of entries) {
217
- if (entry.name.startsWith("."))
218
- continue;
219
- const path = join(dir, entry.name);
220
- if (entry.isDirectory()) {
221
- if (!SKIPPED_DIRS.has(entry.name))
222
- walk(path, false);
223
- }
224
- else if (entry.isFile() &&
225
- SOURCE_EXTENSIONS.has(extname(entry.name)) &&
226
- !entry.name.endsWith(".d.ts")) {
227
- out.push(path);
228
- }
229
- }
230
- };
231
- walk(root, true);
232
- return out.sort();
233
- }
234
- function isWithin(path, dir) {
235
- const rel = relative(dir, path);
236
- return rel === "" || (!rel.startsWith("..") && !rel.startsWith(sep));
237
- }
238
- /** The version of the jazz-tools package at `dir`. */
239
- export function packageVersion(dir) {
240
- return JSON.parse(readFileSync(join(dir, "package.json"), "utf8"))
241
- .version;
242
- }
243
- /** The root of the jazz-tools package running this command. */
244
- export function runningPackageRoot() {
245
- let dir = dirname(new URL(import.meta.url).pathname);
246
- while (!existsSync(join(dir, "package.json"))) {
247
- const parent = dirname(dir);
248
- if (parent === dir)
249
- throw new Error("jazz-tools: can't find its own package.json");
250
- dir = parent;
251
- }
252
- return dir;
253
- }
254
- //# sourceMappingURL=project.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/upgrade/project.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C,iEAAiE;AACjE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC;AAE7D,MAAM,CAAC,MAAM,QAAQ,GAAG,eAAe,CAAC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAClD,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAChD,mEAAmE;AACnE,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC;AAE3C,0CAA0C;AAC1C,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,SAAS;IACT,MAAM;IACN,0CAA0C;IAC1C,OAAO;CACR,CAAC,CAAC;AACH,kFAAkF;AAClF,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,cAAc;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GAAW;IACzC,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAChC,OAAO,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,cAAc,CAAC,GAAW;IACxC,OAAQ,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAyB;SACxF,OAAO,CAAC;AACb,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,kBAAkB;IAChC,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC;IACrD,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;QAC9C,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,KAAK,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACnF,GAAG,GAAG,MAAM,CAAC;IACf,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * The project `jazz-tools upgrade` converts: where its app files and TS\n * sources are, its tsconfig, and the TypeScript it compiles with.\n */\nimport { existsSync, readdirSync, readFileSync, statSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, extname, join, relative, resolve, sep } from \"node:path\";\nimport type * as TS from \"typescript\";\nimport { UpgradeRefusal } from \"./errors.js\";\n\nexport type Ts = typeof TS;\n\n/** Where a project keeps schema.ts, as validate looks for it. */\nexport const SCHEMA_ROOTS = [\".\", \"src\", join(\"src\", \"lib\")];\n\nexport const APP_FILE = \"jazz.app.json\";\nexport const PERMISSIONS_FILE = \"jazz.permissions.json\";\nexport const GENERATED_FILE = \"jazz.generated.ts\";\nexport const COMPUTED_FILE = \"jazz.computed.ts\";\n/** What schema.ts exported besides the schema, once it is gone. */\nexport const EXTRAS_FILE = \"app-extras.ts\";\n\n/** Sources upgrade reads and rewrites. */\nconst SOURCE_EXTENSIONS = new Set([\n \".ts\",\n \".tsx\",\n \".mts\",\n \".cts\",\n \".js\",\n \".jsx\",\n \".mjs\",\n \".cjs\",\n \".svelte\",\n \".vue\",\n // Inline `<script type=\"module\">` blocks.\n \".html\",\n]);\n/** Directories that hold build output, dependencies or tooling, never sources. */\nconst SKIPPED_DIRS = new Set([\n \"node_modules\",\n \"dist\",\n \"build\",\n \"out\",\n \".next\",\n \".svelte-kit\",\n \".turbo\",\n \".vercel\",\n \".output\",\n \".expo\",\n \".wrangler\",\n \"target\",\n \"coverage\",\n \"android\",\n \"ios\",\n \"playwright-report\",\n \"test-results\",\n]);\n\nexport interface Project {\n /** The project root (`--dir`). */\n root: string;\n /** The directory holding schema.ts and the app files. */\n schemaDir: string;\n schemaFile: string;\n permissionsFile: string | undefined;\n /**\n * permissions.ts and the modules whose default export it re-exports\n * (`export { default } from \"./src/db/access\"`): importing any of them\n * imports the permissions.\n */\n permissionsSources: string[];\n migrationsDir: string | undefined;\n appFile: string;\n permissionsJsonFile: string;\n ts: Ts;\n tsconfig: string | undefined;\n compilerOptions: TS.CompilerOptions;\n /** The tsconfig's own files, for the typecheck. */\n configFileNames: string[];\n /** Every source file of the project, absolute. */\n sources: string[];\n}\n\nexport function locateProject(root: string, schemaDirOption?: string): Project {\n root = resolve(root);\n if (!existsSync(root) || !statSync(root).isDirectory()) {\n throw new UpgradeRefusal(`${root} is not a directory`);\n }\n const schemaDir = findSchemaDir(root, schemaDirOption);\n const file = (name: string) =>\n existsSync(join(schemaDir, name)) ? join(schemaDir, name) : undefined;\n const ts = loadTypeScript(root);\n const { tsconfig, options, fileNames } = readTsconfig(ts, root);\n return {\n root,\n schemaDir,\n schemaFile: join(schemaDir, \"schema.ts\"),\n permissionsFile: file(\"permissions.ts\"),\n migrationsDir: existsSync(join(schemaDir, \"migrations\"))\n ? join(schemaDir, \"migrations\")\n : undefined,\n appFile: join(schemaDir, APP_FILE),\n permissionsJsonFile: join(schemaDir, PERMISSIONS_FILE),\n ts,\n tsconfig,\n compilerOptions: options,\n configFileNames: fileNames,\n sources: listSources(root, schemaDir),\n permissionsSources: permissionsSources(ts, file(\"permissions.ts\")),\n };\n}\n\n/** The project's TypeScript: upgrade reads schema.ts with the compiler the app builds with. */\nexport function loadTypeScript(root: string): Ts {\n const require = createRequire(join(root, \"package.json\"));\n try {\n return require(\"typescript\") as Ts;\n } catch {\n throw new UpgradeRefusal(\n `upgrade reads schema.ts with the TypeScript compiler, but typescript isn't installed in ${root}: add it as a dev dependency and run upgrade again`,\n );\n }\n}\n\nfunction readTsconfig(\n ts: Ts,\n root: string,\n): { tsconfig: string | undefined; options: TS.CompilerOptions; fileNames: string[] } {\n const tsconfig = ts.findConfigFile(root, (path) => ts.sys.fileExists(path), \"tsconfig.json\");\n // Only the project's own tsconfig, not a parent's in a monorepo.\n if (!tsconfig || relative(root, tsconfig).startsWith(\"..\")) {\n return {\n tsconfig: undefined,\n options: {\n target: ts.ScriptTarget.ES2022,\n module: ts.ModuleKind.ESNext,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n strict: true,\n skipLibCheck: true,\n jsx: ts.JsxEmit.ReactJSX,\n allowImportingTsExtensions: true,\n noEmit: true,\n },\n fileNames: [],\n };\n }\n const parsed = ts.getParsedCommandLineOfConfigFile(\n tsconfig,\n {},\n {\n ...ts.sys,\n // A missing extended config (SvelteKit's before `svelte-kit sync`) still leaves usable options.\n onUnRecoverableConfigFileDiagnostic: () => {},\n },\n );\n return {\n tsconfig,\n options: { ...parsed?.options, noEmit: true },\n fileNames: parsed?.fileNames ?? [],\n };\n}\n\n/**\n * Where schema.ts is: `--schema-dir`, else where validate looks (., src,\n * src/lib), else the one directory under the project holding both schema.ts\n * and jazz.app.json (an Expo app's `jazz/`, say).\n */\n/**\n * An app whose source is its JSON files (jazz.app.json, no schema.ts), as an\n * alpha.65 Rust or Go backend's: `upgrade` writes its TS from them.\n */\nexport class JsonOnlyApp extends UpgradeRefusal {\n constructor(readonly dir: string) {\n super(`${dir} has jazz.app.json but no schema.ts`);\n }\n}\n\nfunction findSchemaDir(root: string, option: string | undefined): string {\n if (option) {\n const dir = resolve(root, option);\n if (!existsSync(join(dir, \"schema.ts\"))) {\n if (existsSync(join(dir, APP_FILE))) throw new JsonOnlyApp(dir);\n throw new UpgradeRefusal(`--schema-dir ${option}: no schema.ts in ${dir}`);\n }\n return dir;\n }\n const known = SCHEMA_ROOTS.map((r) => join(root, r)).find((dir) =>\n existsSync(join(dir, \"schema.ts\")),\n );\n if (known) return known;\n const found: string[] = [];\n const walk = (dir: string, depth: number): void => {\n if (depth > 3) return;\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n if (entries.some((e) => e.name === \"schema.ts\") && entries.some((e) => e.name === APP_FILE))\n found.push(dir);\n for (const entry of entries) {\n if (entry.isDirectory() && !entry.name.startsWith(\".\") && !SKIPPED_DIRS.has(entry.name)) {\n walk(join(dir, entry.name), depth + 1);\n }\n }\n };\n walk(root, 0);\n if (found.length === 1) return found[0]!;\n if (found.length > 1) {\n throw new UpgradeRefusal(\n `${root} holds several apps (schema.ts beside jazz.app.json in ${found.map((d) => relative(root, d)).join(\", \")}): pass --schema-dir for the one to upgrade`,\n );\n }\n const jsonOnly = SCHEMA_ROOTS.map((r) => join(root, r)).find((dir) =>\n existsSync(join(dir, APP_FILE)),\n );\n if (jsonOnly) throw new JsonOnlyApp(jsonOnly);\n throw new UpgradeRefusal(\n `no schema.ts in ${root}, ${join(root, \"src\")} or ${join(root, \"src\", \"lib\")}: run upgrade in the app's directory (or pass --dir, and --schema-dir where schema.ts lives elsewhere)`,\n );\n}\n\nfunction permissionsSources(ts: Ts, permissionsFile: string | undefined): string[] {\n const out: string[] = [];\n for (let file = permissionsFile; file && !out.includes(file);) {\n out.push(file);\n const source = ts.createSourceFile(\n file,\n readFileSync(file, \"utf8\"),\n ts.ScriptTarget.Latest,\n true,\n );\n let next: string | undefined;\n for (const statement of source.statements) {\n if (\n ts.isExportDeclaration(statement) &&\n statement.moduleSpecifier &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n statement.moduleSpecifier.text.startsWith(\".\") &&\n statement.exportClause &&\n ts.isNamedExports(statement.exportClause) &&\n statement.exportClause.elements.some((e) => (e.propertyName ?? e.name).text === \"default\")\n ) {\n const base = join(dirname(file), statement.moduleSpecifier.text).replace(\n /\\.(js|mjs|ts|mts)$/,\n \"\",\n );\n next = [`${base}.ts`, `${base}.mts`, `${base}.tsx`, join(base, \"index.ts\")].find((c) =>\n existsSync(c),\n );\n }\n }\n file = next;\n }\n return out;\n}\n\nfunction listSources(root: string, schemaDir: string): string[] {\n const out: string[] = [];\n const walk = (dir: string, top: boolean): void => {\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch {\n return;\n }\n // A nested package is part of this app (a backend, a shared `jazz/`\n // folder) unless it is an app of its own, with its own schema.\n if (!top && entries.some((e) => e.name === \"package.json\") && !isWithin(schemaDir, dir)) {\n if (\n SCHEMA_ROOTS.some(\n (r) => existsSync(join(dir, r, \"schema.ts\")) || existsSync(join(dir, r, APP_FILE)),\n )\n )\n return;\n }\n for (const entry of entries) {\n if (entry.name.startsWith(\".\")) continue;\n const path = join(dir, entry.name);\n if (entry.isDirectory()) {\n if (!SKIPPED_DIRS.has(entry.name)) walk(path, false);\n } else if (\n entry.isFile() &&\n SOURCE_EXTENSIONS.has(extname(entry.name)) &&\n !entry.name.endsWith(\".d.ts\")\n ) {\n out.push(path);\n }\n }\n };\n walk(root, true);\n return out.sort();\n}\n\nfunction isWithin(path: string, dir: string): boolean {\n const rel = relative(dir, path);\n return rel === \"\" || (!rel.startsWith(\"..\") && !rel.startsWith(sep));\n}\n\n/** The version of the jazz-tools package at `dir`. */\nexport function packageVersion(dir: string): string {\n return (JSON.parse(readFileSync(join(dir, \"package.json\"), \"utf8\")) as { version: string })\n .version;\n}\n\n/** The root of the jazz-tools package running this command. */\nexport function runningPackageRoot(): string {\n let dir = dirname(new URL(import.meta.url).pathname);\n while (!existsSync(join(dir, \"package.json\"))) {\n const parent = dirname(dir);\n if (parent === dir) throw new Error(\"jazz-tools: can't find its own package.json\");\n dir = parent;\n }\n return dir;\n}\n"]}
@@ -1,34 +0,0 @@
1
- import type { MovedExport } from "./extras.js";
2
- import type { TableTypeNames } from "./names.js";
3
- import type { Project } from "./project.js";
4
- import type { PackageAliases } from "./aliases.js";
5
- export interface RewriteInput {
6
- /** package.json `imports` aliases the rewrite retargets. */
7
- aliases: PackageAliases;
8
- project: Project;
9
- /** Where each export of schema.ts lives now. */
10
- exports: Map<string, MovedExport>;
11
- tables: Record<string, TableTypeNames>;
12
- /** Files upgrade deletes: never rewritten, and imports of them are what it rewrites. */
13
- deleted: Set<string>;
14
- generatedFile: string;
15
- extrasFile: string;
16
- computedFile: string;
17
- }
18
- export interface FileRewrite {
19
- file: string;
20
- text: string;
21
- /** One line per rewrite, `file:line: what`. */
22
- changes: string[];
23
- /** Whether the file now imports a JSON module. */
24
- importsJson: boolean;
25
- }
26
- export interface RewriteResult {
27
- files: FileRewrite[];
28
- /** Code upgrade can't move off the removed APIs, as `file:line: what`. */
29
- manual: string[];
30
- }
31
- export declare function rewriteProject(input: RewriteInput): RewriteResult;
32
- /** The file a module specifier of `file` resolves to, if it is one of the project's. */
33
- export declare function resolveImport(project: Project, specifier: string, file: string): string | undefined;
34
- //# sourceMappingURL=rewrite.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"rewrite.d.ts","sourceRoot":"","sources":["../../src/upgrade/rewrite.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/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