@stamhoofd/backend-statistics-syncer 2.153.0 → 2.160.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 (83) hide show
  1. package/LICENSE.md +7 -7
  2. package/README.md +1 -1
  3. package/dist/index.js +5 -8
  4. package/dist/index.js.map +1 -0
  5. package/dist/migrations.js +19 -0
  6. package/dist/migrations.js.map +1 -0
  7. package/dist/src/boot.js +75 -0
  8. package/dist/src/boot.js.map +1 -0
  9. package/dist/src/crons.js +39 -0
  10. package/dist/src/crons.js.map +1 -0
  11. package/dist/src/database.js +88 -0
  12. package/dist/src/database.js.map +1 -0
  13. package/dist/src/migrate.js +38 -0
  14. package/dist/src/migrate.js.map +1 -0
  15. package/dist/src/migrations/1785958573-platform-statistics-schema.sql +382 -0
  16. package/dist/src/migrations/1786203367-postal-code-coordinates.sql +1203 -0
  17. package/dist/src/periods.js +86 -0
  18. package/dist/src/periods.js.map +1 -0
  19. package/dist/src/rows.js +209 -0
  20. package/dist/src/rows.js.map +1 -0
  21. package/dist/src/schema.js +28 -0
  22. package/dist/src/schema.js.map +1 -0
  23. package/dist/src/sources.js +10 -0
  24. package/dist/src/sources.js.map +1 -0
  25. package/dist/src/sync-state.js +36 -0
  26. package/dist/src/sync-state.js.map +1 -0
  27. package/dist/src/sync.js +608 -0
  28. package/dist/src/sync.js.map +1 -0
  29. package/dist/src/writer.js +63 -0
  30. package/dist/src/writer.js.map +1 -0
  31. package/dist-types/index.d.ts +2 -0
  32. package/dist-types/index.d.ts.map +1 -0
  33. package/dist-types/migrations.d.ts +2 -0
  34. package/dist-types/migrations.d.ts.map +1 -0
  35. package/dist-types/src/boot.d.ts +8 -0
  36. package/dist-types/src/boot.d.ts.map +1 -0
  37. package/dist-types/src/crons.d.ts +21 -0
  38. package/dist-types/src/crons.d.ts.map +1 -0
  39. package/dist-types/src/database.d.ts +28 -0
  40. package/dist-types/src/database.d.ts.map +1 -0
  41. package/dist-types/src/migrate.d.ts +2 -0
  42. package/dist-types/src/migrate.d.ts.map +1 -0
  43. package/dist-types/src/periods.d.ts +51 -0
  44. package/dist-types/src/periods.d.ts.map +1 -0
  45. package/dist-types/src/rows.d.ts +212 -0
  46. package/dist-types/src/rows.d.ts.map +1 -0
  47. package/dist-types/src/schema.d.ts +9 -0
  48. package/dist-types/src/schema.d.ts.map +1 -0
  49. package/dist-types/src/sources.d.ts +10 -0
  50. package/dist-types/src/sources.d.ts.map +1 -0
  51. package/dist-types/src/sync-state.d.ts +20 -0
  52. package/dist-types/src/sync-state.d.ts.map +1 -0
  53. package/dist-types/src/sync.d.ts +37 -0
  54. package/dist-types/src/sync.d.ts.map +1 -0
  55. package/dist-types/src/writer.d.ts +24 -0
  56. package/dist-types/src/writer.d.ts.map +1 -0
  57. package/index.ts +5 -8
  58. package/migrations.ts +16 -11
  59. package/package.json +37 -23
  60. package/src/boot.ts +7 -3
  61. package/src/crons.test.ts +33 -8
  62. package/src/crons.ts +7 -1
  63. package/src/database.test.ts +48 -11
  64. package/src/database.ts +30 -7
  65. package/src/migrate.ts +1 -1
  66. package/src/periods.ts +5 -2
  67. package/src/rows.test.ts +96 -16
  68. package/src/rows.ts +28 -6
  69. package/src/schema.test.ts +48 -19
  70. package/src/schema.ts +14 -4
  71. package/src/sync-state.test.ts +3 -1
  72. package/src/sync-state.ts +13 -4
  73. package/src/sync.test.ts +145 -32
  74. package/src/sync.ts +422 -91
  75. package/src/writer.ts +32 -10
  76. package/tsconfig.build.json +4 -11
  77. package/tsconfig.json +1 -1
  78. package/tsconfig.test.json +1 -3
  79. package/tsconfig.types.json +7 -0
  80. package/.gitignore +0 -221
  81. package/tests/vitest.global.setup.ts +0 -29
  82. package/tests/vitest.setup.ts +0 -24
  83. package/vitest.config.js +0 -18
package/src/writer.ts CHANGED
@@ -10,30 +10,49 @@ export const batchSize = 500;
10
10
  /** What identifies a row when no other key is given. `members` is keyed per period as well. */
11
11
  export const defaultKeyColumns = ['id'];
12
12
 
13
- export function buildUpsertQuery(table: string, columns: string[], escapeId: (value: string) => string, keyColumns: string[] = defaultKeyColumns): string {
13
+ export function buildUpsertQuery(
14
+ table: string,
15
+ columns: string[],
16
+ escapeId: (value: string) => string,
17
+ keyColumns: string[] = defaultKeyColumns,
18
+ ): string {
14
19
  const assignments = columns
15
- .filter(column => !keyColumns.includes(column))
16
- .map(column => `${escapeId(column)} = new.${escapeId(column)}`);
20
+ .filter((column) => !keyColumns.includes(column))
21
+ .map((column) => `${escapeId(column)} = new.${escapeId(column)}`);
17
22
 
18
23
  // The row alias is the MySQL 8 replacement for VALUES(col), which is deprecated.
19
- return `INSERT INTO ${escapeId(table)} (${columns.map(escapeId).join(', ')}) VALUES ? AS new`
20
- + (assignments.length > 0 ? ` ON DUPLICATE KEY UPDATE ${assignments.join(', ')}` : '');
24
+ return (
25
+ `INSERT INTO ${escapeId(table)} (${columns.map(escapeId).join(', ')}) VALUES ? AS new` +
26
+ (assignments.length > 0 ? ` ON DUPLICATE KEY UPDATE ${assignments.join(', ')}` : '')
27
+ );
21
28
  }
22
29
 
23
30
  /**
24
31
  * Write rows, replacing the ones that are already there. Running the same batch twice is a no-op, so
25
32
  * a run that crashed halfway can simply be repeated.
26
33
  */
27
- export async function upsertRows(table: string, columns: string[], rows: StatisticsRow[], keyColumns: string[] = defaultKeyColumns): Promise<number> {
34
+ export async function upsertRows(
35
+ table: string,
36
+ columns: string[],
37
+ rows: StatisticsRow[],
38
+ keyColumns: string[] = defaultKeyColumns,
39
+ ): Promise<number> {
28
40
  if (rows.length === 0) {
29
41
  return 0;
30
42
  }
31
43
 
32
44
  const connection = getStatisticsConnection();
33
- const query = buildUpsertQuery(table, columns, value => connection.escapeId(value), keyColumns);
45
+ const query = buildUpsertQuery(
46
+ table,
47
+ columns,
48
+ (value) => connection.escapeId(value),
49
+ keyColumns,
50
+ );
34
51
 
35
52
  for (let index = 0; index < rows.length; index += batchSize) {
36
- const batch = rows.slice(index, index + batchSize).map(row => columns.map(column => row[column] ?? null));
53
+ const batch = rows
54
+ .slice(index, index + batchSize)
55
+ .map((row) => columns.map((column) => row[column] ?? null));
37
56
  await connection.insert(query, [batch]);
38
57
  }
39
58
 
@@ -46,7 +65,10 @@ export async function deleteRows(table: string, ids: string[]): Promise<number>
46
65
  }
47
66
 
48
67
  const connection = getStatisticsConnection();
49
- const [result] = await connection.delete(`DELETE FROM ${connection.escapeId(table)} WHERE \`id\` IN (?)`, [ids]);
68
+ const [result] = await connection.delete(
69
+ `DELETE FROM ${connection.escapeId(table)} WHERE \`id\` IN (?)`,
70
+ [ids],
71
+ );
50
72
  return result.affectedRows;
51
73
  }
52
74
 
@@ -67,7 +89,7 @@ export async function* iterateIds(table: string, source: string): AsyncGenerator
67
89
  [source, cursor],
68
90
  { nestTables: false },
69
91
  );
70
- const ids = (rows as unknown as { id: string }[]).map(row => row.id);
92
+ const ids = (rows as unknown as { id: string }[]).map((row) => row.id);
71
93
  if (ids.length === 0) {
72
94
  return;
73
95
  }
@@ -1,17 +1,10 @@
1
1
  {
2
- "extends": "../../../tsconfig.base.json",
2
+ "extends": ["../../../tsconfig.base.json", "../../../tsconfig.runtime.json"],
3
3
  "compilerOptions": {
4
+ "tsBuildInfoFile": ".cache/build.tsbuildinfo",
4
5
  "rootDir": ".",
5
6
  "outDir": "dist"
6
7
  },
7
- "include": [
8
- "./index.ts",
9
- "./migrations.ts",
10
- "./src",
11
- "./stamhoofd.d.ts"
12
- ],
13
- "exclude": [
14
- "./src/**/*.spec.ts",
15
- "./src/**/*.test.ts"
16
- ]
8
+ "include": ["./index.ts", "./migrations.ts", "./src", "./stamhoofd.d.ts"],
9
+ "exclude": ["./src/**/*.spec.ts", "./src/**/*.test.ts"]
17
10
  }
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "files": [],
4
4
  "references": [
5
5
  {
6
- "path": "./tsconfig.build.json"
6
+ "path": "./tsconfig.types.json"
7
7
  },
8
8
  {
9
9
  "path": "./tsconfig.test.json"
@@ -5,9 +5,7 @@
5
5
  "outDir": "dist",
6
6
  "noEmit": true
7
7
  },
8
- "references": [
9
- { "path": "./tsconfig.build.json" }
10
- ],
8
+ "references": [{ "path": "./tsconfig.types.json" }],
11
9
  "include": [
12
10
  "./stamhoofd.d.ts",
13
11
  "../../../jest-extended.d.ts",
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": ["./tsconfig.build.json", "../../../tsconfig.types.json"],
3
+ "compilerOptions": {
4
+ "outDir": "dist-types",
5
+ "tsBuildInfoFile": ".cache/types.tsbuildinfo"
6
+ }
7
+ }
package/.gitignore DELETED
@@ -1,221 +0,0 @@
1
- /devops/
2
- node_modules/
3
- .node_modules/
4
- built/*
5
- tests/cases/rwc/*
6
- tests/cases/test262/*
7
- tests/cases/perf/*
8
- !tests/cases/webharness/compilerToString.js
9
- test-args.txt
10
- ~*.docx
11
- \#*\#
12
- .\#*
13
- tests/baselines/local/*
14
- tests/baselines/local.old/*
15
- tests/services/baselines/local/*
16
- tests/baselines/prototyping/local/*
17
- tests/baselines/rwc/*
18
- tests/baselines/test262/*
19
- tests/baselines/reference/projectOutput/*
20
- tests/baselines/local/projectOutput/*
21
- tests/baselines/reference/testresults.tap
22
- tests/services/baselines/prototyping/local/*
23
- tests/services/browser/typescriptServices.js
24
- src/harness/*.js
25
- src/compiler/diagnosticInformationMap.generated.ts
26
- src/compiler/diagnosticMessages.generated.json
27
- src/parser/diagnosticInformationMap.generated.ts
28
- src/parser/diagnosticMessages.generated.json
29
- rwc-report.html
30
- *.swp
31
- build.json
32
- *.actual
33
- tests/webTestServer.js
34
- tests/webTestServer.js.map
35
- tests/webhost/*.d.ts
36
- tests/webhost/webtsc.js
37
- tests/cases/**/*.js
38
- !tests/cases/docker/*.js/
39
- tests/cases/**/*.js.map
40
- *.config
41
- scripts/eslint/built/
42
- scripts/debug.bat
43
- scripts/run.bat
44
- scripts/word2md.js
45
- scripts/buildProtocol.js
46
- scripts/ior.js
47
- scripts/authors.js
48
- scripts/configurePrerelease.js
49
- scripts/configureLanguageServiceBuild.js
50
- scripts/open-user-pr.js
51
- scripts/open-cherry-pick-pr.js
52
- scripts/processDiagnosticMessages.d.ts
53
- scripts/processDiagnosticMessages.js
54
- scripts/produceLKG.js
55
- scripts/importDefinitelyTypedTests/importDefinitelyTypedTests.js
56
- scripts/generateLocalizedDiagnosticMessages.js
57
- scripts/request-pr-review.js
58
- scripts/*.js.map
59
- scripts/typings/
60
- coverage/
61
- internal/
62
- **/.DS_Store
63
- .settings
64
- !tests/cases/projects/projectOption/**/node_modules
65
- !tests/cases/projects/NodeModulesSearch/**/*
66
- !tests/baselines/reference/project/nodeModules*/**/*
67
- .idea
68
- yarn-error.log
69
- .parallelperf.*
70
- tests/cases/user/*/package-lock.json
71
- tests/cases/user/*/node_modules/
72
- tests/cases/user/*/**/*.js
73
- tests/cases/user/*/**/*.js.map
74
- tests/cases/user/*/**/*.d.ts
75
- !tests/cases/user/zone.js/
76
- !tests/cases/user/bignumber.js/
77
- !tests/cases/user/discord.js/
78
- tests/baselines/reference/dt
79
- .failed-tests
80
- TEST-results.xml
81
- package-lock.json
82
- tests/cases/user/TypeScript-React-Starter/TypeScript-React-Starter
83
- tests/cases/user/TypeScript-Node-Starter/TypeScript-Node-Starter
84
- tests/cases/user/TypeScript-React-Native-Starter/TypeScript-React-Native-Starter
85
- tests/cases/user/TypeScript-Vue-Starter/TypeScript-Vue-Starter
86
- tests/cases/user/TypeScript-WeChat-Starter/TypeScript-WeChat-Starter
87
- tests/cases/user/create-react-app/create-react-app
88
- tests/cases/user/fp-ts/fp-ts
89
- tests/cases/user/webpack/webpack
90
- tests/cases/user/puppeteer/puppeteer
91
- tests/cases/user/axios-src/axios-src
92
- tests/cases/user/prettier/prettier
93
- .eslintcache
94
-
95
- # Logs
96
- logs
97
- *.log
98
- npm-debug.log*
99
- yarn-debug.log*
100
- yarn-error.log*
101
- lerna-debug.log*
102
-
103
- # Diagnostic reports (https://nodejs.org/api/report.html)
104
- report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
105
-
106
- # Runtime data
107
- pids
108
- *.pid
109
- *.seed
110
- *.pid.lock
111
-
112
- # Directory for instrumented libs generated by jscoverage/JSCover
113
- lib-cov
114
-
115
- # Coverage directory used by tools like istanbul
116
- coverage
117
- *.lcov
118
-
119
- # nyc test coverage
120
- .nyc_output
121
-
122
- # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
123
- .grunt
124
-
125
- # Bower dependency directory (https://bower.io/)
126
- bower_components
127
-
128
- # node-waf configuration
129
- .lock-wscript
130
-
131
- # Compiled binary addons (https://nodejs.org/api/addons.html)
132
- build/Release
133
-
134
- # Dependency directories
135
- node_modules/
136
- jspm_packages/
137
-
138
- # Snowpack dependency directory (https://snowpack.dev/)
139
- web_modules/
140
-
141
- # TypeScript cache
142
- *.tsbuildinfo
143
-
144
- # Optional npm cache directory
145
- .npm
146
-
147
- # Optional eslint cache
148
- .eslintcache
149
-
150
- # Microbundle cache
151
- .rpt2_cache/
152
- .rts2_cache_cjs/
153
- .rts2_cache_es/
154
- .rts2_cache_umd/
155
-
156
- # Optional REPL history
157
- .node_repl_history
158
-
159
- # Output of 'npm pack'
160
- *.tgz
161
-
162
- # Yarn Integrity file
163
- .yarn-integrity
164
-
165
- # dotenv environment variables file
166
- .env
167
- .env.test
168
-
169
- # parcel-bundler cache (https://parceljs.org/)
170
- .cache
171
- .parcel-cache
172
-
173
- # Next.js build output
174
- .next
175
-
176
- # Nuxt.js build / generate output
177
- .nuxt
178
- dist
179
-
180
- # Gatsby files
181
- .cache/
182
- # Comment in the public line in if your project uses Gatsby and not Next.js
183
- # https://nextjs.org/blog/next-9-1#public-directory-support
184
- # public
185
-
186
- # vuepress build output
187
- .vuepress/dist
188
-
189
- # Serverless directories
190
- .serverless/
191
-
192
- # FuseBox cache
193
- .fusebox/
194
-
195
- # DynamoDB Local files
196
- .dynamodb/
197
-
198
- # TernJS port file
199
- .tern-port
200
-
201
- # Stores VSCode versions used for testing VSCode extensions
202
- .vscode-test
203
-
204
- # yarn v2
205
-
206
- .yarn/cache
207
- .yarn/unplugged
208
- .yarn/build-state.yml
209
- .pnp.*
210
-
211
- .yalc
212
- yalc.lock
213
-
214
- .yarn
215
-
216
- # Yarnrc should be removed from git, because it breaks yarn if the version is not installed yet
217
- .yarnrc
218
-
219
- .env.json
220
- .env.*.json
221
- !.env.template.json
@@ -1,29 +0,0 @@
1
- import { TestUtils } from '@stamhoofd/test-utils';
2
- import path from 'path';
3
-
4
- // Dates are stored and compared in UTC everywhere else in the repo; a date column read back in
5
- // another zone lands a day off.
6
- process.env.TZ = 'UTC';
7
-
8
- if (new Date().getTimezoneOffset() !== 0) {
9
- throw new Error('Process should always run in UTC timezone');
10
- }
11
-
12
- const modelsPath = require.resolve('@stamhoofd/models');
13
-
14
- export async function setup() {
15
- TestUtils.globalSetup();
16
-
17
- const { Database, Migration } = await import('@simonbackx/simple-database');
18
- const { endStatisticsConnection } = await import('../src/database.js');
19
- const { runStatisticsMigrations } = await import('../src/schema.js');
20
-
21
- // The sync reads the source tables, so the main database has to be migrated as well.
22
- if (!await Migration.runAll(path.dirname(modelsPath) + '/migrations')) {
23
- throw new Error('Migrations failed');
24
- }
25
-
26
- await runStatisticsMigrations();
27
- await endStatisticsConnection();
28
- await Database.end();
29
- };
@@ -1,24 +0,0 @@
1
- import { Column, Database } from '@simonbackx/simple-database';
2
- import { endStatisticsConnection } from '../src/database.js';
3
- import { Version } from '@stamhoofd/structures';
4
- import { TestUtils } from '@stamhoofd/test-utils';
5
-
6
- Error.stackTraceLimit = 100;
7
-
8
- // Set version of saved structures
9
- Column.setJSONVersion(Version);
10
-
11
- // Set timezone!
12
- process.env.TZ = 'UTC';
13
-
14
- // Quick check
15
- if (new Date().getTimezoneOffset() !== 0) {
16
- throw new Error('Process should always run in UTC timezone');
17
- }
18
-
19
- afterAll(async () => {
20
- await endStatisticsConnection();
21
- await Database.end();
22
- });
23
-
24
- TestUtils.setup();
package/vitest.config.js DELETED
@@ -1,18 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- include: ['**/*.test.ts'], // only match TypeScript sources, so compiled copies in dist are never picked up
6
- globalSetup: './tests/vitest.global.setup.ts',
7
- setupFiles: ['./tests/vitest.setup.ts'],
8
- watch: false,
9
- globals: true,
10
- root: import.meta.dirname,
11
- isolate: true,
12
- coverage: {
13
- provider: 'v8',
14
- include: ['src/**'],
15
- reporter: ['text', 'html', 'lcov'],
16
- },
17
- },
18
- });