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.
- package/README.md +2 -3
- package/bin/jazz-tools.js +0 -3
- package/dist/accounts/account-manager-core.d.ts +54 -1
- package/dist/accounts/account-manager-core.d.ts.map +1 -1
- package/dist/accounts/account-manager-core.js +2 -2
- package/dist/accounts/account-manager-core.js.map +1 -1
- package/dist/accounts/context.js +1 -1
- package/dist/accounts/context.js.map +1 -1
- package/dist/backend/api.d.ts +1 -2
- package/dist/backend/api.d.ts.map +1 -1
- package/dist/backend/api.js +0 -2
- package/dist/backend/api.js.map +1 -1
- package/dist/backend/create-jazz.d.ts +0 -6
- package/dist/backend/create-jazz.d.ts.map +1 -1
- package/dist/backend/create-jazz.js +1 -1
- package/dist/backend/create-jazz.js.map +1 -1
- package/dist/backend/inspector-ui/11.js +2 -2
- package/dist/backend/inspector-ui/12.js +2 -2
- package/dist/backend/inspector-ui/13.js +2 -2
- package/dist/backend/inspector-ui/14.js +2 -2
- package/dist/backend/inspector-ui/20.js +1 -1
- package/dist/backend/inspector-ui-files.js +4 -4
- package/dist/backend/no-account-error.d.ts +1 -1
- package/dist/backend/no-account-error.js +1 -1
- package/dist/backend/no-account-error.js.map +1 -1
- package/dist/cli.d.ts +0 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -22
- package/dist/cli.js.map +1 -1
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +0 -2
- package/dist/client/index.js.map +1 -1
- package/dist/dev/app-files.js +1 -1
- package/dist/dev/app-files.js.map +1 -1
- package/dist/dev/catalogue-api.d.ts.map +1 -1
- package/dist/dev/catalogue-api.js +3 -6
- package/dist/dev/catalogue-api.js.map +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/{index-D3RK8wNj.js → index-DUKUt96e.js} +3 -3
- package/dist/dev/inspector-overlay/embedded/assets/{jazz-broker-worker-EyaWhBtz.js → jazz-broker-worker-C_mr9Omd.js} +2 -2
- package/dist/dev/inspector-overlay/embedded/assets/{jazz_wasm-O10pptvY.js → jazz_wasm-BOvbCHn3.js} +1 -1
- package/dist/dev/inspector-overlay/embedded/assets/{jazz_wasm_bg-wI43fvvq.wasm → jazz_wasm_bg-BG8gazqt.wasm} +0 -0
- package/dist/dev/inspector-overlay/embedded/embedded.html +1 -1
- package/dist/dev/project.js +1 -1
- package/dist/dev/project.js.map +1 -1
- package/dist/dev/ts-project.d.ts.map +1 -1
- package/dist/dev/ts-project.js +3 -2
- package/dist/dev/ts-project.js.map +1 -1
- package/dist/expo/create-account-manager.d.ts +1 -1
- package/dist/expo/create-account-manager.js.map +1 -1
- package/dist/expo/index.d.ts +1 -2
- package/dist/expo/index.d.ts.map +1 -1
- package/dist/expo/index.js +1 -3
- package/dist/expo/index.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/printer/index.d.ts +2 -2
- package/dist/printer/index.d.ts.map +1 -1
- package/dist/printer/index.js +4 -1
- package/dist/printer/index.js.map +1 -1
- package/dist/react/index.d.ts +1 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +1 -3
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts +0 -2
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/provider.js +1 -2
- package/dist/react/provider.js.map +1 -1
- package/dist/react-core/index.d.ts +1 -2
- package/dist/react-core/index.d.ts.map +1 -1
- package/dist/react-core/index.js +3 -5
- package/dist/react-core/index.js.map +1 -1
- package/dist/react-core/provider.d.ts +0 -8
- package/dist/react-core/provider.d.ts.map +1 -1
- package/dist/react-core/provider.js +0 -13
- package/dist/react-core/provider.js.map +1 -1
- package/dist/react-native/create-account-manager.d.ts +1 -1
- package/dist/react-native/create-account-manager.js.map +1 -1
- package/dist/react-native/index.d.ts +1 -3
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +1 -5
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/provider.d.ts +0 -2
- package/dist/react-native/provider.d.ts.map +1 -1
- package/dist/react-native/provider.js +1 -2
- package/dist/react-native/provider.js.map +1 -1
- package/dist/runtime/db.d.ts +0 -5
- package/dist/runtime/db.d.ts.map +1 -1
- package/dist/runtime/db.js +0 -5
- package/dist/runtime/db.js.map +1 -1
- package/dist/runtime/native-artifact-fingerprint-napi.d.ts +1 -1
- package/dist/runtime/native-artifact-fingerprint-napi.js +1 -1
- package/dist/runtime/native-artifact-fingerprint-napi.js.map +1 -1
- package/dist/runtime/native-artifact-fingerprint-wasm.d.ts +1 -1
- package/dist/runtime/native-artifact-fingerprint-wasm.js +1 -1
- package/dist/runtime/native-artifact-fingerprint-wasm.js.map +1 -1
- package/dist/runtime/native-artifact-fingerprints.d.ts +2 -2
- package/dist/schema-builders.d.ts +0 -7
- package/dist/schema-builders.d.ts.map +1 -1
- package/dist/schema-builders.js +0 -7
- package/dist/schema-builders.js.map +1 -1
- package/dist/session/create-jazz-session.d.ts +1 -1
- package/dist/session/create-jazz-session.d.ts.map +1 -1
- package/dist/session/create-jazz-session.js.map +1 -1
- package/dist/solid/index.d.ts +1 -2
- package/dist/solid/index.d.ts.map +1 -1
- package/dist/solid/index.js +7 -8
- package/dist/solid/index.ssr.js +2 -3
- package/dist/solid/provider.d.ts +1 -12
- package/dist/solid/provider.d.ts.map +1 -1
- package/dist/solid/provider.js +12 -18
- package/dist/solid/provider.js.map +1 -1
- package/dist/solid/provider.ssr.js +1 -11
- package/dist/solid/provider.ssr.js.map +1 -1
- package/dist/svelte/context.svelte.d.ts +1 -12
- package/dist/svelte/context.svelte.d.ts.map +1 -1
- package/dist/svelte/context.svelte.js +2 -20
- package/dist/svelte/index.d.ts +1 -2
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +1 -3
- package/dist/thin/index.d.ts +0 -1
- package/dist/thin/index.d.ts.map +1 -1
- package/dist/thin/index.js +0 -2
- package/dist/thin/index.js.map +1 -1
- package/dist/typed-app.d.ts +1 -1
- package/dist/typed-app.js.map +1 -1
- package/dist/vue/index.d.ts +1 -2
- package/dist/vue/index.d.ts.map +1 -1
- package/dist/vue/index.js +1 -3
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/provider.d.ts +2 -35
- package/dist/vue/provider.d.ts.map +1 -1
- package/dist/vue/provider.js +1 -135
- package/dist/vue/provider.js.map +1 -1
- package/dist/web/lazy-local-first.d.ts +0 -3
- package/dist/web/lazy-local-first.d.ts.map +1 -1
- package/dist/web/lazy-local-first.js +1 -6
- package/dist/web/lazy-local-first.js.map +1 -1
- package/dist/worker/jazz-broker-worker.js +2 -2
- package/dist/worker/jazz_wasm_bg.wasm +0 -0
- package/package.json +4 -8
- package/dist/accounts/create-account-manager.d.ts +0 -57
- package/dist/accounts/create-account-manager.d.ts.map +0 -1
- package/dist/accounts/create-account-manager.js +0 -17
- package/dist/accounts/create-account-manager.js.map +0 -1
- package/dist/permissions/index.d.ts +0 -5
- package/dist/permissions/index.d.ts.map +0 -1
- package/dist/permissions/index.js +0 -11
- package/dist/permissions/index.js.map +0 -1
- package/dist/removed-api.d.ts +0 -87
- package/dist/removed-api.d.ts.map +0 -1
- package/dist/removed-api.js +0 -95
- package/dist/removed-api.js.map +0 -1
- package/dist/removed-schema-api.d.ts +0 -80
- package/dist/removed-schema-api.d.ts.map +0 -1
- package/dist/removed-schema-api.js +0 -128
- package/dist/removed-schema-api.js.map +0 -1
- package/dist/session/deprecated-session-hook.d.ts +0 -8
- package/dist/session/deprecated-session-hook.d.ts.map +0 -1
- package/dist/session/deprecated-session-hook.js +0 -28
- package/dist/session/deprecated-session-hook.js.map +0 -1
- package/dist/svelte/JazzSvelteProvider.svelte +0 -181
- package/dist/svelte/JazzSvelteProvider.svelte.d.ts +0 -14
- package/dist/svelte/JazzSvelteProvider.svelte.d.ts.map +0 -1
- package/dist/upgrade/aliases.d.ts +0 -25
- package/dist/upgrade/aliases.d.ts.map +0 -1
- package/dist/upgrade/aliases.js +0 -80
- package/dist/upgrade/aliases.js.map +0 -1
- package/dist/upgrade/app-json.d.ts +0 -32
- package/dist/upgrade/app-json.d.ts.map +0 -1
- package/dist/upgrade/app-json.js +0 -145
- package/dist/upgrade/app-json.js.map +0 -1
- package/dist/upgrade/constants.d.ts +0 -25
- package/dist/upgrade/constants.d.ts.map +0 -1
- package/dist/upgrade/constants.js +0 -136
- package/dist/upgrade/constants.js.map +0 -1
- package/dist/upgrade/edits.d.ts +0 -10
- package/dist/upgrade/edits.d.ts.map +0 -1
- package/dist/upgrade/edits.js +0 -21
- package/dist/upgrade/edits.js.map +0 -1
- package/dist/upgrade/errors.d.ts +0 -12
- package/dist/upgrade/errors.d.ts.map +0 -1
- package/dist/upgrade/errors.js +0 -18
- package/dist/upgrade/errors.js.map +0 -1
- package/dist/upgrade/extras.d.ts +0 -42
- package/dist/upgrade/extras.d.ts.map +0 -1
- package/dist/upgrade/extras.js +0 -487
- package/dist/upgrade/extras.js.map +0 -1
- package/dist/upgrade/fresh.d.ts +0 -36
- package/dist/upgrade/fresh.d.ts.map +0 -1
- package/dist/upgrade/fresh.js +0 -154
- package/dist/upgrade/fresh.js.map +0 -1
- package/dist/upgrade/index.d.ts +0 -79
- package/dist/upgrade/index.d.ts.map +0 -1
- package/dist/upgrade/index.js +0 -806
- package/dist/upgrade/index.js.map +0 -1
- package/dist/upgrade/json-only.d.ts +0 -24
- package/dist/upgrade/json-only.d.ts.map +0 -1
- package/dist/upgrade/json-only.js +0 -124
- package/dist/upgrade/json-only.js.map +0 -1
- package/dist/upgrade/names.d.ts +0 -29
- package/dist/upgrade/names.d.ts.map +0 -1
- package/dist/upgrade/names.js +0 -105
- package/dist/upgrade/names.js.map +0 -1
- package/dist/upgrade/payload-enums.d.ts +0 -18
- package/dist/upgrade/payload-enums.d.ts.map +0 -1
- package/dist/upgrade/payload-enums.js +0 -52
- package/dist/upgrade/payload-enums.js.map +0 -1
- package/dist/upgrade/permissions-check.d.ts +0 -10
- package/dist/upgrade/permissions-check.d.ts.map +0 -1
- package/dist/upgrade/permissions-check.js +0 -85
- package/dist/upgrade/permissions-check.js.map +0 -1
- package/dist/upgrade/program.d.ts +0 -18
- package/dist/upgrade/program.d.ts.map +0 -1
- package/dist/upgrade/program.js +0 -56
- package/dist/upgrade/program.js.map +0 -1
- package/dist/upgrade/project.d.ts +0 -56
- package/dist/upgrade/project.d.ts.map +0 -1
- package/dist/upgrade/project.js +0 -254
- package/dist/upgrade/project.js.map +0 -1
- package/dist/upgrade/rewrite.d.ts +0 -34
- package/dist/upgrade/rewrite.d.ts.map +0 -1
- package/dist/upgrade/rewrite.js +0 -500
- package/dist/upgrade/rewrite.js.map +0 -1
- package/dist/upgrade/schema-ts.d.ts +0 -59
- package/dist/upgrade/schema-ts.d.ts.map +0 -1
- package/dist/upgrade/schema-ts.js +0 -582
- package/dist/upgrade/schema-ts.js.map +0 -1
- package/dist/upgrade/snapshot.d.ts +0 -11
- package/dist/upgrade/snapshot.d.ts.map +0 -1
- package/dist/upgrade/snapshot.js +0 -90
- package/dist/upgrade/snapshot.js.map +0 -1
- package/dist/upgrade/upgrade-test-helpers.d.ts +0 -12
- package/dist/upgrade/upgrade-test-helpers.d.ts.map +0 -1
- package/dist/upgrade/upgrade-test-helpers.js +0 -72
- package/dist/upgrade/upgrade-test-helpers.js.map +0 -1
package/dist/upgrade/extras.js
DELETED
|
@@ -1,487 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What schema.ts exported besides its schema. Each export ends up in one of:
|
|
3
|
-
* - `jazz.generated.ts`: `app`, and row/insert aliases (`type Todo =
|
|
4
|
-
* s.RowOf<typeof app.todos>`) and enum column aliases (`Issue["status"]`)
|
|
5
|
-
* the generated module declares under some name;
|
|
6
|
-
* - `app-extras.ts`, a hand-written module upgrade starts: everything else
|
|
7
|
-
* that is plain TypeScript (constants, other types), rewritten to the
|
|
8
|
-
* generated types;
|
|
9
|
-
* - nowhere, for schema DSL values nothing imports.
|
|
10
|
-
*/
|
|
11
|
-
import { relative } from "node:path";
|
|
12
|
-
import { applyEdits } from "./edits.js";
|
|
13
|
-
import { UpgradeRefusal, notSupportedYet } from "./errors.js";
|
|
14
|
-
import { pascal } from "./names.js";
|
|
15
|
-
const TYPE_HELPERS = {
|
|
16
|
-
RowOf: "row",
|
|
17
|
-
InsertOf: "insert",
|
|
18
|
-
WhereOf: "keep",
|
|
19
|
-
LargeValueUpdateOf: "keep",
|
|
20
|
-
StreamingInsertOf: "keep",
|
|
21
|
-
StreamingUpdateOf: "keep",
|
|
22
|
-
StreamingUpsertOf: "keep",
|
|
23
|
-
TableMetaOf: "keep",
|
|
24
|
-
};
|
|
25
|
-
export function convertExtras(input) {
|
|
26
|
-
const { ts, program, schemaFile, tables, generatedExports } = input;
|
|
27
|
-
const source = program.getSourceFile(schemaFile);
|
|
28
|
-
const checker = program.getTypeChecker();
|
|
29
|
-
const where = (node) => `${relative(process.cwd(), schemaFile) || schemaFile}:${source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1}`;
|
|
30
|
-
// `schema` from jazz-tools, under whatever local name.
|
|
31
|
-
const dsl = new Set();
|
|
32
|
-
for (const statement of source.statements) {
|
|
33
|
-
if (!ts.isImportDeclaration(statement) || !isJazzTools(statement.moduleSpecifier))
|
|
34
|
-
continue;
|
|
35
|
-
const named = statement.importClause?.namedBindings;
|
|
36
|
-
if (named && ts.isNamedImports(named)) {
|
|
37
|
-
for (const element of named.elements) {
|
|
38
|
-
if ((element.propertyName ?? element.name).text === "schema") {
|
|
39
|
-
const symbol = checker.getSymbolAtLocation(element.name);
|
|
40
|
-
if (symbol)
|
|
41
|
-
dsl.add(symbol);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const isDsl = (node) => {
|
|
47
|
-
if (!node || !ts.isIdentifier(node))
|
|
48
|
-
return false;
|
|
49
|
-
const symbol = checker.getSymbolAtLocation(node);
|
|
50
|
-
return symbol !== undefined && dsl.has(symbol);
|
|
51
|
-
};
|
|
52
|
-
const exports = new Map();
|
|
53
|
-
for (const name of input.movedToComputed)
|
|
54
|
-
exports.set(name, { module: "computed", name, typeOnly: false });
|
|
55
|
-
// The app: a const made by s.defineApp / s.defineSliceableApp, and any
|
|
56
|
-
// slice of it (`full.slice("a", "b")`). Slicing is gone, so every one of
|
|
57
|
-
// them becomes the generated `app`.
|
|
58
|
-
const appSymbols = new Set();
|
|
59
|
-
let defined;
|
|
60
|
-
for (const statement of source.statements) {
|
|
61
|
-
if (!ts.isVariableStatement(statement))
|
|
62
|
-
continue;
|
|
63
|
-
for (const declaration of statement.declarationList.declarations) {
|
|
64
|
-
const init = declaration.initializer && unwrap(ts, declaration.initializer);
|
|
65
|
-
if (!init ||
|
|
66
|
-
!ts.isCallExpression(init) ||
|
|
67
|
-
!ts.isPropertyAccessExpression(init.expression) ||
|
|
68
|
-
!ts.isIdentifier(declaration.name))
|
|
69
|
-
continue;
|
|
70
|
-
const callee = init.expression;
|
|
71
|
-
const isDefine = isDsl(callee.expression) &&
|
|
72
|
-
(callee.name.text === "defineApp" || callee.name.text === "defineSliceableApp");
|
|
73
|
-
const isSlice = callee.name.text === "slice" &&
|
|
74
|
-
ts.isIdentifier(callee.expression) &&
|
|
75
|
-
appSymbols.has(checker.getSymbolAtLocation(callee.expression));
|
|
76
|
-
if (!isDefine && !isSlice)
|
|
77
|
-
continue;
|
|
78
|
-
if (isDefine) {
|
|
79
|
-
if (defined)
|
|
80
|
-
throw notSupportedYet("a schema.ts that defines two apps", where(declaration));
|
|
81
|
-
defined = declaration;
|
|
82
|
-
}
|
|
83
|
-
const symbol = checker.getSymbolAtLocation(declaration.name);
|
|
84
|
-
if (symbol)
|
|
85
|
-
appSymbols.add(symbol);
|
|
86
|
-
if (isExported(ts, statement)) {
|
|
87
|
-
exports.set(declaration.name.text, { module: "generated", name: "app", typeOnly: false });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (!defined) {
|
|
92
|
-
throw notSupportedYet("a schema.ts without `export const app = s.defineApp(...)`", where(source.statements[0] ?? source));
|
|
93
|
-
}
|
|
94
|
-
refuseMissingMigrations(ts, checker, defined, where, input.notes);
|
|
95
|
-
const isApp = (node) => ts.isIdentifier(node) && appSymbols.has(checker.getSymbolAtLocation(node));
|
|
96
|
-
/** `typeof app.<table>` → the table. */
|
|
97
|
-
const tableOfTypeQuery = (node) => {
|
|
98
|
-
if (!node || !ts.isTypeQueryNode(node))
|
|
99
|
-
return undefined;
|
|
100
|
-
const name = node.exprName;
|
|
101
|
-
if (!ts.isQualifiedName(name) || !isApp(name.left))
|
|
102
|
-
return undefined;
|
|
103
|
-
return tables[name.right.text] ? name.right.text : undefined;
|
|
104
|
-
};
|
|
105
|
-
/** `s.RowOf<typeof app.t>` / `s.InsertOf<…>` → its generated name. */
|
|
106
|
-
const generatedHelper = (node) => {
|
|
107
|
-
if (!ts.isTypeReferenceNode(node) ||
|
|
108
|
-
!ts.isQualifiedName(node.typeName) ||
|
|
109
|
-
!isDsl(node.typeName.left))
|
|
110
|
-
return undefined;
|
|
111
|
-
const role = TYPE_HELPERS[node.typeName.right.text];
|
|
112
|
-
if (role !== "row" && role !== "insert")
|
|
113
|
-
return undefined;
|
|
114
|
-
const table = tableOfTypeQuery(node.typeArguments?.[0]);
|
|
115
|
-
return table ? tables[table][role] : undefined;
|
|
116
|
-
};
|
|
117
|
-
// Pass 1: exports the generated module declares.
|
|
118
|
-
const aliasTables = new Map(); // RowOf alias → table
|
|
119
|
-
const extrasStatements = [];
|
|
120
|
-
const dropped = [];
|
|
121
|
-
const movedToComputed = new Set(input.movedToComputed);
|
|
122
|
-
for (const statement of source.statements) {
|
|
123
|
-
if (ts.isImportDeclaration(statement) || !isExported(ts, statement))
|
|
124
|
-
continue;
|
|
125
|
-
if (declaredNames(ts, statement).some((name) => movedToComputed.has(name)))
|
|
126
|
-
continue;
|
|
127
|
-
if (ts.isVariableStatement(statement) &&
|
|
128
|
-
statement.declarationList.declarations.some((d) => ts.isIdentifier(d.name) && appSymbols.has(checker.getSymbolAtLocation(d.name)))) {
|
|
129
|
-
if (statement.declarationList.declarations.length > 1) {
|
|
130
|
-
throw notSupportedYet("declaring other names in the same statement as the app", where(statement));
|
|
131
|
-
}
|
|
132
|
-
continue;
|
|
133
|
-
}
|
|
134
|
-
if (ts.isTypeAliasDeclaration(statement)) {
|
|
135
|
-
const generated = generatedHelper(statement.type);
|
|
136
|
-
if (generated) {
|
|
137
|
-
exports.set(statement.name.text, { module: "generated", name: generated, typeOnly: true });
|
|
138
|
-
const table = tableOfTypeQuery(statement.type.typeArguments?.[0]);
|
|
139
|
-
const symbol = checker.getSymbolAtLocation(statement.name);
|
|
140
|
-
if (symbol &&
|
|
141
|
-
table &&
|
|
142
|
-
statement.type.typeName.getText(source).endsWith("RowOf")) {
|
|
143
|
-
aliasTables.set(symbol, table);
|
|
144
|
-
}
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
extrasStatements.push(statement);
|
|
149
|
-
}
|
|
150
|
-
// Pass 2: `Row["column"]` of a row alias, where the column is an enum the generated module names.
|
|
151
|
-
for (const statement of [...extrasStatements]) {
|
|
152
|
-
if (!ts.isTypeAliasDeclaration(statement))
|
|
153
|
-
continue;
|
|
154
|
-
const type = statement.type;
|
|
155
|
-
if (!ts.isIndexedAccessTypeNode(type) ||
|
|
156
|
-
!ts.isLiteralTypeNode(type.indexType) ||
|
|
157
|
-
!ts.isStringLiteral(type.indexType.literal))
|
|
158
|
-
continue;
|
|
159
|
-
let table;
|
|
160
|
-
if (ts.isTypeReferenceNode(type.objectType) && ts.isIdentifier(type.objectType.typeName)) {
|
|
161
|
-
const symbol = checker.getSymbolAtLocation(type.objectType.typeName);
|
|
162
|
-
table = symbol && aliasTables.get(symbol);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
const generated = generatedHelper(type.objectType);
|
|
166
|
-
if (generated) {
|
|
167
|
-
table = Object.keys(tables).find((t) => tables[t].row === generated);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (!table)
|
|
171
|
-
continue;
|
|
172
|
-
const enumName = `${tables[table].row}${pascal(type.indexType.literal.text)}`;
|
|
173
|
-
if (!generatedExports.has(enumName))
|
|
174
|
-
continue;
|
|
175
|
-
exports.set(statement.name.text, { module: "generated", name: enumName, typeOnly: true });
|
|
176
|
-
extrasStatements.splice(extrasStatements.indexOf(statement), 1);
|
|
177
|
-
}
|
|
178
|
-
// Pass 3: the rest, with what it needs, rewritten off the DSL.
|
|
179
|
-
const kept = new Set();
|
|
180
|
-
const importNames = new Map();
|
|
181
|
-
const generatedImports = new Map(); // generated name → local name
|
|
182
|
-
const jazzToolsTypes = new Set();
|
|
183
|
-
const edits = new Map();
|
|
184
|
-
const extrasNames = new Set();
|
|
185
|
-
const usesDsl = (statement) => {
|
|
186
|
-
let found;
|
|
187
|
-
const visit = (node) => {
|
|
188
|
-
if (found)
|
|
189
|
-
return;
|
|
190
|
-
if (ts.isTypeReferenceNode(node) &&
|
|
191
|
-
ts.isQualifiedName(node.typeName) &&
|
|
192
|
-
isDsl(node.typeName.left) &&
|
|
193
|
-
TYPE_HELPERS[node.typeName.right.text]) {
|
|
194
|
-
node.typeArguments?.forEach(visit);
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (ts.isIdentifier(node) && isDsl(node)) {
|
|
198
|
-
found = node;
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
ts.forEachChild(node, visit);
|
|
202
|
-
};
|
|
203
|
-
visit(statement);
|
|
204
|
-
return found;
|
|
205
|
-
};
|
|
206
|
-
for (const statement of extrasStatements) {
|
|
207
|
-
const names = declaredNames(ts, statement);
|
|
208
|
-
const dslNode = usesDsl(statement);
|
|
209
|
-
if (dslNode) {
|
|
210
|
-
const live = names.filter((n) => input.importedNames.has(n));
|
|
211
|
-
if (live.length > 0) {
|
|
212
|
-
throw notSupportedYet(`moving \`${live.join("`, `")}\` out of schema.ts: it is built with the schema DSL, and other files import it`, where(dslNode), "replace its uses with the generated types from jazz.generated.ts, then upgrade again");
|
|
213
|
-
}
|
|
214
|
-
dropped.push(...names);
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
for (const name of names) {
|
|
218
|
-
extrasNames.add(name);
|
|
219
|
-
exports.set(name, { module: "extras", name, typeOnly: isTypeOnly(ts, statement) });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
const local = (generatedName, typeOnly) => {
|
|
223
|
-
const existing = generatedImports.get(generatedName);
|
|
224
|
-
if (existing) {
|
|
225
|
-
existing.typeOnly &&= typeOnly;
|
|
226
|
-
return existing.local;
|
|
227
|
-
}
|
|
228
|
-
const name = extrasNames.has(generatedName) ? `Generated${generatedName}` : generatedName;
|
|
229
|
-
generatedImports.set(generatedName, { local: name, typeOnly });
|
|
230
|
-
return name;
|
|
231
|
-
};
|
|
232
|
-
const keep = (statement) => {
|
|
233
|
-
if (kept.has(statement))
|
|
234
|
-
return;
|
|
235
|
-
kept.add(statement);
|
|
236
|
-
const list = [];
|
|
237
|
-
edits.set(statement, list);
|
|
238
|
-
const visit = (node) => {
|
|
239
|
-
if (ts.isTypeReferenceNode(node) &&
|
|
240
|
-
ts.isQualifiedName(node.typeName) &&
|
|
241
|
-
isDsl(node.typeName.left)) {
|
|
242
|
-
const generated = generatedHelper(node);
|
|
243
|
-
if (generated) {
|
|
244
|
-
list.push({
|
|
245
|
-
start: node.getStart(source),
|
|
246
|
-
end: node.getEnd(),
|
|
247
|
-
text: local(generated, true),
|
|
248
|
-
});
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
const helper = node.typeName.right.text;
|
|
252
|
-
if (TYPE_HELPERS[helper]) {
|
|
253
|
-
jazzToolsTypes.add(helper);
|
|
254
|
-
list.push({
|
|
255
|
-
start: node.typeName.getStart(source),
|
|
256
|
-
end: node.typeName.getEnd(),
|
|
257
|
-
text: helper,
|
|
258
|
-
});
|
|
259
|
-
node.typeArguments?.forEach(visit);
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (ts.isIdentifier(node) && !isPropertyNameOnly(ts, node)) {
|
|
264
|
-
if (isApp(node)) {
|
|
265
|
-
const inType = isInTypePosition(ts, node);
|
|
266
|
-
list.push({
|
|
267
|
-
start: node.getStart(source),
|
|
268
|
-
end: node.getEnd(),
|
|
269
|
-
text: local("app", inType),
|
|
270
|
-
});
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const symbol = checker.getSymbolAtLocation(node);
|
|
274
|
-
for (const declaration of symbol?.declarations ?? []) {
|
|
275
|
-
if (declaration.getSourceFile() !== source)
|
|
276
|
-
continue;
|
|
277
|
-
const top = topLevel(ts, declaration);
|
|
278
|
-
if (!top || top === statement)
|
|
279
|
-
continue;
|
|
280
|
-
if (ts.isImportDeclaration(top)) {
|
|
281
|
-
const set = importNames.get(top) ?? new Set();
|
|
282
|
-
set.add(node.text);
|
|
283
|
-
importNames.set(top, set);
|
|
284
|
-
continue;
|
|
285
|
-
}
|
|
286
|
-
const moved = exports.get(node.text);
|
|
287
|
-
if (moved?.module === "generated") {
|
|
288
|
-
list.push({
|
|
289
|
-
start: node.getStart(source),
|
|
290
|
-
end: node.getEnd(),
|
|
291
|
-
text: local(moved.name, true),
|
|
292
|
-
});
|
|
293
|
-
continue;
|
|
294
|
-
}
|
|
295
|
-
if (moved?.module === "computed") {
|
|
296
|
-
const set = computedImports;
|
|
297
|
-
set.add(node.text);
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
const dslNode = usesDsl(top);
|
|
301
|
-
if (dslNode) {
|
|
302
|
-
throw notSupportedYet(`moving \`${declaredNames(ts, statement).join("`, `")}\` out of schema.ts: it uses \`${node.text}\`, which is built with the schema DSL`, where(node));
|
|
303
|
-
}
|
|
304
|
-
keep(top);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
ts.forEachChild(node, visit);
|
|
308
|
-
};
|
|
309
|
-
visit(statement);
|
|
310
|
-
};
|
|
311
|
-
const computedImports = new Set();
|
|
312
|
-
for (const statement of extrasStatements) {
|
|
313
|
-
if (!usesDsl(statement))
|
|
314
|
-
keep(statement);
|
|
315
|
-
}
|
|
316
|
-
if (kept.size === 0)
|
|
317
|
-
return { exports, extrasFile: null, dropped };
|
|
318
|
-
const ext = input.jsExtensions ? ".js" : "";
|
|
319
|
-
const lines = [
|
|
320
|
-
"// What schema.ts exported besides the schema, moved here by `jazz-tools upgrade`.",
|
|
321
|
-
"// The schema is schema.ts (for `generate` only); its types are in jazz.generated.ts.",
|
|
322
|
-
];
|
|
323
|
-
if (jazzToolsTypes.size > 0)
|
|
324
|
-
lines.push(`import type { ${[...jazzToolsTypes].sort().join(", ")} } from "jazz-tools";`);
|
|
325
|
-
for (const [statement, names] of importNames) {
|
|
326
|
-
const line = importLine(ts, statement, names);
|
|
327
|
-
if (line)
|
|
328
|
-
lines.push(line);
|
|
329
|
-
}
|
|
330
|
-
if (generatedImports.size > 0) {
|
|
331
|
-
const allTypes = [...generatedImports.values()].every((g) => g.typeOnly);
|
|
332
|
-
const parts = [...generatedImports].map(([name, g]) => {
|
|
333
|
-
const spec = g.local === name ? name : `${name} as ${g.local}`;
|
|
334
|
-
return !allTypes && g.typeOnly ? `type ${spec}` : spec;
|
|
335
|
-
});
|
|
336
|
-
lines.push(`import ${allTypes ? "type " : ""}{ ${parts.join(", ")} } from "./jazz.generated${ext}";`);
|
|
337
|
-
}
|
|
338
|
-
if (computedImports.size > 0)
|
|
339
|
-
lines.push(`import { ${[...computedImports].join(", ")} } from "./jazz.computed${ext}";`);
|
|
340
|
-
lines.push("");
|
|
341
|
-
for (const statement of [...kept].sort((a, b) => a.pos - b.pos)) {
|
|
342
|
-
const start = statement.getFullStart();
|
|
343
|
-
const text = applyEdits(source.text.slice(start, statement.getEnd()), edits.get(statement).map((e) => ({ ...e, start: e.start - start, end: e.end - start })));
|
|
344
|
-
lines.push(text.replace(/^\s*\n/, ""));
|
|
345
|
-
}
|
|
346
|
-
return { exports, extrasFile: `${lines.join("\n")}\n`, dropped };
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* An app ships its history through the migrations module schema.ts passes
|
|
350
|
-
* to s.defineApp: alpha.65's validate writes it only then, and otherwise
|
|
351
|
-
* just warns. Without it, stores may hold versions jazz.app.json doesn't
|
|
352
|
-
* carry, so upgrade refuses rather than start the history empty. An explicit
|
|
353
|
-
* `migrations: "none"` is the app saying it keeps no history.
|
|
354
|
-
*/
|
|
355
|
-
function refuseMissingMigrations(ts, checker, declaration, where, notes) {
|
|
356
|
-
const call = unwrap(ts, declaration.initializer);
|
|
357
|
-
const options = call.arguments[1] && unwrap(ts, call.arguments[1]);
|
|
358
|
-
const property = options && ts.isObjectLiteralExpression(options)
|
|
359
|
-
? options.properties.find((p) => (ts.isPropertyAssignment(p) || ts.isShorthandPropertyAssignment(p)) &&
|
|
360
|
-
p.name.getText() === "migrations")
|
|
361
|
-
: undefined;
|
|
362
|
-
const value = property && ts.isPropertyAssignment(property)
|
|
363
|
-
? unwrap(ts, property.initializer)
|
|
364
|
-
: property && ts.isShorthandPropertyAssignment(property)
|
|
365
|
-
? property.name
|
|
366
|
-
: undefined;
|
|
367
|
-
if (value && ts.isStringLiteral(value) && value.text === "none") {
|
|
368
|
-
notes.push('schema.ts declares `migrations: "none"`: jazz.app.json starts with no history, as the app shipped none.');
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
// The value must come from an import of the migrations module.
|
|
372
|
-
let imported = false;
|
|
373
|
-
if (value && ts.isIdentifier(value)) {
|
|
374
|
-
const symbol = property && ts.isShorthandPropertyAssignment(property)
|
|
375
|
-
? checker.getShorthandAssignmentValueSymbol(property)
|
|
376
|
-
: checker.getSymbolAtLocation(value);
|
|
377
|
-
const declarationNode = symbol?.declarations?.[0];
|
|
378
|
-
let importDecl = declarationNode;
|
|
379
|
-
while (importDecl && !ts.isImportDeclaration(importDecl))
|
|
380
|
-
importDecl = importDecl.parent;
|
|
381
|
-
if (importDecl &&
|
|
382
|
-
ts.isImportDeclaration(importDecl) &&
|
|
383
|
-
ts.isStringLiteral(importDecl.moduleSpecifier)) {
|
|
384
|
-
imported = /(^|\/)migrations(\/index)?(\.[mc]?[jt]s)?$/.test(importDecl.moduleSpecifier.text);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
if (imported)
|
|
388
|
-
return;
|
|
389
|
-
throw new UpgradeRefusal("schema.ts doesn't pass its migrations module to s.defineApp, so alpha.65 shipped no schema history and a store may " +
|
|
390
|
-
'hold versions jazz.app.json doesn\'t record. Add `import { migrations } from "./migrations";` and ' +
|
|
391
|
-
"`s.defineApp(schema, { migrations })`, run `npx jazz-tools validate` with the app's alpha.65 (it writes the history " +
|
|
392
|
-
'into jazz.app.json), commit, then upgrade again. If the app really keeps no history, say `{ migrations: "none" }`.', where(call));
|
|
393
|
-
}
|
|
394
|
-
function unwrap(ts, node) {
|
|
395
|
-
while (ts.isAsExpression(node) ||
|
|
396
|
-
ts.isSatisfiesExpression(node) ||
|
|
397
|
-
ts.isParenthesizedExpression(node))
|
|
398
|
-
node = node.expression;
|
|
399
|
-
return node;
|
|
400
|
-
}
|
|
401
|
-
function isJazzTools(specifier) {
|
|
402
|
-
const text = specifier.text;
|
|
403
|
-
return text === "jazz-tools" || text?.startsWith("jazz-tools/");
|
|
404
|
-
}
|
|
405
|
-
function isExported(ts, statement) {
|
|
406
|
-
const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;
|
|
407
|
-
return modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ?? false;
|
|
408
|
-
}
|
|
409
|
-
function isTypeOnly(ts, statement) {
|
|
410
|
-
return ts.isTypeAliasDeclaration(statement) || ts.isInterfaceDeclaration(statement);
|
|
411
|
-
}
|
|
412
|
-
export function declaredNames(ts, statement) {
|
|
413
|
-
if (ts.isVariableStatement(statement)) {
|
|
414
|
-
return statement.declarationList.declarations.flatMap((d) => ts.isIdentifier(d.name) ? [d.name.text] : []);
|
|
415
|
-
}
|
|
416
|
-
const named = statement;
|
|
417
|
-
return named.name && ts.isIdentifier(named.name) ? [named.name.text] : [];
|
|
418
|
-
}
|
|
419
|
-
function topLevel(ts, node) {
|
|
420
|
-
let current = node;
|
|
421
|
-
while (current.parent && !ts.isSourceFile(current.parent))
|
|
422
|
-
current = current.parent;
|
|
423
|
-
return current.parent ? current : undefined;
|
|
424
|
-
}
|
|
425
|
-
function isPropertyNameOnly(ts, node) {
|
|
426
|
-
const parent = node.parent;
|
|
427
|
-
if (ts.isPropertyAccessExpression(parent) && parent.name === node)
|
|
428
|
-
return true;
|
|
429
|
-
if ((ts.isPropertyAssignment(parent) ||
|
|
430
|
-
ts.isPropertySignature(parent) ||
|
|
431
|
-
ts.isMethodDeclaration(parent)) &&
|
|
432
|
-
parent.name === node)
|
|
433
|
-
return true;
|
|
434
|
-
if (ts.isQualifiedName(parent) && parent.right === node)
|
|
435
|
-
return true;
|
|
436
|
-
if (ts.isTypeAliasDeclaration(parent) ||
|
|
437
|
-
ts.isInterfaceDeclaration(parent) ||
|
|
438
|
-
ts.isVariableDeclaration(parent) ||
|
|
439
|
-
ts.isFunctionDeclaration(parent)) {
|
|
440
|
-
return parent.name === node;
|
|
441
|
-
}
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
function isInTypePosition(ts, node) {
|
|
445
|
-
for (let current = node.parent; current; current = current.parent) {
|
|
446
|
-
if (ts.isTypeQueryNode(current))
|
|
447
|
-
return true;
|
|
448
|
-
if (ts.isTypeNode(current) && !ts.isExpressionWithTypeArguments(current))
|
|
449
|
-
return true;
|
|
450
|
-
if (ts.isStatement(current) || ts.isExpressionStatement(current))
|
|
451
|
-
return false;
|
|
452
|
-
}
|
|
453
|
-
return false;
|
|
454
|
-
}
|
|
455
|
-
/** An import of only `names` from `statement`, or null when it imports none of them. */
|
|
456
|
-
export function importLine(ts, statement, names) {
|
|
457
|
-
const specifier = JSON.stringify(statement.moduleSpecifier.text);
|
|
458
|
-
const clause = statement.importClause;
|
|
459
|
-
if (!clause)
|
|
460
|
-
return null;
|
|
461
|
-
const typePrefix = clause.isTypeOnly ? "type " : "";
|
|
462
|
-
const parts = [];
|
|
463
|
-
const head = [];
|
|
464
|
-
if (clause.name && names.has(clause.name.text))
|
|
465
|
-
head.push(clause.name.text);
|
|
466
|
-
const bindings = clause.namedBindings;
|
|
467
|
-
if (bindings && ts.isNamespaceImport(bindings) && names.has(bindings.name.text)) {
|
|
468
|
-
return `import ${typePrefix}* as ${bindings.name.text} from ${specifier};`;
|
|
469
|
-
}
|
|
470
|
-
if (bindings && ts.isNamedImports(bindings)) {
|
|
471
|
-
for (const element of bindings.elements) {
|
|
472
|
-
if (!names.has(element.name.text))
|
|
473
|
-
continue;
|
|
474
|
-
const name = element.propertyName
|
|
475
|
-
? `${element.propertyName.text} as ${element.name.text}`
|
|
476
|
-
: element.name.text;
|
|
477
|
-
parts.push(element.isTypeOnly ? `type ${name}` : name);
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
if (parts.length > 0)
|
|
481
|
-
head.push(`{ ${parts.join(", ")} }`);
|
|
482
|
-
if (head.length === 0)
|
|
483
|
-
return null;
|
|
484
|
-
return `import ${typePrefix}${head.join(", ")} from ${specifier};`;
|
|
485
|
-
}
|
|
486
|
-
export { UpgradeRefusal };
|
|
487
|
-
//# sourceMappingURL=extras.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extras.js","sourceRoot":"","sources":["../../src/upgrade/extras.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,UAAU,EAAiB,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,e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AE,CAAC;QAChF,OAAO,UAAU,UAAU,QAAQ,QAAQ,CAAC,IAAI,CAAC,IAAI,SAAS,SAAS,GAAG,CAAC;IAC7E,CAAC;IACD,IAAI,QAAQ,IAAI,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5C,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;gBAAE,SAAS;YAC5C,MAAM,IAAI,GAAG,OAAO,CAAC,YAAY;gBAC/B,CAAC,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE;gBACxD,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;YACtB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IACD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,UAAU,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,SAAS,GAAG,CAAC;AACrE,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["/**\n * What schema.ts exported besides its schema. Each export ends up in one of:\n * - `jazz.generated.ts`: `app`, and row/insert aliases (`type Todo =\n * s.RowOf<typeof app.todos>`) and enum column aliases (`Issue[\"status\"]`)\n * the generated module declares under some name;\n * - `app-extras.ts`, a hand-written module upgrade starts: everything else\n * that is plain TypeScript (constants, other types), rewritten to the\n * generated types;\n * - nowhere, for schema DSL values nothing imports.\n */\nimport { relative } from \"node:path\";\nimport type * as TS from \"typescript\";\nimport { applyEdits, type TextEdit } from \"./edits.js\";\nimport { UpgradeRefusal, notSupportedYet } from \"./errors.js\";\nimport { pascal, type TableTypeNames } from \"./names.js\";\n\ntype Ts = typeof TS;\n\n/** Where an export of schema.ts lives after upgrade. */\nexport interface MovedExport {\n module: \"generated\" | \"extras\" | \"computed\";\n /** Its name there. */\n name: string;\n /** Whether it is only a type. */\n typeOnly: boolean;\n}\n\nexport interface ExtrasResult {\n exports: Map<string, MovedExport>;\n /** The text of app-extras.ts, or null when nothing needs it. */\n extrasFile: string | null;\n /** Exports dropped because they were schema DSL values. */\n dropped: string[];\n}\n\nexport interface ExtrasInput {\n ts: Ts;\n program: TS.Program;\n schemaFile: string;\n /** Table → generated type names. */\n tables: Record<string, TableTypeNames>;\n /** Every name jazz.generated.ts exports. */\n generatedExports: Set<string>;\n /** Exports of schema.ts that moved into jazz.computed.ts with a computed callback. */\n movedToComputed: string[];\n /** Whether relative imports in this project carry `.js` (`./schema.js`). */\n jsExtensions: boolean;\n /** Where to put notes for the report. */\n notes: string[];\n /** Names of schema.ts other project files import, to tell dead DSL exports from live ones. */\n importedNames: Set<string>;\n}\n\nconst TYPE_HELPERS: Record<string, \"row\" | \"insert\" | \"keep\"> = {\n RowOf: \"row\",\n InsertOf: \"insert\",\n WhereOf: \"keep\",\n LargeValueUpdateOf: \"keep\",\n StreamingInsertOf: \"keep\",\n StreamingUpdateOf: \"keep\",\n StreamingUpsertOf: \"keep\",\n TableMetaOf: \"keep\",\n};\n\nexport function convertExtras(input: ExtrasInput): ExtrasResult {\n const { ts, program, schemaFile, tables, generatedExports } = input;\n const source = program.getSourceFile(schemaFile)!;\n const checker = program.getTypeChecker();\n const where = (node: TS.Node) =>\n `${relative(process.cwd(), schemaFile) || schemaFile}:${source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1}`;\n\n // `schema` from jazz-tools, under whatever local name.\n const dsl = new Set<TS.Symbol>();\n for (const statement of source.statements) {\n if (!ts.isImportDeclaration(statement) || !isJazzTools(statement.moduleSpecifier)) continue;\n const named = statement.importClause?.namedBindings;\n if (named && ts.isNamedImports(named)) {\n for (const element of named.elements) {\n if ((element.propertyName ?? element.name).text === \"schema\") {\n const symbol = checker.getSymbolAtLocation(element.name);\n if (symbol) dsl.add(symbol);\n }\n }\n }\n }\n const isDsl = (node: TS.Node | undefined): boolean => {\n if (!node || !ts.isIdentifier(node)) return false;\n const symbol = checker.getSymbolAtLocation(node);\n return symbol !== undefined && dsl.has(symbol);\n };\n\n const exports = new Map<string, MovedExport>();\n for (const name of input.movedToComputed)\n exports.set(name, { module: \"computed\", name, typeOnly: false });\n\n // The app: a const made by s.defineApp / s.defineSliceableApp, and any\n // slice of it (`full.slice(\"a\", \"b\")`). Slicing is gone, so every one of\n // them becomes the generated `app`.\n const appSymbols = new Set<TS.Symbol>();\n let defined: TS.Node | undefined;\n for (const statement of source.statements) {\n if (!ts.isVariableStatement(statement)) continue;\n for (const declaration of statement.declarationList.declarations) {\n const init = declaration.initializer && unwrap(ts, declaration.initializer);\n if (\n !init ||\n !ts.isCallExpression(init) ||\n !ts.isPropertyAccessExpression(init.expression) ||\n !ts.isIdentifier(declaration.name)\n )\n continue;\n const callee = init.expression;\n const isDefine =\n isDsl(callee.expression) &&\n (callee.name.text === \"defineApp\" || callee.name.text === \"defineSliceableApp\");\n const isSlice =\n callee.name.text === \"slice\" &&\n ts.isIdentifier(callee.expression) &&\n appSymbols.has(checker.getSymbolAtLocation(callee.expression)!);\n if (!isDefine && !isSlice) continue;\n if (isDefine) {\n if (defined) throw notSupportedYet(\"a schema.ts that defines two apps\", where(declaration));\n defined = declaration;\n }\n const symbol = checker.getSymbolAtLocation(declaration.name);\n if (symbol) appSymbols.add(symbol);\n if (isExported(ts, statement)) {\n exports.set(declaration.name.text, { module: \"generated\", name: \"app\", typeOnly: false });\n }\n }\n }\n if (!defined) {\n throw notSupportedYet(\n \"a schema.ts without `export const app = s.defineApp(...)`\",\n where(source.statements[0] ?? source),\n );\n }\n refuseMissingMigrations(ts, checker, defined as TS.VariableDeclaration, where, input.notes);\n const isApp = (node: TS.Node): boolean =>\n ts.isIdentifier(node) && appSymbols.has(checker.getSymbolAtLocation(node)!);\n\n /** `typeof app.<table>` → the table. */\n const tableOfTypeQuery = (node: TS.TypeNode | undefined): string | undefined => {\n if (!node || !ts.isTypeQueryNode(node)) return undefined;\n const name = node.exprName;\n if (!ts.isQualifiedName(name) || !isApp(name.left)) return undefined;\n return tables[name.right.text] ? name.right.text : undefined;\n };\n /** `s.RowOf<typeof app.t>` / `s.InsertOf<…>` → its generated name. */\n const generatedHelper = (node: TS.Node): string | undefined => {\n if (\n !ts.isTypeReferenceNode(node) ||\n !ts.isQualifiedName(node.typeName) ||\n !isDsl(node.typeName.left)\n )\n return undefined;\n const role = TYPE_HELPERS[node.typeName.right.text];\n if (role !== \"row\" && role !== \"insert\") return undefined;\n const table = tableOfTypeQuery(node.typeArguments?.[0]);\n return table ? tables[table]![role] : undefined;\n };\n\n // Pass 1: exports the generated module declares.\n const aliasTables = new Map<TS.Symbol, string>(); // RowOf alias → table\n const extrasStatements: TS.Statement[] = [];\n const dropped: string[] = [];\n const movedToComputed = new Set(input.movedToComputed);\n for (const statement of source.statements) {\n if (ts.isImportDeclaration(statement) || !isExported(ts, statement)) continue;\n if (declaredNames(ts, statement).some((name) => movedToComputed.has(name))) continue;\n if (\n ts.isVariableStatement(statement) &&\n statement.declarationList.declarations.some(\n (d) => ts.isIdentifier(d.name) && appSymbols.has(checker.getSymbolAtLocation(d.name)!),\n )\n ) {\n if (statement.declarationList.declarations.length > 1) {\n throw notSupportedYet(\n \"declaring other names in the same statement as the app\",\n where(statement),\n );\n }\n continue;\n }\n if (ts.isTypeAliasDeclaration(statement)) {\n const generated = generatedHelper(statement.type);\n if (generated) {\n exports.set(statement.name.text, { module: \"generated\", name: generated, typeOnly: true });\n const table = tableOfTypeQuery((statement.type as TS.TypeReferenceNode).typeArguments?.[0]);\n const symbol = checker.getSymbolAtLocation(statement.name);\n if (\n symbol &&\n table &&\n (statement.type as TS.TypeReferenceNode).typeName.getText(source).endsWith(\"RowOf\")\n ) {\n aliasTables.set(symbol, table);\n }\n continue;\n }\n }\n extrasStatements.push(statement);\n }\n // Pass 2: `Row[\"column\"]` of a row alias, where the column is an enum the generated module names.\n for (const statement of [...extrasStatements]) {\n if (!ts.isTypeAliasDeclaration(statement)) continue;\n const type = statement.type;\n if (\n !ts.isIndexedAccessTypeNode(type) ||\n !ts.isLiteralTypeNode(type.indexType) ||\n !ts.isStringLiteral(type.indexType.literal)\n )\n continue;\n let table: string | undefined;\n if (ts.isTypeReferenceNode(type.objectType) && ts.isIdentifier(type.objectType.typeName)) {\n const symbol = checker.getSymbolAtLocation(type.objectType.typeName);\n table = symbol && aliasTables.get(symbol);\n } else {\n const generated = generatedHelper(type.objectType);\n if (generated) {\n table = Object.keys(tables).find((t) => tables[t]!.row === generated);\n }\n }\n if (!table) continue;\n const enumName = `${tables[table]!.row}${pascal(type.indexType.literal.text)}`;\n if (!generatedExports.has(enumName)) continue;\n exports.set(statement.name.text, { module: \"generated\", name: enumName, typeOnly: true });\n extrasStatements.splice(extrasStatements.indexOf(statement), 1);\n }\n\n // Pass 3: the rest, with what it needs, rewritten off the DSL.\n const kept = new Set<TS.Statement>();\n const importNames = new Map<TS.ImportDeclaration, Set<string>>();\n const generatedImports = new Map<string, { local: string; typeOnly: boolean }>(); // generated name → local name\n const jazzToolsTypes = new Set<string>();\n const edits = new Map<TS.Statement, TextEdit[]>();\n const extrasNames = new Set<string>();\n const usesDsl = (statement: TS.Statement): TS.Node | undefined => {\n let found: TS.Node | undefined;\n const visit = (node: TS.Node): void => {\n if (found) return;\n if (\n ts.isTypeReferenceNode(node) &&\n ts.isQualifiedName(node.typeName) &&\n isDsl(node.typeName.left) &&\n TYPE_HELPERS[node.typeName.right.text]\n ) {\n node.typeArguments?.forEach(visit);\n return;\n }\n if (ts.isIdentifier(node) && isDsl(node)) {\n found = node;\n return;\n }\n ts.forEachChild(node, visit);\n };\n visit(statement);\n return found;\n };\n\n for (const statement of extrasStatements) {\n const names = declaredNames(ts, statement);\n const dslNode = usesDsl(statement);\n if (dslNode) {\n const live = names.filter((n) => input.importedNames.has(n));\n if (live.length > 0) {\n throw notSupportedYet(\n `moving \\`${live.join(\"`, `\")}\\` out of schema.ts: it is built with the schema DSL, and other files import it`,\n where(dslNode),\n \"replace its uses with the generated types from jazz.generated.ts, then upgrade again\",\n );\n }\n dropped.push(...names);\n continue;\n }\n for (const name of names) {\n extrasNames.add(name);\n exports.set(name, { module: \"extras\", name, typeOnly: isTypeOnly(ts, statement) });\n }\n }\n\n const local = (generatedName: string, typeOnly: boolean): string => {\n const existing = generatedImports.get(generatedName);\n if (existing) {\n existing.typeOnly &&= typeOnly;\n return existing.local;\n }\n const name = extrasNames.has(generatedName) ? `Generated${generatedName}` : generatedName;\n generatedImports.set(generatedName, { local: name, typeOnly });\n return name;\n };\n\n const keep = (statement: TS.Statement): void => {\n if (kept.has(statement)) return;\n kept.add(statement);\n const list: TextEdit[] = [];\n edits.set(statement, list);\n const visit = (node: TS.Node): void => {\n if (\n ts.isTypeReferenceNode(node) &&\n ts.isQualifiedName(node.typeName) &&\n isDsl(node.typeName.left)\n ) {\n const generated = generatedHelper(node);\n if (generated) {\n list.push({\n start: node.getStart(source),\n end: node.getEnd(),\n text: local(generated, true),\n });\n return;\n }\n const helper = node.typeName.right.text;\n if (TYPE_HELPERS[helper]) {\n jazzToolsTypes.add(helper);\n list.push({\n start: node.typeName.getStart(source),\n end: node.typeName.getEnd(),\n text: helper,\n });\n node.typeArguments?.forEach(visit);\n return;\n }\n }\n if (ts.isIdentifier(node) && !isPropertyNameOnly(ts, node)) {\n if (isApp(node)) {\n const inType = isInTypePosition(ts, node);\n list.push({\n start: node.getStart(source),\n end: node.getEnd(),\n text: local(\"app\", inType),\n });\n return;\n }\n const symbol = checker.getSymbolAtLocation(node);\n for (const declaration of symbol?.declarations ?? []) {\n if (declaration.getSourceFile() !== source) continue;\n const top = topLevel(ts, declaration);\n if (!top || top === statement) continue;\n if (ts.isImportDeclaration(top)) {\n const set = importNames.get(top) ?? new Set<string>();\n set.add(node.text);\n importNames.set(top, set);\n continue;\n }\n const moved = exports.get(node.text);\n if (moved?.module === \"generated\") {\n list.push({\n start: node.getStart(source),\n end: node.getEnd(),\n text: local(moved.name, true),\n });\n continue;\n }\n if (moved?.module === \"computed\") {\n const set = computedImports;\n set.add(node.text);\n continue;\n }\n const dslNode = usesDsl(top);\n if (dslNode) {\n throw notSupportedYet(\n `moving \\`${declaredNames(ts, statement).join(\"`, `\")}\\` out of schema.ts: it uses \\`${node.text}\\`, which is built with the schema DSL`,\n where(node),\n );\n }\n keep(top);\n }\n }\n ts.forEachChild(node, visit);\n };\n visit(statement);\n };\n const computedImports = new Set<string>();\n for (const statement of extrasStatements) {\n if (!usesDsl(statement)) keep(statement);\n }\n if (kept.size === 0) return { exports, extrasFile: null, dropped };\n\n const ext = input.jsExtensions ? \".js\" : \"\";\n const lines: string[] = [\n \"// What schema.ts exported besides the schema, moved here by `jazz-tools upgrade`.\",\n \"// The schema is schema.ts (for `generate` only); its types are in jazz.generated.ts.\",\n ];\n if (jazzToolsTypes.size > 0)\n lines.push(`import type { ${[...jazzToolsTypes].sort().join(\", \")} } from \"jazz-tools\";`);\n for (const [statement, names] of importNames) {\n const line = importLine(ts, statement, names);\n if (line) lines.push(line);\n }\n if (generatedImports.size > 0) {\n const allTypes = [...generatedImports.values()].every((g) => g.typeOnly);\n const parts = [...generatedImports].map(([name, g]) => {\n const spec = g.local === name ? name : `${name} as ${g.local}`;\n return !allTypes && g.typeOnly ? `type ${spec}` : spec;\n });\n lines.push(\n `import ${allTypes ? \"type \" : \"\"}{ ${parts.join(\", \")} } from \"./jazz.generated${ext}\";`,\n );\n }\n if (computedImports.size > 0)\n lines.push(`import { ${[...computedImports].join(\", \")} } from \"./jazz.computed${ext}\";`);\n lines.push(\"\");\n for (const statement of [...kept].sort((a, b) => a.pos - b.pos)) {\n const start = statement.getFullStart();\n const text = applyEdits(\n source.text.slice(start, statement.getEnd()),\n edits.get(statement)!.map((e) => ({ ...e, start: e.start - start, end: e.end - start })),\n );\n lines.push(text.replace(/^\\s*\\n/, \"\"));\n }\n return { exports, extrasFile: `${lines.join(\"\\n\")}\\n`, dropped };\n}\n\n/**\n * An app ships its history through the migrations module schema.ts passes\n * to s.defineApp: alpha.65's validate writes it only then, and otherwise\n * just warns. Without it, stores may hold versions jazz.app.json doesn't\n * carry, so upgrade refuses rather than start the history empty. An explicit\n * `migrations: \"none\"` is the app saying it keeps no history.\n */\nfunction refuseMissingMigrations(\n ts: Ts,\n checker: TS.TypeChecker,\n declaration: TS.VariableDeclaration,\n where: (node: TS.Node) => string,\n notes: string[],\n): void {\n const call = unwrap(ts, declaration.initializer!) as TS.CallExpression;\n const options = call.arguments[1] && unwrap(ts, call.arguments[1]);\n const property =\n options && ts.isObjectLiteralExpression(options)\n ? options.properties.find(\n (p) =>\n (ts.isPropertyAssignment(p) || ts.isShorthandPropertyAssignment(p)) &&\n p.name.getText() === \"migrations\",\n )\n : undefined;\n const value =\n property && ts.isPropertyAssignment(property)\n ? unwrap(ts, property.initializer)\n : property && ts.isShorthandPropertyAssignment(property)\n ? property.name\n : undefined;\n if (value && ts.isStringLiteral(value) && value.text === \"none\") {\n notes.push(\n 'schema.ts declares `migrations: \"none\"`: jazz.app.json starts with no history, as the app shipped none.',\n );\n return;\n }\n // The value must come from an import of the migrations module.\n let imported = false;\n if (value && ts.isIdentifier(value)) {\n const symbol =\n property && ts.isShorthandPropertyAssignment(property)\n ? checker.getShorthandAssignmentValueSymbol(property)\n : checker.getSymbolAtLocation(value);\n const declarationNode = symbol?.declarations?.[0];\n let importDecl: TS.Node | undefined = declarationNode;\n while (importDecl && !ts.isImportDeclaration(importDecl)) importDecl = importDecl.parent;\n if (\n importDecl &&\n ts.isImportDeclaration(importDecl) &&\n ts.isStringLiteral(importDecl.moduleSpecifier)\n ) {\n imported = /(^|\\/)migrations(\\/index)?(\\.[mc]?[jt]s)?$/.test(importDecl.moduleSpecifier.text);\n }\n }\n if (imported) return;\n throw new UpgradeRefusal(\n \"schema.ts doesn't pass its migrations module to s.defineApp, so alpha.65 shipped no schema history and a store may \" +\n 'hold versions jazz.app.json doesn\\'t record. Add `import { migrations } from \"./migrations\";` and ' +\n \"`s.defineApp(schema, { migrations })`, run `npx jazz-tools validate` with the app's alpha.65 (it writes the history \" +\n 'into jazz.app.json), commit, then upgrade again. If the app really keeps no history, say `{ migrations: \"none\" }`.',\n where(call),\n );\n}\n\nfunction unwrap(ts: Ts, node: TS.Expression): TS.Expression {\n while (\n ts.isAsExpression(node) ||\n ts.isSatisfiesExpression(node) ||\n ts.isParenthesizedExpression(node)\n )\n node = node.expression;\n return node;\n}\n\nfunction isJazzTools(specifier: TS.Expression): boolean {\n const text = (specifier as TS.StringLiteral).text;\n return text === \"jazz-tools\" || text?.startsWith(\"jazz-tools/\");\n}\n\nfunction isExported(ts: Ts, statement: TS.Statement): boolean {\n const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) : undefined;\n return modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) ?? false;\n}\n\nfunction isTypeOnly(ts: Ts, statement: TS.Statement): boolean {\n return ts.isTypeAliasDeclaration(statement) || ts.isInterfaceDeclaration(statement);\n}\n\nexport function declaredNames(ts: Ts, statement: TS.Statement): string[] {\n if (ts.isVariableStatement(statement)) {\n return statement.declarationList.declarations.flatMap((d) =>\n ts.isIdentifier(d.name) ? [d.name.text] : [],\n );\n }\n const named = statement as TS.Statement & { name?: TS.Identifier };\n return named.name && ts.isIdentifier(named.name) ? [named.name.text] : [];\n}\n\nfunction topLevel(ts: Ts, node: TS.Node): TS.Statement | undefined {\n let current: TS.Node = node;\n while (current.parent && !ts.isSourceFile(current.parent)) current = current.parent;\n return current.parent ? (current as TS.Statement) : undefined;\n}\n\nfunction isPropertyNameOnly(ts: Ts, node: TS.Identifier): boolean {\n const parent = node.parent;\n if (ts.isPropertyAccessExpression(parent) && parent.name === node) return true;\n if (\n (ts.isPropertyAssignment(parent) ||\n ts.isPropertySignature(parent) ||\n ts.isMethodDeclaration(parent)) &&\n parent.name === node\n )\n return true;\n if (ts.isQualifiedName(parent) && parent.right === node) return true;\n if (\n ts.isTypeAliasDeclaration(parent) ||\n ts.isInterfaceDeclaration(parent) ||\n ts.isVariableDeclaration(parent) ||\n ts.isFunctionDeclaration(parent)\n ) {\n return (parent as { name?: TS.Node }).name === node;\n }\n return false;\n}\n\nfunction isInTypePosition(ts: Ts, node: TS.Node): boolean {\n for (let current = node.parent; current; current = current.parent) {\n if (ts.isTypeQueryNode(current)) return true;\n if (ts.isTypeNode(current) && !ts.isExpressionWithTypeArguments(current)) return true;\n if (ts.isStatement(current) || ts.isExpressionStatement(current)) return false;\n }\n return false;\n}\n\n/** An import of only `names` from `statement`, or null when it imports none of them. */\nexport function importLine(\n ts: Ts,\n statement: TS.ImportDeclaration,\n names: Set<string>,\n): string | null {\n const specifier = JSON.stringify((statement.moduleSpecifier as TS.StringLiteral).text);\n const clause = statement.importClause;\n if (!clause) return null;\n const typePrefix = clause.isTypeOnly ? \"type \" : \"\";\n const parts: string[] = [];\n const head: string[] = [];\n if (clause.name && names.has(clause.name.text)) head.push(clause.name.text);\n const bindings = clause.namedBindings;\n if (bindings && ts.isNamespaceImport(bindings) && names.has(bindings.name.text)) {\n return `import ${typePrefix}* as ${bindings.name.text} from ${specifier};`;\n }\n if (bindings && ts.isNamedImports(bindings)) {\n for (const element of bindings.elements) {\n if (!names.has(element.name.text)) continue;\n const name = element.propertyName\n ? `${element.propertyName.text} as ${element.name.text}`\n : element.name.text;\n parts.push(element.isTypeOnly ? `type ${name}` : name);\n }\n }\n if (parts.length > 0) head.push(`{ ${parts.join(\", \")} }`);\n if (head.length === 0) return null;\n return `import ${typePrefix}${head.join(\", \")} from ${specifier};`;\n}\n\nexport { UpgradeRefusal };\n"]}
|
package/dist/upgrade/fresh.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { type Project } from "./project.js";
|
|
2
|
-
/** The last release with `defineApp` and the callback permissions. */
|
|
3
|
-
export declare const LAST_DSL_ALPHA = 65;
|
|
4
|
-
export interface LegacyJazzTools {
|
|
5
|
-
/** The package directory. */
|
|
6
|
-
dir: string;
|
|
7
|
-
version: string;
|
|
8
|
-
}
|
|
9
|
-
/** The DSL-era alpha number of a jazz-tools version, or null when it has no DSL. */
|
|
10
|
-
export declare function dslAlpha(version: string): number | null;
|
|
11
|
-
/**
|
|
12
|
-
* The project's installed jazz-tools, which must still have the DSL: the old
|
|
13
|
-
* validate bundles schema.ts against it, and the checker reads its types.
|
|
14
|
-
*/
|
|
15
|
-
export declare function findLegacyJazzTools(project: Project): LegacyJazzTools;
|
|
16
|
-
/**
|
|
17
|
-
* The environment for the app's own jazz-tools: everything but what points
|
|
18
|
-
* Jazz at other native or WASM builds. jazz-napi and jazz-tools honour
|
|
19
|
-
* `JAZZ_CORRECTNESS_*` (the monorepo's sealed test artifacts) and napi-rs
|
|
20
|
-
* `NAPI_RS_*` overrides; inherited, they would run alpha.65's validate on
|
|
21
|
-
* this release's engine, which writes different files (no `slices`).
|
|
22
|
-
*/
|
|
23
|
-
export declare function legacyEnvironment(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
24
|
-
/** The bundle id and schema hashes of an app's two files. */
|
|
25
|
-
export type Identity = (app: string, permissions: string) => Promise<unknown>;
|
|
26
|
-
/**
|
|
27
|
-
* Freshness for a jazz.permissions.json with hand-written `defs`, which the
|
|
28
|
-
* old `validate` never writes (it inlines its helpers), so `--check` would
|
|
29
|
-
* call it stale: run the old `validate` on the project, put every file back,
|
|
30
|
-
* and compare what it wrote with the committed files, `defs` expanded, by
|
|
31
|
-
* what a deployment would get (schema hashes and bundle id).
|
|
32
|
-
*/
|
|
33
|
-
export declare function checkLegacyFilesWithDefs(project: Project, legacy: LegacyJazzTools, expanded: string, identity: Identity): Promise<string[]>;
|
|
34
|
-
/** Run the old `validate --check`, refusing what it refuses. */
|
|
35
|
-
export declare function checkLegacyFiles(project: Project, legacy: LegacyJazzTools): string[];
|
|
36
|
-
//# sourceMappingURL=fresh.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fresh.d.ts","sourceRoot":"","sources":["../../src/upgrade/fresh.ts"],"names":[],"mappings":"AAaA,OAAO,EAML,KAAK,OAAO,EACb,MAAM,cAAc,CAAC;AAEtB,sEAAsE;AACtE,eAAO,MAAM,cAAc,KAAK,CAAC;AAGjC,MAAM,WAAW,eAAe;IAC9B,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,oFAAoF;AACpF,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKvD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe,CAqBrE;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAY3E;AASD,6DAA6D;AAC7D,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE9E;;;;;;GAMG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CA6CnB;AAED,gEAAgE;AAChE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,GAAG,MAAM,EAAE,CAqCpF"}
|