Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# Dependencies
node_modules/

# yarn2+ stuff
.yarn/*
!.yarn/releases
!.yarn/releases/*
!.yarn/plugins
!.yarn/plugins/*
!.yarn/patches
!.yarn/patches/*

# Misc
/.git
dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.vscode
node_modules/
/tasks/
/rewired/
_LOCAL/
Expand Down
942 changes: 942 additions & 0 deletions .yarn/releases/yarn-4.12.0.cjs

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# re-enable a specific script via `package.json:dependenciesMeta:<moduleName>:built = true`
enableScripts: false

# Don't install anything that was released less than a week ago
npmMinimalAgeGate: "1w"
# Unless it's one of ours:
npmPreapprovedPackages:
- "@graphile/*"
- graphile
- graphile-config

# ------------------------------------------------------------------------------

compressionLevel: mixed
enableGlobalCache: false
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.12.0.cjs
6 changes: 1 addition & 5 deletions __tests__/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
sleep,
sleepUntil as baseSleepUntil,
} from "jest-time-helpers";
import * as pg from "pg";
import pg from "pg";

import defer from "../src/deferred";
import {
Expand Down Expand Up @@ -43,10 +43,6 @@ export function sleepUntil(condition: () => boolean, ms?: number) {
return baseSleepUntil(condition, ms ?? 5000);
}

// Sometimes CI's clock can get interrupted (it is shared infra!) so this
// extends the default timeout just in case.
jest.setTimeout(20000);

// process.env.GRAPHILE_LOGGER_DEBUG = "1";

async function createTestDatabase() {
Expand Down
4 changes: 2 additions & 2 deletions __tests__/nodeEnvironment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const NodeEnvironment = require("jest-environment-node");
const { TestEnvironment } = require("jest-environment-node");

class CustomEnvironment extends NodeEnvironment {
class CustomEnvironment extends TestEnvironment {
constructor(config, context) {
super(config, context);
this.global.AbortController = global.AbortController;
Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
module.exports = {
roots: ["<rootDir>/src", "<rootDir>/__tests__"],
transform: {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.tsx?$": [
"ts-jest",
{ tsconfig: { rootDir: ".", module: "node16" } },
],
},
testRegex: "(/__tests__/.*\\.(test|spec))\\.[tj]sx?$",
moduleFileExtensions: ["ts", "js", "json"],
Expand All @@ -10,4 +13,5 @@ module.exports = {
"^(\\.{1,2}/.*)\\.js$": "$1",
},
testEnvironment: "./__tests__/nodeEnvironment.js",
testTimeout: 20000,
};
16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
"website:start": "yarn website start",
"website:deploy": "yarn website deploy"
},
"bin": {
"graphile-worker": "./dist/cli.js"
},
"bin": "./dist/cli.js",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/graphile/worker.git"
Expand Down Expand Up @@ -73,7 +71,7 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@mdx-js/react": "^1.6.22",
"@tsconfig/node18": "^18.2.4",
"@types/jest": "^26.0.0",
"@types/jest": "^30.0.0",
"@types/json5": "^2.2.0",
"@types/node": "^20.8.7",
"@typescript-eslint/eslint-plugin": "^6.8.0",
Expand All @@ -83,11 +81,11 @@
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jest": "^26.0.0",
"eslint-plugin-jest": "^29.15.0",
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint_d": "^13.0.0",
"graphile": "^5.0.0-beta.41",
"jest": "^26.0.0",
"jest": "^30.2.0",
"jest-time-helpers": "0.1.1",
"juice": "5.2.0",
"pg-connection-string": "^2.6.2",
Expand All @@ -97,8 +95,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"svgo": "^1.3.0",
"ts-jest": "^26.0.0",
"ts-node": "^10.9.1",
"ts-jest": "^29.4.6",
"typescript": "^5.2.2",
"zx": "^7.2.3"
},
Expand All @@ -121,5 +118,6 @@
"last 1 firefox version",
"last 1 safari version"
]
}
},
"packageManager": "yarn@4.12.0"
}
2 changes: 1 addition & 1 deletion scripts/dump_db
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dropdb --if-exists graphile_worker_dump
dropuser graphile_worker_role || true
psql template1 -c "CREATE USER graphile_worker_role WITH SUPERUSER PASSWORD 'password';"
createdb graphile_worker_dump -O graphile_worker_role
PGUSER=graphile_worker_role PGPASSWORD=password PGHOST=127.0.0.1 ts-node src/cli.ts -c postgres:///graphile_worker_dump --schema-only
PGUSER=graphile_worker_role PGPASSWORD=password PGHOST=127.0.0.1 node dist/cli.js -c postgres:///graphile_worker_dump --schema-only
pg_dump --schema-only --no-owner graphile_worker_dump | sed -E -e '/^--/d' -e '/^\s*$/d' -e '/^[\\](un)?restrict/d' -e '/^SET /d' -e 's/EXECUTE FUNCTION/EXECUTE PROCEDURE/g' -e '/^(REVOKE|GRANT) .* ON SCHEMA public (FROM|TO) PUBLIC;$/d' > __tests__/schema.sql
pg_dump --data-only --no-owner graphile_worker_dump --table=graphile_worker.migrations --table=graphile_worker._private_pro_migrations | sed -E -e '/^--/d' -e '/^\s*$/d' -e '/^[\\](un)?restrict/d' -e 's/\b2[0-9]{3}-[0-9]{2}-[0-9]{2}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{1,6}\+[0-9]+/1970-01-01 00:00:00.000000+00/g' -e '/^SET /d' >> __tests__/schema.sql
dropdb graphile_worker_dump
Expand Down
5 changes: 3 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const argv = yargs
"Clean the database, then exit. Accepts a comma-separated list of cleanup tasks: GC_TASK_IDENTIFIERS, GC_JOB_QUEUES, DELETE_PERMAFAILED_JOBS",
})
.string("cleanup")
.strict(true).argv;
.strict(true)
.parseSync();

const integerOrUndefined = (n: number | undefined): number | undefined => {
return typeof n === "number" && isFinite(n) && Math.round(n) === n
Expand All @@ -86,7 +87,7 @@ function stripUndefined<T extends object>(
) as T;
}

function argvToPreset(inArgv: Awaited<typeof argv>): GraphileConfig.Preset {
function argvToPreset(inArgv: typeof argv): GraphileConfig.Preset {
return {
worker: stripUndefined({
connectionString: inArgv["connection"],
Expand Down
8 changes: 5 additions & 3 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as assert from "assert";

Check failure on line 1 in src/lib.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

Run autofix to sort these imports!

Check failure on line 1 in src/lib.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

Run autofix to sort these imports!
import EventEmitter from "events";
import {
applyHooks,
Expand All @@ -7,7 +7,8 @@
orderedApply,
resolvePreset,
} from "graphile-config";
import { Client, Pool, PoolClient, PoolConfig } from "pg";
import pg from "pg";
import type { Pool, PoolClient, PoolConfig } from "pg";

import { makeWorkerPresetWorkerOptions } from "./config";
import { migrations } from "./generated/sql";
Expand Down Expand Up @@ -234,7 +235,8 @@
},
plugins,
} = resolvedPreset;
const escapedWorkerSchema = Client.prototype.escapeIdentifier(workerSchema);
const escapedWorkerSchema =
pg.Client.prototype.escapeIdentifier(workerSchema);

const ctx: WorkerPluginBaseContext = {
version,
Expand Down Expand Up @@ -357,7 +359,7 @@
releasers: Releasers,
poolOptions: PoolConfig,
) {
const pgPool = new Pool(poolOptions);
const pgPool = new pg.Pool(poolOptions);
releasers.push(() => {
pgPool.end();
});
Expand Down
3 changes: 0 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"ts-node": {
"experimentalResolver": true
},
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"rootDir": "src",
Expand Down
27 changes: 16 additions & 11 deletions website/docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ See the [CLI documentation](./cli/run.md) for more information about CLI mode.

### Running in Library Mode

#### In the Graphile Worker repo

When Graphile Worker users run in library mode, they use the functions exported
from `src/index.ts`. The scrappiest thing you can do to run your local version
of Graphile Worker similarly is to create a Typescript file that runs functions
imported from `.`.
from `src/index.ts`, which is compiled to `dist/index.js`. To run your local
version of Graphile Worker similarly you can create a `.mts` Typescript file
that runs functions imported from `./dist/index.js` (this uses Node.js' built in
type stripping):

```ts title="src/temp.ts"
import { run, WorkerPreset } from ".";
```ts title="temp.mts"
import { run, WorkerPreset } from "./dist/index.js";

async function main() {
const runner = await run({
Expand All @@ -144,21 +147,23 @@ main().catch((err) => {
});
```

Then you can run `temp.ts` with `ts-node`:
Then you can run `temp.mts` by first compiling Graphile Worker then running your
file with `node`:

```sh
yarn run ts-node src/temp.ts
yarn prepack && node temp.mts
```

You have to remember not to commit `src/temp.ts`, so a cleaner way to achieve
this would be using `yarn link`. In the root of your local Graphile Worker
repository run the following:
#### In your own repo

To try out your Graphile Worker version in your own repository, use `yarn link`.
In the root of your local Graphile Worker repository run the following:

```sh
yarn link
```

Create another node.js project with yarn that imports from `graphile-worker`
Create another Node.js project with yarn that imports from `graphile-worker`
like it would if it was using the published package. In that directory, run the
following:

Expand Down
7 changes: 7 additions & 0 deletions website/docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ for inspiration.

### Loading TypeScript files

:::info

You might not need to use ts-node anymore since Node.js has native type
stripping support. These docs need to be updated.

:::

:::tip

For performance and memory usage reasons, we recommend that you compile
Expand Down
Loading
Loading