syncables 0.10.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/LICENSE +201 -0
- package/README.md +115 -0
- package/build/src/db.js +73 -0
- package/build/src/db.js.map +1 -0
- package/build/src/readme-example.js +16 -0
- package/build/src/readme-example.js.map +1 -0
- package/build/src/syncable.js +275 -0
- package/build/src/syncable.js.map +1 -0
- package/compose.yaml +15 -0
- package/package.json +76 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Syncables
|
|
2
|
+
|
|
3
|
+
This repository contains a sync engine that can be used to download (and in the future also update) a collection of objects from an API. It can be configured declaratively by extending the OpenAPI spec.
|
|
4
|
+
|
|
5
|
+
Find the path that can be used to fetch a (paged) collection of items. This will typically look something like this:
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
paths:
|
|
9
|
+
/widgets:
|
|
10
|
+
get:
|
|
11
|
+
parameters:
|
|
12
|
+
- description: Token specifying which result page to return. Optional.
|
|
13
|
+
in: query
|
|
14
|
+
name: pageToken
|
|
15
|
+
schema:
|
|
16
|
+
type: string
|
|
17
|
+
responses:
|
|
18
|
+
"200":
|
|
19
|
+
content:
|
|
20
|
+
application/json:
|
|
21
|
+
schema:
|
|
22
|
+
$ref: "#/components/schemas/CalendarList"
|
|
23
|
+
components:
|
|
24
|
+
schemas:
|
|
25
|
+
CalendarList:
|
|
26
|
+
properties:
|
|
27
|
+
results:
|
|
28
|
+
items:
|
|
29
|
+
properties:
|
|
30
|
+
backgroundColor:
|
|
31
|
+
type: string
|
|
32
|
+
type: array
|
|
33
|
+
nextPageToken:
|
|
34
|
+
description: Token used to access the next page of this result. Omitted if no further results are available.
|
|
35
|
+
type: string
|
|
36
|
+
type: object
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Under `paths['/widgets']['get']['responses']['200']['content']['application/json']`, add an object `syncable`, in which you can specify:
|
|
40
|
+
* `name`: a `string` descriptor of the collection, e.g. `"widgets"`
|
|
41
|
+
* `pagingStrategy`: one of `pageNumber`, `offset`, `pageToken`, `dateRange` or (experimental) `rangeHeader`
|
|
42
|
+
* `query`: an object containing query parameters to add in addition to the paging-related ones
|
|
43
|
+
* `itemsPathInResponse`: path within the response body schema, as an array of strings, that contains the array of items (default: `[]` for the response body root)
|
|
44
|
+
* `defaultPageSize`: tell Syncable how many items per page (max) to expect by default
|
|
45
|
+
* `forcePageSize`: if possible, let Syncable tell the API which page size to use (not applicable to paging strategy `dateRange`)
|
|
46
|
+
* when using `forcePageSize`, you can add `forcePageSizeParamInQuery` if it's not `pageSize` (not applicable to paging strategies `dateRange` and `rangeHeader`).
|
|
47
|
+
* for a `pageNumber` paging strategy, you can add `pageNumberParamInQuery` if it's not `page`.
|
|
48
|
+
* for an `offset` paging strategy, you can add `offsetParamInQuery` if it's not `offset`.
|
|
49
|
+
* for a `pageToken` paging strategy, you can add `pageTokenParamInQuery` if it's not `pageToken` and `pageTokenPathInResponse` if it's not `['nextPageToken']`
|
|
50
|
+
* for a `dateRange` paging strategy, you can add `startDateParamInQuery` if it's not `startDate`, `endDateParamInQuery` if it's not `endDate`, `startDate` if it's not `'20000101000000'`, and `endDate` if it's not `'99990101000000'`
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
### Create the OAD
|
|
54
|
+
You start with an OAD, for instance one from [here](https://github.com/tubsproject/syncables/tree/main/openapi/oad).
|
|
55
|
+
Probably the API you want to use is not specifying syncables yet, so you'll need to add those yourself using an overlay, something like the ones you see [here](https://github.com/tubsproject/syncables/tree/main/openapi/overlay).
|
|
56
|
+
To compute the effect of the overlay you can run a command like:
|
|
57
|
+
```sh
|
|
58
|
+
./node_modules/.bin/overlayjs --openapi ./openapi/oad/acube-peppol.yaml --overlay ./openapi/overlay/acube-peppol-overlay.yaml > openapi/generated/acube.yaml
|
|
59
|
+
```
|
|
60
|
+
### Generate the type
|
|
61
|
+
Assuming you're working in TypeScript, you can benefit from generating types from the OAD, like so:
|
|
62
|
+
```ts
|
|
63
|
+
npx openapi-typescript openapi/generated/acube.yaml -o ./src/types/acube.d.ts
|
|
64
|
+
```
|
|
65
|
+
### Install syncables
|
|
66
|
+
Depending on your preferred package manager, you can run something like this to install [syncables from npm](https://www.npmjs.com/package/syncables):
|
|
67
|
+
```sh
|
|
68
|
+
pnpm install syncables
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Write your code
|
|
72
|
+
Now you have the AOD with the definition of the syncable, and the type for the items you will sync, you can write code like [this](./src/readme-example.ts):
|
|
73
|
+
```ts
|
|
74
|
+
import { readFileSync } from 'fs';
|
|
75
|
+
import { components } from './src/types/google-calendar.js';
|
|
76
|
+
import { Syncable } from 'syncable';
|
|
77
|
+
|
|
78
|
+
type Entry = components['schemas']['CalendarListEntry'];
|
|
79
|
+
const specStr = readFileSync('./openapi/generated/google-calendar.yaml').toString();
|
|
80
|
+
|
|
81
|
+
const syncable = new Syncable<Entry>({
|
|
82
|
+
specStr,
|
|
83
|
+
syncableName: 'widgets',
|
|
84
|
+
authHeaders: {
|
|
85
|
+
Authorization: `Bearer ${process.env.GOOGLE_BEARER_TOKEN}`
|
|
86
|
+
},
|
|
87
|
+
dbConn: 'postgresql://syncables:syncables@localhost:5432/db_unit_tests'
|
|
88
|
+
});
|
|
89
|
+
await syncable.fullFetch();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
You can use the [`showcase-google-calendar` branch of this repo]() to run a simple OAuth client that can obtain a value for the `GOOGLE_BEARER_TOKEN` environment variable.
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
```sh
|
|
96
|
+
git clone https://github.com/tubsproject/syncables
|
|
97
|
+
cd syncables
|
|
98
|
+
pnpm install
|
|
99
|
+
pnpm generate
|
|
100
|
+
pnpm build
|
|
101
|
+
pnpm test
|
|
102
|
+
pnpm prettier
|
|
103
|
+
pnpm login
|
|
104
|
+
pnpm publish
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Usage
|
|
108
|
+
```sh
|
|
109
|
+
docker compose up -d
|
|
110
|
+
# run your code that calls syncable.fullFetch();
|
|
111
|
+
docker exec -it db psql postgresql://syncables:syncables@localhost:5432/db_unit_tests -c "\d+"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Acknowledgements
|
|
115
|
+
The `__tests__/integration/mock-server' folder is a copy of [`@scalar/mock-server`](https://github.com/scalar/scalar/blob/main/packages/mock-server/src) - thanks [Scalar](https://scalar.com)!
|
package/build/src/db.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* eslint @typescript-eslint/no-explicit-any: 0 */
|
|
2
|
+
import { Client } from 'pg';
|
|
3
|
+
export { Client } from 'pg';
|
|
4
|
+
export async function getPostgresClient() {
|
|
5
|
+
if (!process.env.DATABASE_URL) {
|
|
6
|
+
throw new Error('DATABASE_URL not set');
|
|
7
|
+
}
|
|
8
|
+
const client = new Client({
|
|
9
|
+
connectionString: process.env.DATABASE_URL,
|
|
10
|
+
ssl: {
|
|
11
|
+
rejectUnauthorized: process.env.NODE_ENV === 'production',
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
await client.connect();
|
|
15
|
+
return client;
|
|
16
|
+
}
|
|
17
|
+
export function getFields(openApiSpec, endPoint, rowsFrom) {
|
|
18
|
+
const successResponseProperties = openApiSpec.paths[endPoint]?.get?.responses?.['200']?.content;
|
|
19
|
+
// console.log(openApiSpec.paths, endPoint);
|
|
20
|
+
const schema = successResponseProperties?.['application/ld+json']?.schema ||
|
|
21
|
+
successResponseProperties?.['application/json']?.schema;
|
|
22
|
+
// console.log(`Schema for ${endPoint}:`, JSON.stringify(schema, null, 2));
|
|
23
|
+
// if (typeof schema['$ref'] !== 'undefined') {
|
|
24
|
+
// schema = resolveRef(openApiSpec, schema['$ref']);
|
|
25
|
+
// }
|
|
26
|
+
// const whatWeWant = schema?.properties?.[rowsFrom].items?.properties;
|
|
27
|
+
const whatWeWant = typeof rowsFrom === 'string'
|
|
28
|
+
? schema?.properties?.[rowsFrom]?.items?.properties
|
|
29
|
+
: schema?.items?.properties;
|
|
30
|
+
// console.log(
|
|
31
|
+
// `What we want (getFields ${endPoint} ${rowsFrom}):`,
|
|
32
|
+
// JSON.stringify(whatWeWant, null, 2),
|
|
33
|
+
// );
|
|
34
|
+
return whatWeWant;
|
|
35
|
+
}
|
|
36
|
+
export async function createSqlTable(client, tableName, whatWeWant) {
|
|
37
|
+
const rowSpecs = [];
|
|
38
|
+
// console.log(
|
|
39
|
+
// `What we want (createSqlTable ${tableName}):`,
|
|
40
|
+
// JSON.stringify(whatWeWant, null, 2),
|
|
41
|
+
// );
|
|
42
|
+
if (!whatWeWant) {
|
|
43
|
+
throw new Error(`No fields found for table ${tableName}`);
|
|
44
|
+
}
|
|
45
|
+
Object.entries(whatWeWant).forEach(([key, value]) => {
|
|
46
|
+
const type = value.type;
|
|
47
|
+
if (type === 'string') {
|
|
48
|
+
rowSpecs.push(`"S${key}" TEXT`);
|
|
49
|
+
}
|
|
50
|
+
else if (type === 'boolean') {
|
|
51
|
+
rowSpecs.push(`"S${key}" BOOLEAN`);
|
|
52
|
+
}
|
|
53
|
+
else if (type === 'number') {
|
|
54
|
+
rowSpecs.push(`"S${key}" INTEGER`);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const createTableQuery = `
|
|
58
|
+
CREATE TABLE IF NOT EXISTS ${tableName.replace('-', '_')} (
|
|
59
|
+
${rowSpecs.join(',\n ')}\n
|
|
60
|
+
);
|
|
61
|
+
`;
|
|
62
|
+
// console.log(createTableQuery);
|
|
63
|
+
await client.query(createTableQuery);
|
|
64
|
+
}
|
|
65
|
+
export async function insertData(client, tableName, items, fields) {
|
|
66
|
+
// console.log(`Fetched data:`, items);
|
|
67
|
+
await Promise.all(items.map((item) => {
|
|
68
|
+
const insertQuery = `INSERT INTO ${tableName.replace('-', '_')} (${fields.map((x) => `"S${x}"`).join(', ')}) VALUES (${fields.map((field) => `'${item[field]}'`).join(', ')})`;
|
|
69
|
+
// console.log(`Executing insert query: ${insertQuery}`);
|
|
70
|
+
return client.query(insertQuery);
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/db.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAE5B,MAAM,CAAC,KAAK,UAAU,iBAAiB;IACrC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC1C,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC;QACxB,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QAC1C,GAAG,EAAE;YACH,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;SAC1D;KACF,CAAC,CAAC;IACH,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,WAAgB,EAChB,QAAgB,EAChB,QAA4B;IAE5B,MAAM,yBAAyB,GAC7B,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,GAAG,E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KAAK,QAAQ,EAAE,CAAC;YAC7B,QAAQ,CAAC,IAAI,CAAC,KAAK,GAAG,WAAW,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG;6BACE,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC;IACpD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;;CAEzB,CAAC;IACA,iCAAiC;IACjC,MAAM,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AACvC,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAc,EACd,SAAiB,EACjB,KAAY,EACZ,MAAgB;IAEhB,uCAAuC;IACvC,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE;QACtB,MAAM,WAAW,GAAG,eAAe,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QAC/K,yDAAyD;QACzD,OAAO,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { Syncable } from './syncable.js';
|
|
3
|
+
const specFilename = './openapi/generated/google-calendar.yaml';
|
|
4
|
+
const specStr = readFileSync(specFilename).toString();
|
|
5
|
+
const syncable = new Syncable({
|
|
6
|
+
specStr,
|
|
7
|
+
specFilename,
|
|
8
|
+
syncableName: 'widgets',
|
|
9
|
+
authHeaders: {
|
|
10
|
+
Authorization: `Bearer ${process.env.GOOGLE_BEARER_TOKEN}`,
|
|
11
|
+
},
|
|
12
|
+
dbConn: 'postgresql://syncables:syncables@localhost:5432/db_unit_tests',
|
|
13
|
+
});
|
|
14
|
+
const data = await syncable.fullFetch();
|
|
15
|
+
console.log(data);
|
|
16
|
+
//# sourceMappingURL=readme-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readme-example.js","sourceRoot":"","sources":["../../src/readme-example.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAGzC,MAAM,YAAY,GAAG,0CAA0C,CAAC;AAChE,MAAM,OAAO,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,CAAC;AAEtD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAQ;IACnC,OAAO;IACP,YAAY;IACZ,YAAY,EAAE,SAAS;IACvB,WAAW,EAAE;QACX,aAAa,EAAE,UAAU,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;KAC3D;IACD,MAAM,EAAE,+DAA+D;CACxE,CAAC,CAAC;AACH,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC;AACxC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { default as urljoin } from 'url-join';
|
|
3
|
+
import { default as createDebug } from 'debug';
|
|
4
|
+
import { Client, getFields, createSqlTable, insertData } from './db.js';
|
|
5
|
+
import { dereference } from '@readme/openapi-parser';
|
|
6
|
+
import { parse } from 'yaml';
|
|
7
|
+
import { getObjectPath } from '../__tests__/integration/mock-server/apply-pagination.js';
|
|
8
|
+
const debug = createDebug('syncable');
|
|
9
|
+
export class Syncable extends EventEmitter {
|
|
10
|
+
fetchFunction;
|
|
11
|
+
config;
|
|
12
|
+
specStr;
|
|
13
|
+
specFilename;
|
|
14
|
+
syncableName;
|
|
15
|
+
spec;
|
|
16
|
+
authHeaders = {};
|
|
17
|
+
client = null;
|
|
18
|
+
constructor({ specStr, specFilename, syncableName, authHeaders = {}, fetchFunction = fetch, dbConn, }) {
|
|
19
|
+
super();
|
|
20
|
+
this.specStr = specStr;
|
|
21
|
+
this.specFilename = specFilename;
|
|
22
|
+
this.syncableName = syncableName;
|
|
23
|
+
this.authHeaders = authHeaders;
|
|
24
|
+
this.fetchFunction = fetchFunction;
|
|
25
|
+
if (dbConn) {
|
|
26
|
+
this.client = new Client({
|
|
27
|
+
connectionString: dbConn,
|
|
28
|
+
ssl: {
|
|
29
|
+
rejectUnauthorized: process.env.NODE_ENV === 'production',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async parseSpec() {
|
|
35
|
+
let specObj;
|
|
36
|
+
if (this.specFilename.endsWith('.json')) {
|
|
37
|
+
specObj = JSON.parse(this.specStr);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
specObj = parse(this.specStr);
|
|
41
|
+
}
|
|
42
|
+
const schema = await dereference(specObj);
|
|
43
|
+
for (const path of Object.keys(schema.paths)) {
|
|
44
|
+
const pathItem = schema.paths[path];
|
|
45
|
+
if (pathItem.get && pathItem.get.responses['200']) {
|
|
46
|
+
const response =
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
pathItem.get.responses['200'].content['application/json'];
|
|
49
|
+
if (response.syncable && response.syncable.name === this.syncableName) {
|
|
50
|
+
const config = {
|
|
51
|
+
baseUrl:
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
schema.servers && schema.servers.length > 0
|
|
54
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
schema.servers[0].url
|
|
56
|
+
: '',
|
|
57
|
+
urlPath: path,
|
|
58
|
+
name: response.syncable.name,
|
|
59
|
+
pagingStrategy: response.syncable.pagingStrategy,
|
|
60
|
+
query: response.syncable.query || {},
|
|
61
|
+
itemsPathInResponse: response.syncable.itemsPathInResponse || [],
|
|
62
|
+
defaultPageSize: response.syncable.defaultPageSize,
|
|
63
|
+
forcePageSize: response.syncable.forcePageSize,
|
|
64
|
+
forcePageSizeParamInQuery: response.syncable.forcePageSizeParamInQuery,
|
|
65
|
+
};
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
console.log('baseUrl:', config.baseUrl, schema.servers);
|
|
68
|
+
if (response.syncable.pagingStrategy === 'pageNumber') {
|
|
69
|
+
config.pageNumberParamInQuery =
|
|
70
|
+
response.syncable.pageNumberParamInQuery || 'page';
|
|
71
|
+
}
|
|
72
|
+
else if (response.syncable.pagingStrategy === 'offset') {
|
|
73
|
+
config.offsetParamInQuery =
|
|
74
|
+
response.syncable.offsetParamInQuery || 'offset';
|
|
75
|
+
}
|
|
76
|
+
else if (response.syncable.pagingStrategy === 'pageToken') {
|
|
77
|
+
config.pageTokenParamInQuery =
|
|
78
|
+
response.syncable.pageTokenParamInQuery || 'pageToken';
|
|
79
|
+
config.nextPageTokenPathInResponse = response.syncable
|
|
80
|
+
.nextPageTokenPathInResponse || ['nextPageToken'];
|
|
81
|
+
}
|
|
82
|
+
else if (response.syncable.pagingStrategy === 'dateRange') {
|
|
83
|
+
config.startDateParamInQuery =
|
|
84
|
+
response.syncable.startDateParamInQuery || 'startDate';
|
|
85
|
+
config.endDateParamInQuery =
|
|
86
|
+
response.syncable.endDateParamInQuery || 'endDate';
|
|
87
|
+
config.startDate = response.syncable.startDate || '20000101000000';
|
|
88
|
+
config.endDate = response.syncable.endDate || '99990101000000';
|
|
89
|
+
}
|
|
90
|
+
this.config = config;
|
|
91
|
+
return schema;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`Syncable with name "${this.syncableName}" not found in spec`);
|
|
96
|
+
}
|
|
97
|
+
async doFetch(url, headers = {}, minNumItemsToExpect = 1) {
|
|
98
|
+
debug('Fetching', url, headers);
|
|
99
|
+
const response = await this.fetchFunction(url, {
|
|
100
|
+
headers: Object.assign({}, this.authHeaders, headers),
|
|
101
|
+
});
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
throw new Error(`Fetch error: ${response.status} ${response.statusText} for URL ${url} (${await response.text()})`);
|
|
104
|
+
}
|
|
105
|
+
const responseData = await response.json();
|
|
106
|
+
// console.log('responseData nextPageToken', Object.keys(responseData), this.config.pageTokenParamInQuery, responseData[this.config.pageTokenParamInQuery]);
|
|
107
|
+
let items = responseData;
|
|
108
|
+
for (let i = 0; i < this.config.itemsPathInResponse.length; i++) {
|
|
109
|
+
const pathPart = this.config.itemsPathInResponse[i];
|
|
110
|
+
if (typeof items !== 'object' || items === null || !(pathPart in items)) {
|
|
111
|
+
throw new Error(`Invalid itemsPathInResponse: could not find path part "${pathPart}" in response ${url}`);
|
|
112
|
+
}
|
|
113
|
+
items = items[pathPart];
|
|
114
|
+
}
|
|
115
|
+
// console.log('parsed responseData', responseData, items, this.config.itemsPathInResponse);
|
|
116
|
+
let nextPageToken = undefined;
|
|
117
|
+
try {
|
|
118
|
+
nextPageToken = getObjectPath(responseData, this.config.nextPageTokenPathInResponse || ['nextPageToken']);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
// ignore
|
|
122
|
+
void err;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
items,
|
|
126
|
+
hasMore: items.length >= minNumItemsToExpect,
|
|
127
|
+
nextPageToken,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
async pageNumberFetch() {
|
|
131
|
+
let allData = [];
|
|
132
|
+
let page = 1;
|
|
133
|
+
let hasMore = true;
|
|
134
|
+
while (hasMore) {
|
|
135
|
+
const url = this.getUrl();
|
|
136
|
+
Object.entries(this.config.query || {}).forEach(([key, value]) => {
|
|
137
|
+
url.searchParams.append(key, value);
|
|
138
|
+
});
|
|
139
|
+
url.searchParams.append(this.config.pageNumberParamInQuery, page.toString());
|
|
140
|
+
if (this.config.forcePageSize) {
|
|
141
|
+
const param = this.config.forcePageSizeParamInQuery || 'pageSize';
|
|
142
|
+
url.searchParams.append(param, this.config.forcePageSize.toString());
|
|
143
|
+
}
|
|
144
|
+
const data = await this.doFetch(url.toString(), {}, this.config.forcePageSize || this.config.defaultPageSize || 1);
|
|
145
|
+
allData = allData.concat(data.items);
|
|
146
|
+
hasMore = data.hasMore;
|
|
147
|
+
page += 1;
|
|
148
|
+
}
|
|
149
|
+
return allData;
|
|
150
|
+
}
|
|
151
|
+
async offsetFetch() {
|
|
152
|
+
let allData = [];
|
|
153
|
+
let offset = 0;
|
|
154
|
+
let hasMore = true;
|
|
155
|
+
while (hasMore) {
|
|
156
|
+
const url = this.getUrl();
|
|
157
|
+
Object.entries(this.config.query || {}).forEach(([key, value]) => {
|
|
158
|
+
url.searchParams.append(key, value);
|
|
159
|
+
});
|
|
160
|
+
url.searchParams.append(this.config.offsetParamInQuery, offset.toString());
|
|
161
|
+
if (this.config.forcePageSize) {
|
|
162
|
+
const param = this.config.forcePageSizeParamInQuery || 'pageSize';
|
|
163
|
+
url.searchParams.append(param, this.config.forcePageSize.toString());
|
|
164
|
+
}
|
|
165
|
+
const data = await this.doFetch(url.toString(), {}, this.config.forcePageSize || this.config.defaultPageSize || 1);
|
|
166
|
+
allData = allData.concat(data.items);
|
|
167
|
+
hasMore = data.hasMore;
|
|
168
|
+
offset += data.items.length;
|
|
169
|
+
}
|
|
170
|
+
return allData;
|
|
171
|
+
}
|
|
172
|
+
async pageTokenFetch() {
|
|
173
|
+
let allData = [];
|
|
174
|
+
let nextPageToken = null;
|
|
175
|
+
do {
|
|
176
|
+
const url = this.getUrl();
|
|
177
|
+
Object.entries(this.config.query || {}).forEach(([key, value]) => {
|
|
178
|
+
url.searchParams.append(key, value);
|
|
179
|
+
});
|
|
180
|
+
if (this.config.forcePageSize) {
|
|
181
|
+
const param = this.config.forcePageSizeParamInQuery || 'pageSize';
|
|
182
|
+
url.searchParams.append(param, this.config.forcePageSize.toString());
|
|
183
|
+
}
|
|
184
|
+
if (nextPageToken) {
|
|
185
|
+
url.searchParams.append(this.config.pageTokenParamInQuery, nextPageToken);
|
|
186
|
+
}
|
|
187
|
+
const data = await this.doFetch(url.toString(), {}, this.config.forcePageSize || this.config.defaultPageSize || 1);
|
|
188
|
+
// console.log('fetched', data);
|
|
189
|
+
allData = allData.concat(data.items);
|
|
190
|
+
nextPageToken = data.nextPageToken || null;
|
|
191
|
+
} while (nextPageToken);
|
|
192
|
+
return allData;
|
|
193
|
+
}
|
|
194
|
+
getUrl() {
|
|
195
|
+
const joined = urljoin(this.config.baseUrl, this.config.urlPath);
|
|
196
|
+
return new URL(joined);
|
|
197
|
+
}
|
|
198
|
+
async dateRangeFetch() {
|
|
199
|
+
let allData = [];
|
|
200
|
+
let startDate = this.config.startDate || null;
|
|
201
|
+
const endDate = this.config.endDate || null;
|
|
202
|
+
while (true) {
|
|
203
|
+
const url = this.getUrl();
|
|
204
|
+
Object.entries(this.config.query || {}).forEach(([key, value]) => {
|
|
205
|
+
url.searchParams.append(key, value);
|
|
206
|
+
});
|
|
207
|
+
if (startDate) {
|
|
208
|
+
url.searchParams.append('startDate', startDate);
|
|
209
|
+
}
|
|
210
|
+
if (endDate) {
|
|
211
|
+
url.searchParams.append('endDate', endDate);
|
|
212
|
+
}
|
|
213
|
+
const data = await this.doFetch(url.toString());
|
|
214
|
+
allData = allData.concat(data.items);
|
|
215
|
+
if (data.items.length === 0 || !data.hasMore) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
// Assuming items are sorted by date ascending
|
|
219
|
+
startDate = data.items[data.items.length - 1].date; // FIXME
|
|
220
|
+
}
|
|
221
|
+
return allData;
|
|
222
|
+
}
|
|
223
|
+
async rangeHeaderFetch() {
|
|
224
|
+
let allData = [];
|
|
225
|
+
const numItemsPerPage = this.config.forcePageSize || 20;
|
|
226
|
+
let rangeHeader = `id ..; max=${numItemsPerPage}`;
|
|
227
|
+
while (true) {
|
|
228
|
+
const url = this.getUrl();
|
|
229
|
+
Object.entries(this.config.query || {}).forEach(([key, value]) => {
|
|
230
|
+
url.searchParams.append(key, value);
|
|
231
|
+
});
|
|
232
|
+
const data = await this.doFetch(url.toString(), {
|
|
233
|
+
Range: rangeHeader,
|
|
234
|
+
}, numItemsPerPage);
|
|
235
|
+
allData = allData.concat(data.items);
|
|
236
|
+
const lastItemId = data.items.length > 0
|
|
237
|
+
? data.items[data.items.length - 1].id
|
|
238
|
+
: null;
|
|
239
|
+
rangeHeader = `id ]${lastItemId}..; max=${numItemsPerPage}`;
|
|
240
|
+
if (data.items.length < numItemsPerPage || !data.hasMore) {
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return allData;
|
|
245
|
+
}
|
|
246
|
+
async doFullFetch() {
|
|
247
|
+
switch (this.config['pagingStrategy']) {
|
|
248
|
+
case 'pageNumber':
|
|
249
|
+
return this.pageNumberFetch();
|
|
250
|
+
case 'offset':
|
|
251
|
+
return this.offsetFetch();
|
|
252
|
+
case 'pageToken':
|
|
253
|
+
return this.pageTokenFetch();
|
|
254
|
+
case 'dateRange':
|
|
255
|
+
return this.dateRangeFetch();
|
|
256
|
+
case 'rangeHeader':
|
|
257
|
+
return this.rangeHeaderFetch();
|
|
258
|
+
default:
|
|
259
|
+
throw new Error(`Unknown paging strategy: ${this.config['pagingStrategy']}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async fullFetch() {
|
|
263
|
+
const schema = await this.parseSpec();
|
|
264
|
+
const data = await this.doFullFetch();
|
|
265
|
+
if (this.client) {
|
|
266
|
+
await this.client.connect();
|
|
267
|
+
const fields = getFields(schema, this.config.urlPath, this.config.itemsPathInResponse.join('.'));
|
|
268
|
+
await createSqlTable(this.client, this.config.name, fields);
|
|
269
|
+
await insertData(this.client, this.config.name, data, Object.keys(fields).filter((f) => ['string'].indexOf(fields[f].type) !== -1));
|
|
270
|
+
await this.client.end();
|
|
271
|
+
}
|
|
272
|
+
return data;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=syncable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncable.js","sourceRoot":"","sources":["../../src/syncable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,0DAA0D,CAAC;AAEzF,MAAM,KAAK,GAAG,WAAW,CAAC,UAAU,CAAC,CAAC;AA2BtC,MAAM,OAAO,QAAY,SAAQ,YAAY;IAC3C,aAAa,CAAe;IAC5B,MAAM,CAAiB;IACvB,OAAO,CAAS;IAChB,YAAY,CAAS;IACrB,YAAY,CAAS;IACrB,IAAI,CAAgD;IACpD,WAAW,GAA8B,EAAE,CAAC;IAC5C,MAAM,GAAkB,IAAI,CAAC;IAC7B,YAAY,EACV,OAAO,EACP,YAAY,EACZ,YAAY,EACZ,WAAW,GAAG,EAAE,EAChB,aAAa,GAAG,KAAK,EACrB,MAAM,GAQP;QACC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,Y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I,CAAC;IACd,CAAC;CACF"}
|
package/compose.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
services:
|
|
2
|
+
db:
|
|
3
|
+
build:
|
|
4
|
+
context: ./docker/db
|
|
5
|
+
container_name: db
|
|
6
|
+
restart: unless-stopped
|
|
7
|
+
ports:
|
|
8
|
+
- "5432:5432"
|
|
9
|
+
environment:
|
|
10
|
+
POSTGRES_USER: postgres
|
|
11
|
+
POSTGRES_PASSWORD: postgres
|
|
12
|
+
POSTGRES_DB: postgres
|
|
13
|
+
POSTGRES_APP_DB: db_unit_tests
|
|
14
|
+
POSTGRES_APP_USER: syncables
|
|
15
|
+
POSTGRES_APP_PASSWORD: syncables
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "syncables",
|
|
3
|
+
"version": "0.10.0",
|
|
4
|
+
"description": "Generate sync engine code from OpenAPI specifications",
|
|
5
|
+
"main": "build/src/syncable.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">= 22.11 < 23"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@eslint/js": "~9.17",
|
|
12
|
+
"@faker-js/faker": "^10.2.0",
|
|
13
|
+
"@hono/node-server": "^1.19.9",
|
|
14
|
+
"@scalar/helpers": "^0.2.10",
|
|
15
|
+
"@scalar/json-magic": "^0.9.5",
|
|
16
|
+
"@scalar/openapi-parser": "^0.24.6",
|
|
17
|
+
"@scalar/openapi-types": "^0.5.3",
|
|
18
|
+
"@scalar/openapi-upgrader": "^0.1.8",
|
|
19
|
+
"@scalar/workspace-store": "^0.28.1",
|
|
20
|
+
"@stoplight/yaml": "^4.3.0",
|
|
21
|
+
"@types/eslint__js": "~8.42",
|
|
22
|
+
"@types/node": "~20",
|
|
23
|
+
"@typescript-eslint/parser": "~8.19",
|
|
24
|
+
"@typescript-eslint/utils": "^8.46.4",
|
|
25
|
+
"@vitest/coverage-v8": "^3.0.8",
|
|
26
|
+
"@vitest/eslint-plugin": "~1.1",
|
|
27
|
+
"build-seed-context": "link:../../scalar/scalar/utils/build-seed-context",
|
|
28
|
+
"eslint": "~9.17",
|
|
29
|
+
"eslint-config-prettier": "~9.1",
|
|
30
|
+
"globals": "~15.14",
|
|
31
|
+
"hono": "^4.11.7",
|
|
32
|
+
"prettier": "~3.4",
|
|
33
|
+
"rimraf": "~6.0",
|
|
34
|
+
"ts-api-utils": "~2.0",
|
|
35
|
+
"types": "link:../../scalar/scalar/types",
|
|
36
|
+
"typescript": "~5.7",
|
|
37
|
+
"typescript-eslint": "~8.19",
|
|
38
|
+
"vitest": "^3.0.8"
|
|
39
|
+
},
|
|
40
|
+
"author": "Michiel de Jong <michiel@unhosted.org>",
|
|
41
|
+
"license": "Apache-2.0",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@readme/openapi-parser": "^5.4.0",
|
|
44
|
+
"debug": "^4.4.3",
|
|
45
|
+
"express": "^5.1.0",
|
|
46
|
+
"express-session": "^1.18.2",
|
|
47
|
+
"fast-xml-parser": "^5.3.0",
|
|
48
|
+
"openapi-overlays-js": "^0.2.0",
|
|
49
|
+
"passport": "^0.7.0",
|
|
50
|
+
"passport-oauth": "^1.0.0",
|
|
51
|
+
"pg": "^8.16.3",
|
|
52
|
+
"url-join": "^5.0.0",
|
|
53
|
+
"utils": "link:@scalar/types/utils",
|
|
54
|
+
"yaml": "^2.8.0"
|
|
55
|
+
},
|
|
56
|
+
"volta": {
|
|
57
|
+
"node": "22.12.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"start": "node build/src/cron.js",
|
|
61
|
+
"clean": "rimraf coverage build tmp",
|
|
62
|
+
"prebuild": "npm run lint",
|
|
63
|
+
"generate": "sh ./ts-gen.sh",
|
|
64
|
+
"build": "tsc -p tsconfig.json",
|
|
65
|
+
"build:watch": "tsc -w -p tsconfig.json",
|
|
66
|
+
"build:release": "npm run clean && tsc -p tsconfig.release.json",
|
|
67
|
+
"lint": "eslint .",
|
|
68
|
+
"test": "npm run test:unit && npm run test:integration",
|
|
69
|
+
"test:unit": "vitest run unit --config __tests__/vitest.config.ts",
|
|
70
|
+
"test:integration": "vitest run integration --config __tests__/vitest.config.ts",
|
|
71
|
+
"test:coverage": "vitest run unit --config __tests__/vitest.config.ts --coverage.enabled --coverage.all",
|
|
72
|
+
"prettier": "prettier \"{src,__tests__}/**/*.{ts,mts}\" --config .prettierrc --write",
|
|
73
|
+
"prettier:check": "prettier \"{src,__tests__}/**/*.{ts,mts}\" --config .prettierrc --check",
|
|
74
|
+
"test:watch": "vitest unit"
|
|
75
|
+
}
|
|
76
|
+
}
|