Skip to content

Commit 6db0e54

Browse files
committed
feat: add typescript support
1 parent 57f4a17 commit 6db0e54

File tree

16 files changed

+464
-53
lines changed

16 files changed

+464
-53
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ node_modules
3030
# Emacs
3131
*~
3232
.eslintcache
33+
34+
# build folder
35+
dist

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ The [Parse Server guide](https://docs.parseplatform.org/parse-server/guide/) is
5454
These scripts can help you to develop your app for Parse Server:
5555

5656
* `npm run watch` will start your Parse Server and restart if you make any changes.
57-
* `npm run lint` will check the linting of your cloud code, tests and `index.js`, as defined in `.eslintrc.json`.
58-
* `npm run lint-fix` will attempt fix the linting of your cloud code, tests and `index.js`.
59-
* `npm run prettier` will help improve the formatting and layout of your cloud code, tests and `index.js`, as defined in `.prettierrc`.
57+
* `npm run lint` will check the linting of your cloud code, tests and `index.ts`, as defined in `.eslintrc.json`.
58+
* `npm run lint-fix` will attempt fix the linting of your cloud code, tests and `index.ts`.
59+
* `npm run prettier` will help improve the formatting and layout of your cloud code, tests and `index.ts`, as defined in `.prettierrc`.
6060
* `npm test` will run all tests
6161
* `npm run coverage` will run tests and check coverage. Output is available in the `/coverage` folder.
6262

6363
## Configuration
6464

65-
Configuration is located in `config.js`.
65+
Configuration is located in `config.ts`.
6666

6767

6868
# Remote Deployment
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
Parse.Cloud.define('hello', req => {
2+
// @ts-ignore
23
req.log.info(req);
34
return 'Hi';
45
});
56

67
Parse.Cloud.define('helloAsyncFunction', async req => {
78
await new Promise(resolve => setTimeout(resolve, 1000));
9+
// @ts-ignore
810
req.log.info(req);
911
return 'Hi async';
1012
});
1113

1214
Parse.Cloud.beforeSave('TestObject', () => {
13-
throw new Parse.Error(9001, 'Saving test objects is not available.');
15+
throw new Parse.Error(Parse.Error.OTHER_CAUSE, 'Saving test objects is not available.');
1416
});
17+
18+
export {};
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// It is best practise to organize your cloud functions group into their own file. You can then import them in your main.js.
2-
await Promise.all([
3-
import('./functions.js')
4-
]);
2+
await Promise.all([import('./functions.js')]);
3+
4+
export {};

cloud/schema.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

cloud/schema.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const schemaDefinitions = [
2+
{
3+
className: 'TestObject',
4+
fields: {
5+
beforeSave: { type: 'Boolean', defaultValue: false },
6+
additionalData: { type: 'String' },
7+
},
8+
classLevelPermissions: {
9+
find: { '*': true },
10+
count: { '*': true },
11+
get: { '*': true },
12+
update: { '*': true },
13+
create: { '*': true },
14+
delete: { '*': true },
15+
},
16+
},
17+
];

config.js renamed to config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { schemaDefinitions } from "./cloud/schema.js";
1+
import { schemaDefinitions } from './cloud/schema.js';
2+
23
export const config = {
3-
databaseURI: process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://localhost:27017/dev',
4-
cloud: process.env.CLOUD_CODE_MAIN || './cloud/main.js',
4+
databaseURI:
5+
process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://localhost:27017/dev',
6+
cloud: async () => {
7+
await import('./cloud/main.js');
8+
},
59
appId: process.env.APP_ID || 'myAppId',
610
masterKey: process.env.MASTER_KEY || '', //Add your master key here. Keep it secret!
711
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse', // Don't forget to change to https if needed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default [
22
{
3-
files: ['**/*.js'], // Apply to JavaScript files.
3+
files: ['**/*.js', '**/*.ts', '**/*.mjs', '**/*.cjs'], // Apply to JavaScript files.
44
languageOptions: {
55
ecmaVersion: 2022,
66
sourceType: 'module',

index.js renamed to index.ts

File renamed without changes.

nodemon.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"ignore": [
3+
"dist"
4+
],
5+
"ext": "json,ts,mjs,cjs,js",
6+
"execMap": {
7+
"ts": "node -r source-map-support/register --loader=ts-node/esm/transpile-only"
8+
}
9+
}

0 commit comments

Comments
 (0)