@ethlete/query 6.0.0-next.2 → 6.0.0-next.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.
@@ -0,0 +1,97 @@
1
+ import * as ts from 'typescript';
2
+ const TEMP_SOURCE_FILE = 'temp.ts';
3
+ export const createSourceFile = (content, filePath = TEMP_SOURCE_FILE) => ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
4
+ export const capitalizeFirstLetter = (value) => {
5
+ if (value.length === 0) {
6
+ return value;
7
+ }
8
+ return `${value[0].toUpperCase()}${value.slice(1)}`;
9
+ };
10
+ export const ensureConfigSuffix = (name) => {
11
+ if (/Config$/i.test(name)) {
12
+ return name;
13
+ }
14
+ return `${name}Config`;
15
+ };
16
+ export const ensureNamedImports = ({ content, importsNeeded, moduleSpecifier }) => {
17
+ const sourceFile = createSourceFile(content);
18
+ let importNode;
19
+ ts.forEachChild(sourceFile, (node) => {
20
+ if (ts.isImportDeclaration(node) &&
21
+ ts.isStringLiteral(node.moduleSpecifier) &&
22
+ node.moduleSpecifier.text === moduleSpecifier) {
23
+ importNode = node;
24
+ }
25
+ });
26
+ const missingImports = new Set(importsNeeded);
27
+ if (importNode?.importClause?.namedBindings && ts.isNamedImports(importNode.importClause.namedBindings)) {
28
+ const namedBindings = importNode.importClause.namedBindings;
29
+ namedBindings.elements.forEach((element) => {
30
+ missingImports.delete(element.name.text);
31
+ });
32
+ if (missingImports.size === 0) {
33
+ return content;
34
+ }
35
+ const existingImports = namedBindings.elements.map((element) => element.getText(sourceFile));
36
+ const nextImports = [...existingImports, ...Array.from(missingImports).sort()].sort();
37
+ const nextImportStatement = `import { ${nextImports.join(', ')} } from '${moduleSpecifier}';`;
38
+ return content.slice(0, importNode.getStart(sourceFile)) + nextImportStatement + content.slice(importNode.getEnd());
39
+ }
40
+ let lastImportEnd = 0;
41
+ ts.forEachChild(sourceFile, (node) => {
42
+ if (!ts.isImportDeclaration(node)) {
43
+ return;
44
+ }
45
+ const end = node.getEnd();
46
+ if (end > lastImportEnd) {
47
+ lastImportEnd = end;
48
+ }
49
+ });
50
+ const nextImportStatement = `\nimport { ${Array.from(missingImports).sort().join(', ')} } from '${moduleSpecifier}';`;
51
+ if (lastImportEnd > 0) {
52
+ return content.slice(0, lastImportEnd) + nextImportStatement + content.slice(lastImportEnd);
53
+ }
54
+ return `import { ${Array.from(missingImports).sort().join(', ')} } from '${moduleSpecifier}';\n\n${content}`;
55
+ };
56
+ export const ensureImportFromQuery = (content, importsNeeded) => ensureNamedImports({ content, importsNeeded, moduleSpecifier: '@ethlete/query' });
57
+ export const ensureAngularCoreImports = (content, importsNeeded) => ensureNamedImports({ content, importsNeeded, moduleSpecifier: '@angular/core' });
58
+ export const getVariableStatementEnd = (sourceFile, variableName, initializerName) => {
59
+ let variableStatementEnd;
60
+ const visit = (node) => {
61
+ if (ts.isVariableDeclaration(node) &&
62
+ ts.isIdentifier(node.name) &&
63
+ node.name.text === variableName &&
64
+ node.initializer &&
65
+ ts.isCallExpression(node.initializer) &&
66
+ ts.isIdentifier(node.initializer.expression) &&
67
+ node.initializer.expression.text === initializerName) {
68
+ let parent = node.parent;
69
+ while (parent && !ts.isVariableStatement(parent)) {
70
+ parent = parent.parent;
71
+ }
72
+ if (parent && ts.isVariableStatement(parent)) {
73
+ variableStatementEnd = parent.getEnd();
74
+ }
75
+ }
76
+ ts.forEachChild(node, visit);
77
+ };
78
+ visit(sourceFile);
79
+ return variableStatementEnd;
80
+ };
81
+ export const getIndentation = (content, position) => {
82
+ let lineStart = position;
83
+ while (lineStart > 0 && content[lineStart - 1] !== '\n') {
84
+ lineStart -= 1;
85
+ }
86
+ let indentation = '';
87
+ for (let index = lineStart; index < position && /\s/.test(content[index]); index += 1) {
88
+ indentation += content[index];
89
+ }
90
+ return indentation || ' ';
91
+ };
92
+ export const getLineNumber = (node, sourceFile) => {
93
+ const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
94
+ return line + 1;
95
+ };
96
+ export const getLineNumberFromPosition = (content, position) => content.slice(0, position).split('\n').length;
97
+ //# sourceMappingURL=shared.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethlete/query",
3
- "version": "6.0.0-next.2",
3
+ "version": "6.0.0-next.4",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1186,10 +1186,10 @@ declare const paginatedEntityValueUpdater: <T extends Paginated<unknown>, Args e
1186
1186
  entity: Entity;
1187
1187
  }) => {
1188
1188
  response: T & {
1189
- items: any[];
1189
+ items: unknown[];
1190
1190
  };
1191
1191
  rawResponse: T & {
1192
- items: any[];
1192
+ items: unknown[];
1193
1193
  };
1194
1194
  } | null;
1195
1195