Skip to content

Commit

Permalink
generate types
Browse files Browse the repository at this point in the history
  • Loading branch information
dblythy committed Jun 30, 2023
1 parent 72908b7 commit 00953ab
Show file tree
Hide file tree
Showing 17 changed files with 2,191 additions and 4,681 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ jobs:
uses: mansona/npm-lockfile-version@v1
with:
version: 2
check-types:
name: Check types
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check types
- run: npm run test:types
build:
runs-on: ubuntu-latest
timeout-minutes: 30
Expand Down Expand Up @@ -51,7 +59,6 @@ jobs:
${{ runner.os }}-node-${{ matrix.NODE_VERSION }}-
- run: npm ci
- run: npm run lint
- run: npm run test:types
- run: npm test -- --maxWorkers=4
- run: npm run test:mongodb
env:
Expand Down
10 changes: 5 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ const transformRuntime = ["@babel/plugin-transform-runtime", {
}];

const PRESETS = {
'browser': [["@babel/preset-env", {
'browser': ["@babel/preset-typescript",["@babel/preset-env", {
"targets": "> 0.25%, not dead"
}]],
'weapp': [["@babel/preset-env", {
'weapp': ["@babel/preset-typescript",["@babel/preset-env", {
"targets": "> 0.25%, not dead"
}], '@babel/react'],
'node': [["@babel/preset-env", {
'node': ["@babel/preset-typescript",["@babel/preset-env", {
"targets": { "node": "14" }
}]],
'react-native': ['module:metro-react-native-babel-preset'],
'react-native': ["@babel/preset-typescript", 'module:metro-react-native-babel-preset'],
};
const PLUGINS = {
'browser': [transformRuntime, '@babel/plugin-transform-flow-comments', '@babel/plugin-proposal-class-properties', 'inline-package-json',
Expand Down Expand Up @@ -79,7 +79,7 @@ function compileTask(stream) {
}

gulp.task('compile', function() {
return compileTask(gulp.src('src/*.js'));
return compileTask(gulp.src('src/*.*(js|ts)'));
});

gulp.task('browserify', function(cb) {
Expand Down
630 changes: 342 additions & 288 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"xmlhttprequest": "1.8.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.22.5",
"@babel/core": "7.22.0",
"@babel/eslint-parser": "7.21.8",
"@babel/plugin-proposal-class-properties": "7.18.6",
Expand Down Expand Up @@ -98,6 +99,7 @@
},
"scripts": {
"build": "node build_releases.js",
"build:types": "tsc",
"release": "node build_releases.js && npm publish",
"test": "cross-env PARSE_BUILD=node jest",
"test:mongodb": "npm run test:mongodb:runnerstart && npm run integration",
Expand Down
5 changes: 3 additions & 2 deletions src/Analytics.js → src/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @flow
*/

// @ts-ignore
import CoreManager from './CoreManager';

/**
Expand Down Expand Up @@ -44,7 +45,7 @@ import CoreManager from './CoreManager';
* @returns {Promise} A promise that is resolved when the round-trip
* to the server completes.
*/
export function track(name: string, dimensions: { [key: string]: string }): Promise {
export function track(name: string, dimensions: { [key: string]: string }): Promise<any> {
name = name || '';
name = name.replace(/^\s*/, '');
name = name.replace(/\s*$/, '');
Expand All @@ -62,7 +63,7 @@ export function track(name: string, dimensions: { [key: string]: string }): Prom
}

const DefaultController = {
track(name, dimensions) {
track(name: string, dimensions: { [key: string]: string }) {
const path = 'events/' + name;
const RESTController = CoreManager.getRESTController();
return RESTController.request('POST', path, { dimensions: dimensions });
Expand Down
14 changes: 7 additions & 7 deletions src/ObjectStateMutations.js → src/ObjectStateMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function setServerData(serverData: AttributeMap, attributes: AttributeMap
}
}

export function setPendingOp(pendingOps: Array<OpsMap>, attr: string, op: ?Op) {
export function setPendingOp(pendingOps: Array<OpsMap>, attr: string, op?: Op) {
const last = pendingOps.length - 1;
if (op) {
pendingOps[last][attr] = op;
Expand All @@ -56,7 +56,7 @@ export function pushPendingState(pendingOps: Array<OpsMap>) {
pendingOps.push({});
}

export function popPendingState(pendingOps: Array<OpsMap>): OpsMap {
export function popPendingState(pendingOps: Array<OpsMap>): OpsMap | undefined {
const first = pendingOps.shift();
if (!pendingOps.length) {
pendingOps[0] = {};
Expand All @@ -83,15 +83,15 @@ export function estimateAttribute(
serverData: AttributeMap,
pendingOps: Array<OpsMap>,
className: string,
id: ?string,
id: string | undefined,
attr: string
): mixed {
): any {
let value = serverData[attr];
for (let i = 0; i < pendingOps.length; i++) {
if (pendingOps[i][attr]) {
if (pendingOps[i][attr] instanceof RelationOp) {
if (id) {
value = pendingOps[i][attr].applyTo(value, { className: className, id: id }, attr);
value = (pendingOps[i][attr] as RelationOp).applyTo(value, { className: className, id: id }, attr);
}
} else {
value = pendingOps[i][attr].applyTo(value);
Expand All @@ -105,7 +105,7 @@ export function estimateAttributes(
serverData: AttributeMap,
pendingOps: Array<OpsMap>,
className: string,
id: ?string
id?: string
): AttributeMap {
const data = {};
let attr;
Expand All @@ -116,7 +116,7 @@ export function estimateAttributes(
for (attr in pendingOps[i]) {
if (pendingOps[i][attr] instanceof RelationOp) {
if (id) {
data[attr] = pendingOps[i][attr].applyTo(
data[attr] = (pendingOps[i][attr] as RelationOp).applyTo(
data[attr],
{ className: className, id: id },
attr
Expand Down
Loading

0 comments on commit 00953ab

Please sign in to comment.