@tanstack/angular-query 5.0.0-rc.3 → 5.0.0-rc.4

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.
@@ -24,9 +24,10 @@ type GetCreateQueryOptionsForCreateQueries<T> = T extends {
24
24
  queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> | SkipTokenForCreateQueries;
25
25
  select?: (data: any) => infer TData;
26
26
  } ? QueryObserverOptionsForCreateQueries<TQueryFnData, QueryError<T>, unknown extends TData ? TQueryFnData : TData, TQueryKey> : QueryObserverOptionsForCreateQueries;
27
+ type IsDefinedInitialData<T, TData> = T extends TData ? true : T extends () => infer TValue ? unknown extends TValue ? false : TValue extends TData ? true : false : false;
27
28
  type GenericGetDefinedOrUndefinedQueryResult<T, TData, TUndefined, TDefined> = T extends {
28
29
  initialData?: infer TInitialData;
29
- } ? unknown extends TInitialData ? TUndefined : TInitialData extends TData ? TDefined : TInitialData extends () => infer TInitialDataResult ? unknown extends TInitialDataResult ? TUndefined : TInitialDataResult extends TData ? TDefined : TUndefined : TUndefined : TUndefined;
30
+ } ? unknown extends TInitialData ? TUndefined : IsDefinedInitialData<TInitialData, TData> extends true ? TDefined : TUndefined : TUndefined;
30
31
  type InferDataAndError<T> = T extends {
31
32
  queryFnData: any;
32
33
  error?: infer TError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/angular-query",
3
- "version": "5.0.0-rc.3",
3
+ "version": "5.0.0-rc.4",
4
4
  "description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
5
5
  "author": "Arnoud de Vries",
6
6
  "license": "MIT",
@@ -6,9 +6,9 @@ const tasks_1 = require("@angular-devkit/schematics/tasks");
6
6
  const source_1 = require("./source");
7
7
  const workspace_1 = require("./workspace");
8
8
  const PACKAGE_NAME = '@tanstack/angular-query';
9
- const PACKAGE_VERSION = '5.0.0-rc.3';
9
+ const PACKAGE_VERSION = '5.0.0-rc.4';
10
10
  const DEVTOOLS_PACKAGE_NAME = '@tanstack/angular-query-devtools';
11
- const DEVTOOLS_PACKAGE_VERSION = '5.0.0-rc.3';
11
+ const DEVTOOLS_PACKAGE_VERSION = '5.0.0-rc.4';
12
12
  const MIGRATION_GUIDE = 'https://tanstack.com/query/latest/docs/framework/angular/guides/migrating-from-experimental';
13
13
  const dependencyTypes = [
14
14
  dependencies_1.NodeDependencyType.Default,
@@ -78,19 +78,29 @@ function migrateDependencies(tree, manifest, needsDevtools, report, migrateCore,
78
78
  if (!dependencies)
79
79
  continue;
80
80
  const experimental = dependencies[source_1.OLD_PACKAGE];
81
- const core = migrateCore && dependencies[source_1.CORE_PACKAGE];
82
- if (!experimental && !core)
83
- continue;
81
+ const core = migrateCore ? dependencies[source_1.CORE_PACKAGE] : undefined;
82
+ const queryAlias = experimentalAlias(dependencies[PACKAGE_NAME]);
83
+ const devtoolsAlias = experimentalAlias(dependencies[DEVTOOLS_PACKAGE_NAME]);
84
84
  if (experimental)
85
85
  changes++;
86
86
  if (core && !remainingCoreReference)
87
87
  changes++;
88
- if (!dependencies[PACKAGE_NAME]) {
88
+ if (queryAlias !== undefined ||
89
+ ((experimental || core) && !dependencies[PACKAGE_NAME])) {
89
90
  (0, dependencies_1.addPackageJsonDependency)(tree, {
90
91
  type,
91
92
  name: PACKAGE_NAME,
92
- version: `^${PACKAGE_VERSION}`,
93
- overwrite: false,
93
+ version: replacementVersion(queryAlias ?? experimental ?? core, PACKAGE_VERSION),
94
+ overwrite: queryAlias !== undefined,
95
+ }, manifest);
96
+ changes++;
97
+ }
98
+ if (devtoolsAlias !== undefined) {
99
+ (0, dependencies_1.addPackageJsonDependency)(tree, {
100
+ type,
101
+ name: DEVTOOLS_PACKAGE_NAME,
102
+ version: replacementVersion(devtoolsAlias, DEVTOOLS_PACKAGE_VERSION),
103
+ overwrite: true,
94
104
  }, manifest);
95
105
  changes++;
96
106
  }
@@ -113,7 +123,12 @@ function migrateDependencies(tree, manifest, needsDevtools, report, migrateCore,
113
123
  (0, dependencies_1.addPackageJsonDependency)(tree, {
114
124
  type,
115
125
  name: DEVTOOLS_PACKAGE_NAME,
116
- version: `^${DEVTOOLS_PACKAGE_VERSION}`,
126
+ version: replacementVersion(experimentalAlias(pkg[type]?.[PACKAGE_NAME]) ??
127
+ pkg[type]?.[source_1.OLD_PACKAGE] ??
128
+ current[type]?.[PACKAGE_NAME] ??
129
+ dependencyTypes
130
+ .map((group) => current[group]?.[PACKAGE_NAME])
131
+ .find(Boolean), DEVTOOLS_PACKAGE_VERSION),
117
132
  overwrite: false,
118
133
  }, manifest);
119
134
  changes++;
@@ -127,3 +142,17 @@ function migrateDependencies(tree, manifest, needsDevtools, report, migrateCore,
127
142
  report(`${manifest}: Rename peerDependenciesMeta["${name}"] to "${PACKAGE_NAME}" and review the optional peer configuration.`);
128
143
  return changes;
129
144
  }
145
+ function experimentalAlias(version) {
146
+ if (version === `npm:${source_1.OLD_PACKAGE}`)
147
+ return '*';
148
+ const prefix = `npm:${source_1.OLD_PACKAGE}@`;
149
+ return version?.startsWith(prefix) ? version.slice(prefix.length) : undefined;
150
+ }
151
+ /** Preserve exact pins; retain the existing caret policy for other specifiers. */
152
+ function replacementVersion(previous, version) {
153
+ const normalized = previous?.trim().replace(/^(?:=\s*)?v?/, '');
154
+ return normalized &&
155
+ /^\d+\.\d+\.\d+(?:-[\dA-Za-z.-]+)?(?:\+[\dA-Za-z.-]+)?$/.test(normalized)
156
+ ? version
157
+ : `^${version}`;
158
+ }
@@ -88,7 +88,10 @@ function configPattern(root, pattern) {
88
88
  .join('');
89
89
  return new RegExp(`^${expression}$`);
90
90
  }
91
- function configuredSources(tree, configPath) {
91
+ function configuredSources(tree, configPath, visited = new Set()) {
92
+ if (visited.has(configPath))
93
+ return [];
94
+ visited.add(configPath);
92
95
  const readFile = (path) => tree.exists(path) ? tree.readText(path) : undefined;
93
96
  const config = typescript_1.default.getParsedCommandLineOfConfigFile(configPath, { noLib: true }, {
94
97
  useCaseSensitiveFileNames: true,
@@ -119,6 +122,9 @@ function configuredSources(tree, configPath) {
119
122
  host.readFile = readFile;
120
123
  host.realpath = (path) => path;
121
124
  host.directoryExists = (path) => {
125
+ // TypeScript also probes file paths here; `getDir` throws on those.
126
+ if (tree.exists(path))
127
+ return false;
122
128
  const directory = tree.getDir(path);
123
129
  return directory.subfiles.length > 0 || directory.subdirs.length > 0;
124
130
  };
@@ -130,11 +136,15 @@ function configuredSources(tree, configPath) {
130
136
  ? undefined
131
137
  : typescript_1.default.createSourceFile(path, text, typescript_1.default.ScriptTarget.Latest, true);
132
138
  };
133
- return typescript_1.default
139
+ const sources = typescript_1.default
134
140
  .createProgram(config.fileNames, config.options, host)
135
141
  .getSourceFiles()
136
142
  .map((source) => source.fileName)
137
143
  .filter(isSource);
144
+ return [
145
+ ...sources,
146
+ ...(config.projectReferences ?? []).flatMap((reference) => configuredSources(tree, typescript_1.default.resolveProjectReferencePath(reference), visited)),
147
+ ];
138
148
  }
139
149
  /** Use Angular/Nx projects and their declared configs, including inherited configs and local imports. */
140
150
  async function migrationWorkspace(tree) {
@@ -147,49 +157,75 @@ async function migrationWorkspace(tree) {
147
157
  const project = projects.get(root) ?? {
148
158
  sourceRoot,
149
159
  configs: new Set(),
160
+ hasExplicitTestConfig: false,
150
161
  };
151
162
  project.sourceRoot ??= sourceRoot;
152
163
  projects.set(root, project);
153
164
  const manifest = node_path_1.posix.join(root, 'package.json');
154
165
  if (tree.exists(manifest))
155
166
  manifests.add(manifest);
156
- for (const target of targets) {
167
+ for (const [name, target] of targets) {
157
168
  for (const options of [
158
169
  target.options,
159
170
  ...Object.values(target.configurations ?? {}),
160
171
  ]) {
161
- if (typeof options?.tsConfig === 'string' &&
162
- tree.exists(options.tsConfig))
163
- project.configs.add(node_path_1.posix.resolve('/', options.tsConfig));
172
+ const tsConfig = options?.tsConfig;
173
+ if (typeof tsConfig !== 'string')
174
+ continue;
175
+ if (name === 'test' || name.startsWith('test:'))
176
+ project.hasExplicitTestConfig = true;
177
+ const config = node_path_1.posix.resolve('/', tsConfig);
178
+ if (tree.exists(config))
179
+ project.configs.add(config);
164
180
  }
165
181
  }
166
182
  };
167
183
  if (tree.exists('/angular.json') || tree.exists('/.angular.json')) {
168
184
  const workspace = await (0, workspace_1.getWorkspace)(tree, tree.exists('/angular.json') ? '/angular.json' : '/.angular.json');
169
185
  for (const project of workspace.projects.values())
170
- addProject(project.root, project.sourceRoot, project.targets.values());
186
+ addProject(project.root, project.sourceRoot, project.targets.entries());
171
187
  }
172
188
  if (tree.exists('/nx.json')) {
173
189
  for (const path of filesUnder(tree, '/')) {
174
190
  if (node_path_1.posix.basename(path) === 'project.json') {
175
191
  const project = tree.readJson(path);
176
- addProject(project.root ?? node_path_1.posix.dirname(path), project.sourceRoot, Object.values(project.targets ?? {}));
192
+ addProject(project.root ?? node_path_1.posix.dirname(path), project.sourceRoot, Object.entries(project.targets ?? {}));
177
193
  }
178
194
  else if (node_path_1.posix.basename(path) === 'package.json') {
179
195
  const pkg = tree.readJson(path);
180
196
  if (pkg.nx)
181
- addProject(node_path_1.posix.dirname(path), pkg.nx.sourceRoot, Object.values(pkg.nx.targets ?? {}));
197
+ addProject(node_path_1.posix.dirname(path), pkg.nx.sourceRoot, Object.entries(pkg.nx.targets ?? {}));
182
198
  }
183
199
  }
184
200
  }
185
201
  if (!projects.size)
186
- return { files: sourcesUnder(tree, '/'), manifests: [...manifests] };
202
+ addProject('/', undefined, []);
187
203
  const files = new Set();
188
204
  for (const [root, project] of projects) {
205
+ // Infer defaults only after Angular and Nx declarations have been merged.
206
+ if (!project.configs.size) {
207
+ for (const name of [
208
+ 'tsconfig.json',
209
+ 'tsconfig.app.json',
210
+ 'tsconfig.lib.json',
211
+ ]) {
212
+ const config = node_path_1.posix.join(root, name);
213
+ if (tree.exists(config))
214
+ project.configs.add(config);
215
+ }
216
+ }
217
+ const testConfigs = project.hasExplicitTestConfig
218
+ ? []
219
+ : ['tsconfig.spec.json', 'tsconfig.test.json']
220
+ .map((name) => node_path_1.posix.join(root, name))
221
+ .filter((path) => tree.exists(path));
189
222
  const sources = project.configs.size
190
223
  ? [...project.configs].flatMap((path) => configuredSources(tree, path))
191
- : sourcesUnder(tree, node_path_1.posix.resolve('/', project.sourceRoot ?? root));
192
- for (const path of sources)
224
+ : sourcesUnder(tree, node_path_1.posix.resolve('/', project.sourceRoot ?? root)).filter((path) => !testConfigs.length || !/\.(spec|test)\.[cm]?tsx?$/.test(path));
225
+ for (const path of [
226
+ ...sources,
227
+ ...testConfigs.flatMap((configPath) => configuredSources(tree, configPath)),
228
+ ])
193
229
  files.add(path);
194
230
  }
195
231
  return { files: [...files], manifests: [...manifests] };
@@ -16,7 +16,7 @@ const typescript_1 = __importDefault(require("typescript"));
16
16
  // The published schematic contains literal values and does not read package.json.
17
17
  const PACKAGE_NAME = '@tanstack/angular-query';
18
18
  const DEVTOOLS_PACKAGE_NAME = '@tanstack/angular-query-devtools';
19
- const DEVTOOLS_PACKAGE_VERSION = '5.0.0-rc.3';
19
+ const DEVTOOLS_PACKAGE_VERSION = '5.0.0-rc.4';
20
20
  function hasPackageDependency(tree, name) {
21
21
  const packageJsonPath = tree.exists('/package.json')
22
22
  ? '/package.json'
package/types.d.ts CHANGED
@@ -17,14 +17,14 @@ type CreateStatusBasedDefinedInfiniteQueryResult<TStatus extends DefinedInfinite
17
17
  status: TStatus;
18
18
  }>;
19
19
  export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
20
- isSuccess: SignalFunction<(this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>>;
21
- isError: SignalFunction<(this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>>;
22
- isPending: SignalFunction<(this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>>;
20
+ isSuccess: SignalFunction<() => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>>;
21
+ isError: SignalFunction<() => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>>;
22
+ isPending: SignalFunction<() => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>>;
23
23
  }
24
24
  export interface DefinedQueryNarrowing<TData = unknown, TError = DefaultError> {
25
- isSuccess: SignalFunction<(this: DefinedCreateQueryResult<TData, TError>) => this is DefinedCreateQueryResult<TData, TError, CreateStatusBasedDefinedQueryResult<'success', TData, TError>>>;
26
- isError: SignalFunction<(this: DefinedCreateQueryResult<TData, TError>) => this is DefinedCreateQueryResult<TData, TError, CreateStatusBasedDefinedQueryResult<'error', TData, TError>>>;
27
- isPending: SignalFunction<(this: DefinedCreateQueryResult<TData, TError>) => this is never>;
25
+ isSuccess: SignalFunction<() => this is DefinedCreateQueryResult<TData, TError, CreateStatusBasedDefinedQueryResult<'success', TData, TError>>>;
26
+ isError: SignalFunction<() => this is DefinedCreateQueryResult<TData, TError, CreateStatusBasedDefinedQueryResult<'error', TData, TError>>>;
27
+ isPending: SignalFunction<() => this is never>;
28
28
  }
29
29
  export interface BaseInfiniteQueryNarrowing<TData = unknown, TError = DefaultError> {
30
30
  isSuccess: SignalFunction<(this: CreateInfiniteQueryResult<TData, TError>) => this is CreateInfiniteQueryResult<TData, TError, CreateStatusBasedInfiniteQueryResult<'success', TData, TError>>>;